diff --git a/CMakeLists.txt b/CMakeLists.txt index 91d3442899..9ebc8c0a2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,16 +112,16 @@ set(package-contact "px4users@googlegroups.com") list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) #============================================================================= -# cmake modules +# Validate build configuration and build # if (NOT NESTED_CMAKE_CALL) message(STATUS "IN TOP") - if (EXISTS ${CMAKE_SOURCE_DIR}/cmake/configs/config_${CONFIG}.cmake) + if (EXISTS ${CMAKE_SOURCE_DIR}/cmake/configs/${CONFIG}.cmake) # Get the toolchain information - include(configs/config_${CONFIG}) + include(configs/${CONFIG}) else() - message(FATAL_ERROR "build config not found: config_${CONFIG}.cmake") + message(FATAL_ERROR "build config not found: ${CONFIG}.cmake") endif() if (NOT "${USE_TOOLCHAIN}" STREQUAL "") set(TOOLCHAIN -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/cmake/toolchains/${USE_TOOLCHAIN}.cmake) @@ -130,15 +130,6 @@ if (NOT NESTED_CMAKE_CALL) list(GET TARGET_PARAMS 0 OS) list(GET TARGET_PARAMS 1 BOARD) list(GET TARGET_PARAMS 2 LABEL) - message(STATUS "CONFIG ${OS} ${BOARD} ${LABEL}") - if ("${LABEL}" STREQUAL "upload") - set(LABEL "simple") - set(DOUPLOAD "1") - endif() - if ("${LABEL}" STREQUAL "test") - set(LABEL "simple") - set(DOTEST "1") - endif() execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory ${CONFIG} ) set(NESTED_CMAKE_CALL 1) message(STATUS "Before") @@ -149,14 +140,6 @@ if (NOT NESTED_CMAKE_CALL) COMMAND make -s ) message(STATUS "${CMAKE_COMMAND} VERBOSE=1 ${CMAKE_SOURCE_DIR} ${TOOLCHAIN} -DOS=${OS} -DBOARD=${BOARD} -DLABEL=${LABEL}") - if ("${DOUPLOAD}" STREQUAL "1") - execute_process( WORKING_DIRECTORY ${CONFIG} - COMMAND make upload) - endif() - if ("${DOTEST}" STREQUAL "1") - execute_process( WORKING_DIRECTORY ${CONFIG} - COMMAND make test) - endif() return() endif(NOT NESTED_CMAKE_CALL) diff --git a/cmake/configs/config_nuttx_px4fmu-v2_default.cmake b/cmake/configs/nuttx_px4fmu-v2_default.cmake similarity index 100% rename from cmake/configs/config_nuttx_px4fmu-v2_default.cmake rename to cmake/configs/nuttx_px4fmu-v2_default.cmake diff --git a/cmake/configs/config_nuttx_px4fmu-v2_simple.cmake b/cmake/configs/nuttx_px4fmu-v2_simple.cmake similarity index 100% rename from cmake/configs/config_nuttx_px4fmu-v2_simple.cmake rename to cmake/configs/nuttx_px4fmu-v2_simple.cmake diff --git a/cmake/configs/config_nuttx_sim_simple.cmake b/cmake/configs/nuttx_sim_simple.cmake similarity index 100% rename from cmake/configs/config_nuttx_sim_simple.cmake rename to cmake/configs/nuttx_sim_simple.cmake diff --git a/cmake/configs/config_posix_eagle_default.cmake b/cmake/configs/posix_eagle_default.cmake similarity index 83% rename from cmake/configs/config_posix_eagle_default.cmake rename to cmake/configs/posix_eagle_default.cmake index 04f80c7523..228b4e50ae 100644 --- a/cmake/configs/config_posix_eagle_default.cmake +++ b/cmake/configs/posix_eagle_default.cmake @@ -1,10 +1,13 @@ include(posix/px4_impl_posix-arm) +set(USE_TOOLCHAIN Toolchain-arm-linux-gnueabihf) + function(px4_get_config) px4_parse_function_args( NAME px4_set_config_modules - ONE_VALUE OUT_MODULES OUT_FW_OPTS OUT_EXTRA_CMDS + ONE_VALUE OUT_MODULES + REQUIRED OUT_MODULES ARGN ${ARGN}) set(config_module_list @@ -47,7 +50,7 @@ function(px4_get_config) platforms/posix/work_queue ) - set(${out_module_list} ${config_module_list} PARENT_SCOPE) + set(${OUT_MODULES} ${config_module_list} PARENT_SCOPE) endfunction() diff --git a/cmake/configs/config_posix_eagle_hil.cmake b/cmake/configs/posix_eagle_hil.cmake similarity index 79% rename from cmake/configs/config_posix_eagle_hil.cmake rename to cmake/configs/posix_eagle_hil.cmake index 115f70d406..af3785f5c7 100644 --- a/cmake/configs/config_posix_eagle_hil.cmake +++ b/cmake/configs/posix_eagle_hil.cmake @@ -1,10 +1,13 @@ include(posix/px4_impl_posix-arm) +set(USE_TOOLCHAIN Toolchain-arm-linux-gnueabihf) + function(px4_get_config) px4_parse_function_args( NAME px4_set_config_modules - ONE_VALUE OUT_MODULES OUT_FW_OPTS OUT_EXTRA_CMDS + ONE_VALUE OUT_MODULES + REQUIRED OUT_MODULES ARGN ${ARGN}) set(config_module_list @@ -36,7 +39,7 @@ function(px4_get_config) modules/muorb/krait ) - set(${out_module_list} ${config_module_list} PARENT_SCOPE) + set(${OUT_MODULES} ${config_module_list} PARENT_SCOPE) endfunction() diff --git a/cmake/configs/config_posix_eagle_muorb.cmake b/cmake/configs/posix_eagle_muorb.cmake similarity index 65% rename from cmake/configs/config_posix_eagle_muorb.cmake rename to cmake/configs/posix_eagle_muorb.cmake index 44fe4cebe0..450d7b1e4e 100644 --- a/cmake/configs/config_posix_eagle_muorb.cmake +++ b/cmake/configs/posix_eagle_muorb.cmake @@ -1,10 +1,13 @@ include(posix/px4_impl_posix-arm) +set(USE_TOOLCHAIN Toolchain-arm-linux-gnueabihf) + function(px4_get_config) px4_parse_function_args( NAME px4_set_config_modules - ONE_VALUE OUT_MODULES OUT_FW_OPTS OUT_EXTRA_CMDS + ONE_VALUE OUT_MODULES + REQUIRED OUT_MODULES ARGN ${ARGN}) set(config_module_list @@ -18,7 +21,7 @@ function(px4_get_config) modules/muorb/krait ) - set(${out_module_list} ${config_module_list} PARENT_SCOPE) + set(${OUT_MODULES} ${config_module_list} PARENT_SCOPE) endfunction() diff --git a/cmake/configs/config_posix_eagle_release.cmake b/cmake/configs/posix_eagle_release.cmake similarity index 78% rename from cmake/configs/config_posix_eagle_release.cmake rename to cmake/configs/posix_eagle_release.cmake index 90c81fd411..cc220cb306 100644 --- a/cmake/configs/config_posix_eagle_release.cmake +++ b/cmake/configs/posix_eagle_release.cmake @@ -1,10 +1,12 @@ include(posix/px4_impl_posix-arm) +set(USE_TOOLCHAIN Toolchain-arm-linux-gnueabihf) + function(px4_get_config) px4_parse_function_args( NAME px4_set_config_modules - ONE_VALUE OUT_MODULES OUT_FW_OPTS OUT_EXTRA_CMDS + ONE_VALUE OUT_MODULES ARGN ${ARGN}) set(config_module_list @@ -31,7 +33,7 @@ function(px4_get_config) modules/muorb/krait ) - set(${out_module_list} ${config_module_list} PARENT_SCOPE) + set(${OUT_MODULES} ${config_module_list} PARENT_SCOPE) endfunction() diff --git a/cmake/configs/config_posix_sitl_simple.cmake b/cmake/configs/posix_sitl_simple.cmake similarity index 98% rename from cmake/configs/config_posix_sitl_simple.cmake rename to cmake/configs/posix_sitl_simple.cmake index 20481bdb1e..39aed67046 100644 --- a/cmake/configs/config_posix_sitl_simple.cmake +++ b/cmake/configs/posix_sitl_simple.cmake @@ -1,4 +1,5 @@ include(posix/px4_impl_posix) +set(USE_TOOLCHAIN Toolchain-native) function(px4_get_config) diff --git a/cmake/configs/config_qurt_eagle_hello.cmake b/cmake/configs/qurt_eagle_hello.cmake similarity index 100% rename from cmake/configs/config_qurt_eagle_hello.cmake rename to cmake/configs/qurt_eagle_hello.cmake diff --git a/cmake/configs/config_qurt_eagle_hil.cmake b/cmake/configs/qurt_eagle_hil.cmake similarity index 100% rename from cmake/configs/config_qurt_eagle_hil.cmake rename to cmake/configs/qurt_eagle_hil.cmake diff --git a/cmake/configs/config_qurt_eagle_muorb.cmake b/cmake/configs/qurt_eagle_muorb.cmake similarity index 100% rename from cmake/configs/config_qurt_eagle_muorb.cmake rename to cmake/configs/qurt_eagle_muorb.cmake diff --git a/cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake b/cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake new file mode 100644 index 0000000000..2db5cf82b9 --- /dev/null +++ b/cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake @@ -0,0 +1,67 @@ +# defines: +# +# NM +# OBJCOPY +# LD +# CXX_COMPILER +# C_COMPILER +# CMAKE_SYSTEM_NAME +# CMAKE_SYSTEM_VERSION +# GENROMFS +# LINKER_FLAGS +# CMAKE_EXE_LINKER_FLAGS +# CMAKE_FIND_ROOT_PATH +# CMAKE_FIND_ROOT_PATH_MODE_PROGRAM +# CMAKE_FIND_ROOT_PATH_MODE_LIBRARY +# CMAKE_FIND_ROOT_PATH_MODE_INCLUDE + +include(CMakeForceCompiler) + +# this one is important +set(CMAKE_SYSTEM_NAME Generic) + +#this one not so much +set(CMAKE_SYSTEM_VERSION 1) + +# specify the cross compiler +find_program(C_COMPILER arm-linux-gnueabihf-gcc) +if(NOT C_COMPILER) + message(FATAL_ERROR "could not find arm-none-eabi-gcc compiler") +endif() +cmake_force_c_compiler(${C_COMPILER} GNU) + +find_program(CXX_COMPILER arm-linux-gnueabihf-g++) +if(NOT CXX_COMPILER) + message(FATAL_ERROR "could not find arm-none-eabi-g++ compiler") +endif() +cmake_force_cxx_compiler(${CXX_COMPILER} GNU) + +# compiler tools +foreach(tool objcopy nm ld) + string(TOUPPER ${tool} TOOL) + find_program(${TOOL} arm-linux-gnueabihf-${tool}) + if(NOT ${TOOL}) + message(FATAL_ERROR "could not find ${tool}") + endif() +endforeach() + +# os tools +foreach(tool echo patch grep rm mkdir nm genromfs awk cp touch make unzip) + string(TOUPPER ${tool} TOOL) + find_program(${TOOL} ${tool}) + if(NOT ${TOOL}) + message(FATAL_ERROR "could not find ${TOOL}") + endif() +endforeach() + +set(LINKER_FLAGS "-Wl,-gc-sections") +set(CMAKE_EXE_LINKER_FLAGS ${LINKER_FLAGS}) + +# where is the target environment +set(CMAKE_FIND_ROOT_PATH get_file_component(${C_COMPILER} PATH)) + +# search for programs in the build host directories +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# for libraries and headers in the target directories +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)