From 68a78b0580682af83c7c7f45dfb23d699a333e25 Mon Sep 17 00:00:00 2001 From: James Goppert Date: Sat, 12 Sep 2015 00:49:10 -0400 Subject: [PATCH] Some cleanup of cmake module build. --- CMakeLists.txt | 1 + cmake/common/px4_base.cmake | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04efb3c89c..a3c277559b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,7 @@ project(px4 CXX C ASM) if (NOT ${CMAKE_VERSION} VERSION_LESS 3.0.0) cmake_policy(SET CMP0045 NEW) # error on non-existent target in get prop cmake_policy(SET CMP0046 NEW) # no non-existent targets as dependencies + cmake_policy(SET CMP0054 NEW) # don't dereference quoted variables endif() set(version_major 1) diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index 0142d21736..38ae2f7e2f 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -254,33 +254,44 @@ endfunction() # ) # function(px4_add_module) + px4_parse_function_args( NAME px4_add_module ONE_VALUE MODULE MAIN STACK PRIORITY MULTI_VALUE COMPILE_FLAGS LINK_FLAGS SRCS INCLUDES DEPENDS REQUIRED MODULE ARGN ${ARGN}) + add_library(${MODULE} STATIC EXCLUDE_FROM_ALL ${SRCS}) + if(INCLUDES) target_include_directories(${MODULE} ${INCLUDES}) endif() + if(DEPENDS) add_dependencies(${MODULE} ${DEPENDS}) endif() + + if(MAIN) + target_compile_definitions(${MODULE} PUBLIC -DPX4_MAIN=${MAIN}_app_main) + endif() + + # join list variables to get ready to send to compiler foreach(prop LINK_FLAGS COMPILE_FLAGS) if(${prop}) px4_join(OUT ${prop} LIST ${${prop}} GLUE " ") endif() endforeach() - foreach (prop STACK MAIN COMPILE_FLAGS LINK_FLAGS PRIORITY) - if ("${prop}" STREQUAL "MAIN") - add_definitions(-DPX4_MAIN=${${prop}}_app_main) - endif() + + # store module properties in target + # COMPILE_FLAGS and LINK_FLAGS are passed to compiler/linker by cmake + # STACK, MAIN, PRIORITY are PX4 specific + foreach (prop COMPILE_FLAGS LINK_FLAGS STACK MAIN PRIORITY) if (${prop}) - set_target_properties(${MODULE} PROPERTIES "${prop}" "${${prop}}") + set_target_properties(${MODULE} PROPERTIES ${prop} ${${prop}}) endif() endforeach() - set_target_properties(${MODULE} PROPERTIES LINK_INTERFACE_MULTIPLICITY 4) + endfunction() #=============================================================================