From b561215017bc787d04a16823019b8c51999754d8 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Tue, 8 Sep 2015 19:17:53 -0700 Subject: [PATCH] cmake: fixes for apps.h generation for posix and qurt Signed-off-by: Mark Charlebois --- .../apps.h_in} | 32 +++++++++++-------- cmake/posix/px4_impl_posix.cmake | 2 +- .../apps.h_in} | 0 cmake/qurt/px4_impl_qurt.cmake | 2 +- src/firmware/posix/CMakeLists.txt | 8 ++--- src/firmware/qurt/CMakeLists.txt | 7 ++-- 6 files changed, 29 insertions(+), 22 deletions(-) rename cmake/{qurt/builtin_commands.cpp_in => posix/apps.h_in} (75%) rename cmake/{posix/builtin_commands.cpp_in => qurt/apps.h_in} (100%) diff --git a/cmake/qurt/builtin_commands.cpp_in b/cmake/posix/apps.h_in similarity index 75% rename from cmake/qurt/builtin_commands.cpp_in rename to cmake/posix/apps.h_in index f4d240d529..7b29304b3f 100644 --- a/cmake/qurt/builtin_commands.cpp_in +++ b/cmake/posix/apps.h_in @@ -22,9 +22,10 @@ static int list_topics_main(int argc, char *argv[]); static int sleep_main(int argc, char *argv[]); } - -void init_app_map(map &apps) +static map app_map(void) { + static map apps; + ${builtin_apps_string} apps["shutdown"] = shutdown_main; apps["list_tasks"] = list_tasks_main; @@ -32,13 +33,17 @@ ${builtin_apps_string} apps["list_devices"] = list_devices_main; apps["list_topics"] = list_topics_main; apps["sleep"] = sleep_main; + + return apps; } -void list_builtins(map &apps) +map apps = app_map(); + +static void list_builtins(void) { - printf("Builtin Commands:\\n"); + cout << "Builtin Commands:" << endl; for (map::iterator it=apps.begin(); it!=apps.end(); ++it) - printf("\\t%s\\n", (it->first).c_str()); + cout << '\t' << it->first << endl; } static int shutdown_main(int argc, char *argv[]) @@ -64,21 +69,20 @@ static int list_topics_main(int argc, char *argv[]) px4_show_topics(); return 0; } + static int list_files_main(int argc, char *argv[]) { px4_show_files(); return 0; } + static int sleep_main(int argc, char *argv[]) { - if (argc != 2) { - PX4_WARN( "Usage: sleep " ); - return 1; - } - - unsigned long usecs = ( (unsigned long) atol( argv[1] ) ) * 1000 * 1000; - PX4_WARN("Sleeping for %s, %ld",argv[1],usecs); - usleep( usecs ); - return 0; + if (argc != 2) { + cout << "Usage: sleep " << endl; + return 1; + } + sleep(atoi(argv[1])); + return 0; } diff --git a/cmake/posix/px4_impl_posix.cmake b/cmake/posix/px4_impl_posix.cmake index 46c21e29f9..6108b9c94f 100644 --- a/cmake/posix/px4_impl_posix.cmake +++ b/cmake/posix/px4_impl_posix.cmake @@ -102,7 +102,7 @@ function(px4_posix_generate_builtin_commands) math(EXPR command_count "${command_count}+1") endif() endforeach() - configure_file(${CMAKE_SOURCE_DIR}/cmake/posix/builtin_commands.cpp_in + configure_file(${CMAKE_SOURCE_DIR}/cmake/posix/apps.h_in ${OUT}) endfunction() diff --git a/cmake/posix/builtin_commands.cpp_in b/cmake/qurt/apps.h_in similarity index 100% rename from cmake/posix/builtin_commands.cpp_in rename to cmake/qurt/apps.h_in diff --git a/cmake/qurt/px4_impl_qurt.cmake b/cmake/qurt/px4_impl_qurt.cmake index 44cce7599d..cdd42a37fa 100644 --- a/cmake/qurt/px4_impl_qurt.cmake +++ b/cmake/qurt/px4_impl_qurt.cmake @@ -104,7 +104,7 @@ function(px4_qurt_generate_builtin_commands) math(EXPR command_count "${command_count}+1") endif() endforeach() - configure_file(${CMAKE_SOURCE_DIR}/cmake/qurt/builtin_commands.cpp_in + configure_file(${CMAKE_SOURCE_DIR}/cmake/qurt/apps.h_in ${OUT}) endfunction() diff --git a/src/firmware/posix/CMakeLists.txt b/src/firmware/posix/CMakeLists.txt index 6dfda2bea7..de02be35c4 100644 --- a/src/firmware/posix/CMakeLists.txt +++ b/src/firmware/posix/CMakeLists.txt @@ -7,8 +7,8 @@ message(STATUS "module list: ${module_dir_list}") include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_custom_command(OUTPUT apps.h - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/posix_apps.py > apps.h) +#add_custom_command(OUTPUT apps.h +# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/posix_apps.py > apps.h) foreach(directory ${module_dir_list}) message(STATUS "directory: ${directory}") @@ -17,13 +17,13 @@ foreach(directory ${module_dir_list}) ${mangled_name}) endforeach() px4_posix_generate_builtin_commands( - OUT builtin_commands.cpp + OUT apps.h MODULE_LIST ${module_list}) add_executable(mainapp ${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp apps.h - builtin_commands.cpp) + ) set(main_link_flags "-T${CMAKE_SOURCE_DIR}/cmake/posix/ld.script" diff --git a/src/firmware/qurt/CMakeLists.txt b/src/firmware/qurt/CMakeLists.txt index b5babecf11..5087639174 100644 --- a/src/firmware/qurt/CMakeLists.txt +++ b/src/firmware/qurt/CMakeLists.txt @@ -16,7 +16,7 @@ foreach(directory ${module_dir_list}) ${mangled_name}) endforeach() px4_qurt_generate_builtin_commands( - OUT builtin_commands.cpp + OUT apps.h MODULE_LIST ${module_list}) # FIXME @jgoppert - how to work around issues like this? @@ -25,7 +25,10 @@ px4_qurt_generate_builtin_commands( set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -add_library(mainapp builtin_commands.cpp) +add_library(mainapp + ${CMAKE_SOURCE_DIR}/src/platforms/qurt/px4_layer/main.cpp + apps.h) + target_link_libraries(mainapp -Wl,--whole-archive ${module_list}