diff --git a/CMakeLists.txt b/CMakeLists.txt index c11d61bef6..5645f24ea4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,12 +99,9 @@ # #============================================================================= -# check submodules before we do anything -execute_process(COMMAND Tools/check_submodules.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - # Warning: Changing this modifies CMake's internal workings # and leads to wrong toolchain detection -cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") @@ -187,23 +184,24 @@ execute_process( ) px4_add_git_submodule(TARGET git_cmake_hexagon PATH "cmake/cmake_hexagon") -px4_add_git_submodule(TARGET git_driverframework PATH "src/lib/DriverFramework") +px4_add_git_submodule(TARGET git_uavcan_board_ident PATH "cmake/configs/uavcan_board_ident") px4_add_git_submodule(TARGET git_ecl PATH "src/lib/ecl") -px4_add_git_submodule(TARGET git_gazebo PATH "Tools/sitl_gazebo") -px4_add_git_submodule(TARGET git_gazebo_flow PATH "Tools/sitl_gazebo/external/OpticalFlow") -px4_add_git_submodule(TARGET git_gazebo_klt PATH "Tools/sitl_gazebo/external/OpticalFlow/external/klt_feature_tracker") -px4_add_git_submodule(TARGET git_gps_devices PATH "src/drivers/gps/devices") -px4_add_git_submodule(TARGET git_jmavsim PATH "Tools/jMAVSim") px4_add_git_submodule(TARGET git_matrix PATH "src/lib/matrix") -px4_add_git_submodule(TARGET git_mavlink PATH "mavlink/include/mavlink/v1.0") -px4_add_git_submodule(TARGET git_mavlink2 PATH "mavlink/include/mavlink/v2.0") -px4_add_git_submodule(TARGET git_nuttx PATH "platforms/nuttx/NuttX/nuttx") -px4_add_git_submodule(TARGET git_uavcan PATH "src/modules/uavcan/libuavcan") #============================================================================= message(STATUS "PX4 VERSION: ${git_tag}") message(STATUS "CONFIG: ${target_name}") +message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") + +#============================================================================= +# project definition +# +project(px4 CXX C ASM) + +set(package-contact "px4users@googlegroups.com") + +#============================================================================= # The URL for the elf file for crash logging if (DEFINED ENV{BUILD_URI}) @@ -214,14 +212,19 @@ endif() add_definitions(-DBUILD_URI=${BUILD_URI}) -# Define GNU standard installation directories -include(GNUInstallDirs) - # Setup install paths if (${OS} STREQUAL "posix") + + # Define GNU standard installation directories + include(GNUInstallDirs) + if (NOT CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE) endif() + + # cmake testing only on posix + enable_testing() + include(CTest) endif() #============================================================================= @@ -256,13 +259,6 @@ if (CCACHE AND CCACHE_PROGRAM) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") endif() -#============================================================================= -# project definition -# -project(px4 CXX C ASM) - -set(package-contact "px4users@googlegroups.com") - #============================================================================= # find programs and packages # @@ -281,12 +277,6 @@ endif() find_package(PythonInterp REQUIRED) px4_find_python_module(jinja2 REQUIRED) -#============================================================================= -# cmake testing -# -enable_testing() -include(CTest) - #============================================================================= # generate compile command database # @@ -368,6 +358,8 @@ px4_generate_airframes_xml(BOARD ${BOARD}) # DriverFramework # +px4_add_git_submodule(TARGET git_driverframework PATH "src/lib/DriverFramework") + # List the DriverFramework drivers if (DEFINED config_df_driver_list) message("DF Drivers: ${config_df_driver_list}") diff --git a/Tools/check_submodules.sh b/Tools/check_submodules.sh index 5fdc26acfc..6301c4f3e8 100755 --- a/Tools/check_submodules.sh +++ b/Tools/check_submodules.sh @@ -34,8 +34,8 @@ then echo "Continuing build with manually overridden submodule.." elif [ "$user_cmd" == "u" ] then - git submodule sync --recursive - git submodule update --init --recursive + git submodule sync --recursive -- $1 + git submodule update --init --recursive -- $1 echo "Submodule fixed, continuing build.." else echo "Build aborted." @@ -43,10 +43,9 @@ then fi fi else - echo "REINITIALIZING GIT SUBMODULES" - echo "no git repo found in $1/.git" + echo "REINITIALIZING GIT SUBMODULE $1" git submodule sync --recursive -- $1; - git submodule update --init --recursive $1; + git submodule update --init --recursive -- $1; fi } @@ -54,15 +53,14 @@ fi # If called with a path then respect $GIT_SUBMODULES_ARE_EVIL but do normal processing if [ "$#" != "0" ]; then -# called with a path then process only that path but respect $GIT_SUBMODULES_ARE_EVIL - + # called with a path then process only that path but respect $GIT_SUBMODULES_ARE_EVIL [ -n "$GIT_SUBMODULES_ARE_EVIL" ] && { # GIT_SUBMODULES_ARE_EVIL is set, meaning user doesn't want submodules updated echo "GIT_SUBMODULES_ARE_EVIL is defined - Skipping submodules $1 update." exit 0 } - git submodule update --recursive $1 + git submodule update --init --recursive -- $1 else @@ -79,4 +77,5 @@ else done fi - exit 0 + +exit 0 diff --git a/cmake/common/px4_git.cmake b/cmake/common/px4_git.cmake index b0877e2773..be6f74a474 100644 --- a/cmake/common/px4_git.cmake +++ b/cmake/common/px4_git.cmake @@ -68,6 +68,10 @@ function(px4_add_git_submodule) REQUIRED TARGET PATH ARGN ${ARGN}) + execute_process(COMMAND ${PX4_SOURCE_DIR}/Tools/check_submodules.sh ${PATH} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + string(REPLACE "/" "_" NAME ${PATH}) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git_init_${NAME}.stamp diff --git a/platforms/nuttx/NuttX/CMakeLists.txt b/platforms/nuttx/NuttX/CMakeLists.txt index 4a14d79388..be409c7953 100644 --- a/platforms/nuttx/NuttX/CMakeLists.txt +++ b/platforms/nuttx/NuttX/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.2) +px4_add_git_submodule(TARGET git_nuttx PATH "nuttx") +px4_add_git_submodule(TARGET git_nuttx_apps PATH "apps") + if(NOT BOARD) message(FATAL_ERROR "BOARD must be set (eg px4fmu-v2)") endif() @@ -40,7 +43,7 @@ file(RELATIVE_PATH CP_SRC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR add_custom_command(OUTPUT nuttx_copy.stamp COMMAND ${cp_cmd} ${cp_opts} ${CP_SRC} . COMMAND cmake -E touch nuttx_copy.stamp - DEPENDS ${copy_nuttx_files} + DEPENDS ${copy_nuttx_files} git_nuttx COMMENT "Copying NuttX/nuttx to ${CMAKE_CURRENT_BINARY_DIR}" ) @@ -52,7 +55,7 @@ file(RELATIVE_PATH CP_SRC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR add_custom_command(OUTPUT apps_copy.stamp COMMAND ${cp_cmd} ${cp_opts} ${CMAKE_CURRENT_SOURCE_DIR}/apps . COMMAND cmake -E touch apps_copy.stamp - DEPENDS ${copy_apps_files} + DEPENDS ${copy_apps_files} git_nuttx_apps COMMENT "Copying NuttX/apps to ${CMAKE_CURRENT_BINARY_DIR}" ) set(APPS_DIR ${PX4_BINARY_DIR}/NuttX/apps) diff --git a/src/drivers/gps/CMakeLists.txt b/src/drivers/gps/CMakeLists.txt index d22e084820..b027f163e4 100644 --- a/src/drivers/gps/CMakeLists.txt +++ b/src/drivers/gps/CMakeLists.txt @@ -30,11 +30,13 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ + +px4_add_git_submodule(TARGET git_gps_devices PATH "devices") + px4_add_module( MODULE drivers__gps MAIN gps STACK_MAIN 1200 - COMPILE_FLAGS SRCS gps.cpp devices/src/gps_helper.cpp @@ -43,5 +45,5 @@ px4_add_module( devices/src/ubx.cpp DEPENDS platforms__common + git_gps_devices ) -# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/firmware/posix/CMakeLists.txt b/src/firmware/posix/CMakeLists.txt index bdf7c384b1..781947d34e 100644 --- a/src/firmware/posix/CMakeLists.txt +++ b/src/firmware/posix/CMakeLists.txt @@ -107,7 +107,9 @@ elseif ("${BOARD}" STREQUAL "bebop") elseif ("${BOARD}" STREQUAL "sitl") include(./sitl_target.cmake) - include(./sitl_tests.cmake) + if(BUILD_TESTING) + include(./sitl_tests.cmake) + endif() else() diff --git a/src/firmware/posix/sitl_target.cmake b/src/firmware/posix/sitl_target.cmake index c1a3a94c41..7dcac0d9d3 100644 --- a/src/firmware/posix/sitl_target.cmake +++ b/src/firmware/posix/sitl_target.cmake @@ -1,6 +1,6 @@ function(px4_add_sitl_app) -px4_parse_function_args(NAME px4_add_sitl_app + px4_parse_function_args(NAME px4_add_sitl_app ONE_VALUE APP_NAME MAIN_SRC UPLOAD_NAME REQUIRED APP_NAME MAIN_SRC ARGN ${ARGN} @@ -56,11 +56,14 @@ add_custom_target(run_config ${config_sitl_model} ${PX4_SOURCE_DIR} ${PX4_BINARY_DIR} - WORKING_DIRECTORY ${SITL_WORKING_DIR} - USES_TERMINAL + WORKING_DIRECTORY ${SITL_WORKING_DIR} + USES_TERMINAL DEPENDS px4 logs_symlink ) +px4_add_git_submodule(TARGET git_gazebo PATH "${PX4_SOURCE_DIR}/Tools/sitl_gazebo") +px4_add_git_submodule(TARGET git_jmavsim PATH "${PX4_SOURCE_DIR}/Tools/jMAVSim") + # Add support for external project building include(ExternalProject) @@ -70,13 +73,16 @@ ExternalProject_Add(sitl_gazebo CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} BINARY_DIR ${PX4_BINARY_DIR}/build_gazebo INSTALL_COMMAND "" + DEPENDS + git_gazebo ) set_target_properties(sitl_gazebo PROPERTIES EXCLUDE_FROM_ALL TRUE) ExternalProject_Add_Step(sitl_gazebo forceconfigure DEPENDEES update DEPENDERS configure - ALWAYS 1) + ALWAYS 1 + ) # create targets for each viewer/model/debugger combination set(viewers none jmavsim gazebo replay) @@ -123,9 +129,10 @@ foreach(viewer ${viewers}) ${model} ${PX4_SOURCE_DIR} ${PX4_BINARY_DIR} - WORKING_DIRECTORY ${SITL_WORKING_DIR} - USES_TERMINAL - DEPENDS logs_symlink + WORKING_DIRECTORY ${SITL_WORKING_DIR} + USES_TERMINAL + DEPENDS + logs_symlink ) list(APPEND all_posix_vmd_make_targets ${_targ_name}) if (viewer STREQUAL "gazebo") @@ -133,6 +140,8 @@ foreach(viewer ${viewers}) if (viewer STREQUAL "gazebo") add_dependencies(${_targ_name} px4_${model}) endif() + elseif(viewer STREQUAL "jmavsim") + add_dependencies(${_targ_name} git_jmavsim) endif() endforeach() endforeach() diff --git a/src/modules/ekf2/CMakeLists.txt b/src/modules/ekf2/CMakeLists.txt index 453ac3c113..4a69cd46fb 100644 --- a/src/modules/ekf2/CMakeLists.txt +++ b/src/modules/ekf2/CMakeLists.txt @@ -43,4 +43,3 @@ px4_add_module( platforms__common git_ecl ) -# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/modules/mavlink/CMakeLists.txt b/src/modules/mavlink/CMakeLists.txt index ef8cbecf7b..f98c888c85 100644 --- a/src/modules/mavlink/CMakeLists.txt +++ b/src/modules/mavlink/CMakeLists.txt @@ -31,7 +31,8 @@ # ############################################################################ -include_directories(${PX4_SOURCE_DIR}/mavlink/include/mavlink) +px4_add_git_submodule(TARGET git_mavlink PATH "${PX4_SOURCE_DIR}/mavlink/include/mavlink/v1.0") +px4_add_git_submodule(TARGET git_mavlink2 PATH "${PX4_SOURCE_DIR}/mavlink/include/mavlink/v2.0") px4_add_module( MODULE modules__mavlink @@ -41,6 +42,8 @@ px4_add_module( COMPILE_FLAGS -Wno-extra-semi -Wno-sign-compare # TODO: fix all sign-compare + INCLUDES + ${PX4_SOURCE_DIR}/mavlink/include/mavlink SRCS mavlink.c mavlink_command_sender.cpp @@ -58,5 +61,6 @@ px4_add_module( mavlink_ulog.cpp DEPENDS platforms__common + git_mavlink + git_mavlink2 ) -# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/modules/simulator/CMakeLists.txt b/src/modules/simulator/CMakeLists.txt index 3de83e51a1..6796b0abd8 100644 --- a/src/modules/simulator/CMakeLists.txt +++ b/src/modules/simulator/CMakeLists.txt @@ -63,8 +63,4 @@ px4_add_module( ${SIMULATOR_SRCS} DEPENDS platforms__common - git_jmavsim - git_gazebo ) - -# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/modules/uavcan/CMakeLists.txt b/src/modules/uavcan/CMakeLists.txt index eb0fab8316..7197c45418 100644 --- a/src/modules/uavcan/CMakeLists.txt +++ b/src/modules/uavcan/CMakeLists.txt @@ -31,6 +31,8 @@ # ############################################################################ +px4_add_git_submodule(TARGET git_uavcan PATH "libuavcan") + set(UAVCAN_USE_CPP03 ON CACHE BOOL "uavcan cpp03") set(UAVCAN_PLATFORM stm32 CACHE STRING "uavcan platform") @@ -50,20 +52,19 @@ add_definitions( ) add_subdirectory(libuavcan EXCLUDE_FROM_ALL) -add_dependencies(uavcan platforms__nuttx) - -include_directories(${PX4_SOURCE_DIR}/mavlink/include/mavlink) -include_directories(libuavcan/libuavcan/include) -include_directories(libuavcan/libuavcan/include/dsdlc_generated) -include_directories(libuavcan/libuavcan_drivers/posix/include) -include_directories(libuavcan/libuavcan_drivers/stm32/driver/include) +add_dependencies(uavcan prebuild_targets) px4_add_module( MODULE modules__uavcan MAIN uavcan STACK_MAIN 3200 STACK_MAX 1500 - COMPILE_FLAGS + INCLUDES + ${PX4_SOURCE_DIR}/mavlink/include/mavlink + libuavcan/libuavcan/include + libuavcan/libuavcan/include/dsdlc_generated + libuavcan/libuavcan_drivers/posix/include + libuavcan/libuavcan_drivers/stm32/driver/include SRCS # Main uavcan_main.cpp @@ -81,8 +82,10 @@ px4_add_module( sensors/baro.cpp DEPENDS + git_uavcan platforms__common uavcan + uavcan_stm32_driver ) target_link_libraries(modules__uavcan uavcan uavcan_stm32_driver)