Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake remove circular linking and reorganize #9292

Merged
merged 2 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
113 changes: 42 additions & 71 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#
# * Avoid use of global variables in functions. Functions in a nested
# scope may use global variables, but this makes it difficult to
# resuse functions.
# reuse functions.
#
# Included CMake Files
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -99,18 +99,12 @@
#
#=============================================================================

# Warning: Changing this modifies CMake's internal workings
# and leads to wrong toolchain detection
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)

set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR})

list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH "${PX4_SOURCE_DIR}/cmake")

#=============================================================================
# git
Expand All @@ -124,14 +118,16 @@ execute_process(
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)

px4_add_git_submodule(TARGET git_ecl PATH "src/lib/ecl")
px4_add_git_submodule(TARGET git_matrix PATH "src/lib/matrix")

define_property(GLOBAL PROPERTY PX4_LIBRARIES
BRIEF_DOCS "PX4 libs"
define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES
BRIEF_DOCS "PX4 module libs"
FULL_DOCS "List of all PX4 module libraries"
)

define_property(GLOBAL PROPERTY PX4_MODULE_PATHS
BRIEF_DOCS "PX4 module paths"
FULL_DOCS "List of paths to all PX4 modules"
)

#=============================================================================
# configuration
#
Expand All @@ -142,10 +138,6 @@ string(REPLACE "_" ";" config_args ${CONFIG})
list(GET config_args 0 OS)
list(GET config_args 1 BOARD)
list(GET config_args 2 LABEL)
set(target_name "${OS}_${BOARD}_${LABEL}")

file(GLOB_RECURSE configs RELATIVE cmake/configs "cmake/configs/*.cmake")
set_property(CACHE CONFIG PROPERTY STRINGS ${configs})

set(THREADS "4" CACHE STRING "number of threads to use for external build processes")
set(DEBUG_PORT "/dev/ttyACM0" CACHE STRING "debugging port")
Expand All @@ -155,22 +147,14 @@ if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
get_filename_component(EXTERNAL_MODULES_LOCATION "${EXTERNAL_MODULES_LOCATION}" ABSOLUTE)
endif()

list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${OS}/cmake)

include(platforms/${OS}/cmake/px4_impl_os.cmake)
set(config_module "configs/${CONFIG}")
include(${config_module})

include(common/coverage)
include(common/sanitizers)
include(configs/${CONFIG})
list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${OS}/cmake)

# CMake build type
# Debug Release RelWithDebInfo MinSizeRel Coverage
# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage)
if (NOT CMAKE_BUILD_TYPE)
if (${OS} STREQUAL "nuttx")
set(PX4_BUILD_TYPE "MinSizeRel")
elseif (${OS} STREQUAL "bebop")
set(PX4_BUILD_TYPE "MinSizeRel")
else()
set(PX4_BUILD_TYPE "RelWithDebInfo")
endif()
Expand All @@ -180,12 +164,10 @@ endif()

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage")

message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")

#=============================================================================

message(STATUS "PX4 VERSION: ${git_tag}")
message(STATUS "CONFIG: ${target_name}")
message(STATUS "CONFIG: ${CONFIG}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")

#=============================================================================
Expand All @@ -195,20 +177,23 @@ 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})
set(BUILD_URI $ENV{BUILD_URI})
else()
set(BUILD_URI "localhost")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR})

add_definitions(-DBUILD_URI=${BUILD_URI})
#=============================================================================

# Setup install paths
if (${OS} STREQUAL "posix")

include(common/coverage)
include(common/sanitizers)

# Define GNU standard installation directories
include(GNUInstallDirs)

Expand All @@ -229,28 +214,24 @@ set(px4_required_interface
)
foreach(cmd ${px4_required_interface})
if (NOT COMMAND ${cmd})
message(FATAL_ERROR "${config_module} must implement ${cmd}")
message(FATAL_ERROR "${CONFIG} must implement ${cmd}")
endif()
endforeach()

set(px4_required_config config_module_list)
foreach(conf ${px4_required_config})
if (NOT DEFINED ${conf})
message(FATAL_ERROR "cmake/${config_module} must define ${conf}")
message(FATAL_ERROR "cmake/${CONFIG} must define ${conf}")
endif()
endforeach()

# force static lib build
set(BUILD_SHARED_LIBS OFF)

