forked from Archive/PX4-Autopilot
cmake: add support for out-of-tree modules via EXTERNAL_MODULES_LOCATION variable
This commit is contained in:
parent
65e3ae70dd
commit
670c93e726
|
@ -146,6 +146,7 @@ set_property(CACHE CONFIG PROPERTY STRINGS ${configs})
|
||||||
set(THREADS "4" CACHE STRING
|
set(THREADS "4" CACHE STRING
|
||||||
"number of threads to use for external build processes")
|
"number of threads to use for external build processes")
|
||||||
set(DEBUG_PORT "/dev/ttyACM0" CACHE STRING "debugging port")
|
set(DEBUG_PORT "/dev/ttyACM0" CACHE STRING "debugging port")
|
||||||
|
set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location")
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# configuration
|
# configuration
|
||||||
|
@ -371,6 +372,24 @@ foreach(driver ${config_df_driver_list})
|
||||||
message("Adding DF driver: ${driver}")
|
message("Adding DF driver: ${driver}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# external modules
|
||||||
|
#
|
||||||
|
if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "")
|
||||||
|
message(STATUS "External modules: ${EXTERNAL_MODULES_LOCATION}")
|
||||||
|
add_subdirectory("${EXTERNAL_MODULES_LOCATION}/src" external_modules_src)
|
||||||
|
|
||||||
|
set(config_module_list_external_expanded)
|
||||||
|
foreach(external_module ${config_module_list_external})
|
||||||
|
list(APPEND config_module_list_external_expanded
|
||||||
|
${EXTERNAL_MODULES_LOCATION}/src/${external_module})
|
||||||
|
endforeach()
|
||||||
|
set(config_module_list
|
||||||
|
${config_module_list}
|
||||||
|
${config_module_list_external_expanded}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# subdirectories
|
# subdirectories
|
||||||
#
|
#
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -114,6 +114,12 @@ else
|
||||||
BUILD_DIR_SUFFIX :=
|
BUILD_DIR_SUFFIX :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# additional config parameters passed to cmake
|
||||||
|
CMAKE_ARGS :=
|
||||||
|
ifdef EXTERNAL_MODULES_LOCATION
|
||||||
|
CMAKE_ARGS := -DEXTERNAL_MODULES_LOCATION:STRING=$(EXTERNAL_MODULES_LOCATION)
|
||||||
|
endif
|
||||||
|
|
||||||
SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
@ -122,7 +128,7 @@ SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
define cmake-build
|
define cmake-build
|
||||||
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
|
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
|
||||||
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
|
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
|
||||||
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi
|
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) $(CMAKE_ARGS) || (cd .. && rm -rf $(BUILD_DIR)); fi
|
||||||
+@echo "PX4 CONFIG: $(BUILD_DIR)"
|
+@echo "PX4 CONFIG: $(BUILD_DIR)"
|
||||||
+@$(PX4_MAKE) -C "$(BUILD_DIR)" $(PX4_MAKE_ARGS) $(ARGS)
|
+@$(PX4_MAKE) -C "$(BUILD_DIR)" $(PX4_MAKE_ARGS) $(ARGS)
|
||||||
endef
|
endef
|
||||||
|
|
|
@ -231,6 +231,7 @@ endfunction()
|
||||||
# [ COMPILE_FLAGS <list> ]
|
# [ COMPILE_FLAGS <list> ]
|
||||||
# [ INCLUDES <list> ]
|
# [ INCLUDES <list> ]
|
||||||
# [ DEPENDS <string> ]
|
# [ DEPENDS <string> ]
|
||||||
|
# [ EXTERNAL ]
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
# Input:
|
# Input:
|
||||||
|
@ -244,6 +245,7 @@ endfunction()
|
||||||
# SRCS : source files
|
# SRCS : source files
|
||||||
# INCLUDES : include directories
|
# INCLUDES : include directories
|
||||||
# DEPENDS : targets which this module depends on
|
# DEPENDS : targets which this module depends on
|
||||||
|
# EXTERNAL : flag to indicate that this module is out-of-tree
|
||||||
#
|
#
|
||||||
# Output:
|
# Output:
|
||||||
# Static library with name matching MODULE.
|
# Static library with name matching MODULE.
|
||||||
|
@ -263,9 +265,14 @@ function(px4_add_module)
|
||||||
NAME px4_add_module
|
NAME px4_add_module
|
||||||
ONE_VALUE MODULE MAIN STACK STACK_MAIN STACK_MAX PRIORITY
|
ONE_VALUE MODULE MAIN STACK STACK_MAIN STACK_MAX PRIORITY
|
||||||
MULTI_VALUE COMPILE_FLAGS LINK_FLAGS SRCS INCLUDES DEPENDS
|
MULTI_VALUE COMPILE_FLAGS LINK_FLAGS SRCS INCLUDES DEPENDS
|
||||||
|
OPTIONS EXTERNAL
|
||||||
REQUIRED MODULE
|
REQUIRED MODULE
|
||||||
ARGN ${ARGN})
|
ARGN ${ARGN})
|
||||||
|
|
||||||
|
if(EXTERNAL)
|
||||||
|
px4_mangle_name("${EXTERNAL_MODULES_LOCATION}/src/${MODULE}" MODULE)
|
||||||
|
endif()
|
||||||
|
|
||||||
px4_add_library(${MODULE} STATIC EXCLUDE_FROM_ALL ${SRCS})
|
px4_add_library(${MODULE} STATIC EXCLUDE_FROM_ALL ${SRCS})
|
||||||
|
|
||||||
# set defaults if not set
|
# set defaults if not set
|
||||||
|
|
Loading…
Reference in New Issue