#=============================================================================
# ccache
#
option(CCACHE "Use ccache if available" ON)
find_program(CCACHE_PROGRAM ccache)
if (CCACHE AND CCACHE_PROGRAM AND NOT DEFINED ENV{CCACHE_DISABLE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
else()
endif()

#=============================================================================
Expand All @@ -271,23 +252,10 @@ endif()
find_package(PythonInterp REQUIRED)
px4_find_python_module(jinja2 REQUIRED)

#=============================================================================
# generate compile command database
#
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#=============================================================================
# check required toolchain variables
#

# PX4 requires c++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# PX4 requires c99
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(required_variables CMAKE_C_COMPILER_ID CMAKE_CXX_COMPILER_ID)
foreach(var ${required_variables})
if (NOT ${var})
Expand Down Expand Up @@ -335,24 +303,20 @@ px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${CMAKE_EXE_LINKER_FLAGS};${exe_linker
px4_join(OUT CMAKE_C_FLAGS LIST "${CMAKE_C_FLAGS};${c_flags};${optimization_flags}" GLUE " ")
px4_join(OUT CMAKE_CXX_FLAGS LIST "${CMAKE_CXX_FLAGS};${cxx_flags};${optimization_flags}" GLUE " ")

include_directories(${include_dirs} ${CMAKE_CURRENT_BINARY_DIR}/src/modules/systemlib/param)
link_directories(${link_dirs})
add_definitions(${definitions})

#=============================================================================
# message, and airframe generation
#
include(common/px4_metadata)

add_subdirectory(msg)
add_subdirectory(msg EXCLUDE_FROM_ALL)

px4_generate_airframes_xml(BOARD ${BOARD})

#=============================================================================
# DriverFramework
#

px4_add_git_submodule(TARGET git_driverframework PATH "src/lib/DriverFramework")
add_subdirectory(src/lib/DriverFramework/framework)

# List the DriverFramework drivers
if (DEFINED config_df_driver_list)
Expand All @@ -369,7 +333,6 @@ endforeach()
#=============================================================================
# external projects
#

set(ep_base ${PX4_BINARY_DIR}/external)
set_property(DIRECTORY PROPERTY EP_BASE ${ep_base})

Expand Down Expand Up @@ -397,12 +360,22 @@ endif()
#=============================================================================
# subdirectories
#
add_subdirectory(src/platforms/common)
add_library(parameters_interface INTERFACE)
add_subdirectory(src/lib EXCLUDE_FROM_ALL)
add_subdirectory(src/platforms/common EXCLUDE_FROM_ALL)
add_subdirectory(src/modules/systemlib EXCLUDE_FROM_ALL) # TODO: split into libraries in platform layer
add_subdirectory(src/modules/uORB EXCLUDE_FROM_ALL) # TODO: platform layer
add_subdirectory(src/drivers/boards EXCLUDE_FROM_ALL)

foreach(module ${config_module_list})
add_subdirectory(src/${module})
endforeach()

# must be the last module before firmware
add_subdirectory(src/lib/parameters EXCLUDE_FROM_ALL)
target_link_libraries(parameters_interface INTERFACE parameters)

# firmware added last to generate the builtin for included modules
add_subdirectory(platforms/${OS})

#=============================================================================
Expand Down Expand Up @@ -450,20 +423,18 @@ set(CPACK_PACKAGE_CONTACT ${package-contact})
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(short-description "The px4 autopilot.")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${short-description})
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "The PX4 Pro autopilot.")
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CONFIG}-${git_tag}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${git_version}")
set(CPACK_SOURCE_GENERATOR "ZIP;TBZ2")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_SET_DESTDIR "OFF")

if ("${CMAKE_SYSTEM}" MATCHES "Linux")
find_program(DPKG_PROGRAM dpkg)
if (EXISTS ${DPKG_PROGRAM})
list (APPEND CPACK_GENERATOR "DEB")
endif()
endif()
include(CPack)

# vim: set noet fenc=utf-8 ff=unix ft=cmake :
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ coverity_scan: posix_sitl_default
.PHONY: parameters_metadata airframe_metadata module_documentation px4_metadata

parameters_metadata:
@python $(SRC_DIR)/src/modules/systemlib/param/px_process_params.py -s `find $(SRC_DIR)/src -maxdepth 4 -type d` --inject-xml $(SRC_DIR)/src/modules/systemlib/param/parameters_injected.xml --markdown
@python $(SRC_DIR)/src/modules/systemlib/param/px_process_params.py -s `find $(SRC_DIR)/src -maxdepth 4 -type d` --inject-xml $(SRC_DIR)/src/modules/systemlib/param/parameters_injected.xml --xml
@python $(SRC_DIR)/src/lib/parameters/px_process_params.py -s `find $(SRC_DIR)/src -maxdepth 4 -type d` --inject-xml $(SRC_DIR)/src/lib/parameters/parameters_injected.xml --markdown
@python $(SRC_DIR)/src/lib/parameters/px_process_params.py -s `find $(SRC_DIR)/src -maxdepth 4 -type d` --inject-xml $(SRC_DIR)/src/lib/parameters/parameters_injected.xml --xml

airframe_metadata:
@python $(SRC_DIR)/Tools/px_process_airframes.py -v -a $(SRC_DIR)/ROMFS/px4fmu_common/init.d --markdown
Expand Down
56 changes: 46 additions & 10 deletions cmake/common/px4_base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,22 @@ function(px4_add_module)
ONE_VALUE MODULE MAIN STACK STACK_MAIN STACK_MAX PRIORITY
MULTI_VALUE COMPILE_FLAGS LINK_FLAGS SRCS INCLUDES DEPENDS
OPTIONS EXTERNAL
REQUIRED MODULE
REQUIRED MODULE MAIN
ARGN ${ARGN})

px4_add_library(${MODULE} STATIC EXCLUDE_FROM_ALL ${SRCS})
add_library(${MODULE} STATIC EXCLUDE_FROM_ALL ${SRCS})

# all modules can potentially use parameters and uORB
add_dependencies(${MODULE} uorb_headers)
target_link_libraries(${MODULE} PRIVATE prebuild_targets parameters_interface platforms__common px4_layer systemlib)

set_property(GLOBAL APPEND PROPERTY PX4_MODULE_LIBRARIES ${MODULE})
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})

px4_add_optimization_flags_for_target(${MODULE})

# Pass variable to the parent px4_add_module.
set(_no_optimization_for_target ${_no_optimization_for_target} PARENT_SCOPE)

# set defaults if not set
set(MAIN_DEFAULT MAIN-NOTFOUND)
Expand Down Expand Up @@ -240,7 +252,16 @@ function(px4_add_module)
endif()

if(DEPENDS)
add_dependencies(${MODULE} ${DEPENDS})
# using target_link_libraries for dependencies provides linking
# as well as interface include and libraries
foreach(dep ${DEPENDS})
get_target_property(dep_type ${dep} TYPE)
if (${dep_type} STREQUAL "STATIC_LIBRARY")
target_link_libraries(${MODULE} PRIVATE ${dep})
else()
add_dependencies(${MODULE} ${dep})
endif()
endforeach()
endif()

# join list variables to get ready to send to compiler
Expand Down Expand Up @@ -425,6 +446,10 @@ function(px4_add_common_flags)
-fdiagnostics-color=always
)
endif()

list(APPEND cxx_warnings
-Wno-format-truncation # TODO: fix
)
endif()

set(visibility_flags
Expand All @@ -450,10 +475,13 @@ function(px4_add_common_flags)
${_optimization_flags}
)

set(added_include_dirs
include_directories(
${PX4_BINARY_DIR}
${PX4_BINARY_DIR}/src
${PX4_BINARY_DIR}/src/lib
${PX4_BINARY_DIR}/src/modules


${PX4_SOURCE_DIR}/src
${PX4_SOURCE_DIR}/src/drivers/boards/${BOARD}
${PX4_SOURCE_DIR}/src/include
Expand All @@ -464,13 +492,10 @@ function(px4_add_common_flags)
${PX4_SOURCE_DIR}/src/platforms
)

set(added_link_dirs) # none used currently
set(added_exe_linker_flags)

string(TOUPPER ${BOARD} board_upper)
string(REPLACE "-" "_" board_config ${board_upper})

set(added_definitions
add_definitions(
-DCONFIG_ARCH_BOARD_${board_config}
-D__STDC_FORMAT_MACROS
)
Expand Down Expand Up @@ -548,13 +573,25 @@ endfunction()
#
function(px4_add_library target)
add_library(${target} ${ARGN})
add_dependencies(${target} prebuild_targets)

target_compile_definitions(${target} PRIVATE MODULE_NAME="${target}")

# all PX4 libraries have access to parameters and uORB
add_dependencies(${target} uorb_headers)
target_link_libraries(${target} PRIVATE prebuild_targets parameters_interface uorb_msgs)

# TODO: move to platform layer
if ("${OS}" MATCHES "nuttx")
target_link_libraries(${target} PRIVATE m nuttx_c)
endif()

px4_add_optimization_flags_for_target(${target})

# Pass variable to the parent px4_add_module.
set(_no_optimization_for_target ${_no_optimization_for_target} PARENT_SCOPE)

set_property(GLOBAL APPEND PROPERTY PX4_LIBRARIES ${target})
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
endfunction()

#=============================================================================
Expand Down Expand Up @@ -596,4 +633,3 @@ function(px4_find_python_module module)
#endif()
endfunction(px4_find_python_module)

# vim: set noet fenc=utf-8 ff=unix nowrap:
Loading