2018-03-22 06:27:10 +00:00
|
|
|
# Given a list of components in 'component_paths', filter only paths to the components
|
|
|
|
# mentioned in 'components' and return as a list in 'result_paths'
|
|
|
|
function(components_get_paths component_paths components result_paths)
|
|
|
|
set(result "")
|
|
|
|
foreach(path ${component_paths})
|
|
|
|
get_filename_component(name "${path}" NAME)
|
|
|
|
if("${name}" IN_LIST components)
|
|
|
|
list(APPEND result "${name}")
|
2018-02-27 04:45:30 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2018-03-22 06:27:10 +00:00
|
|
|
set("${result_path}" "${result}" PARENT_SCOPE)
|
2018-02-27 04:45:30 +00:00
|
|
|
endfunction()
|
2018-01-12 02:49:13 +00:00
|
|
|
|
|
|
|
# Add a component to the build, using the COMPONENT variables defined
|
|
|
|
# in the parent
|
|
|
|
#
|
|
|
|
function(register_component)
|
2018-02-27 04:45:30 +00:00
|
|
|
get_filename_component(component_dir ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
|
|
|
|
|
2019-03-06 04:18:38 +00:00
|
|
|
spaces2list(COMPONENT_SRCS)
|
2018-02-27 04:45:30 +00:00
|
|
|
spaces2list(COMPONENT_SRCDIRS)
|
|
|
|
spaces2list(COMPONENT_ADD_INCLUDEDIRS)
|
2018-05-30 07:55:44 +00:00
|
|
|
spaces2list(COMPONENT_SRCEXCLUDE)
|
2018-02-27 04:45:30 +00:00
|
|
|
|
2018-09-11 01:44:12 +00:00
|
|
|
if(COMPONENT_SRCDIRS)
|
|
|
|
# Warn user if both COMPONENT_SRCDIRS and COMPONENT_SRCS are set
|
|
|
|
if(COMPONENT_SRCS)
|
|
|
|
message(WARNING "COMPONENT_SRCDIRS and COMPONENT_SRCS are both set, COMPONENT_SRCS will be ignored")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(COMPONENT_SRCS "")
|
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
foreach(dir ${COMPONENT_SRCDIRS})
|
|
|
|
get_filename_component(abs_dir ${dir} ABSOLUTE BASE_DIR ${component_dir})
|
|
|
|
if(NOT IS_DIRECTORY ${abs_dir})
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_SRCDIRS entry '${dir}' does not exist")
|
|
|
|
endif()
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
file(GLOB matches "${abs_dir}/*.c" "${abs_dir}/*.cpp" "${abs_dir}/*.S")
|
|
|
|
if(matches)
|
|
|
|
list(SORT matches)
|
|
|
|
set(COMPONENT_SRCS "${COMPONENT_SRCS};${matches}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_SRCDIRS entry '${dir}' has no source files")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2018-01-19 05:22:08 +00:00
|
|
|
endif()
|
|
|
|
|
2018-05-30 07:55:44 +00:00
|
|
|
# Remove COMPONENT_SRCEXCLUDE matches
|
|
|
|
foreach(exclude ${COMPONENT_SRCEXCLUDE})
|
|
|
|
get_filename_component(exclude "${exclude}" ABSOLUTE ${component_dir})
|
|
|
|
foreach(src ${COMPONENT_SRCS})
|
|
|
|
get_filename_component(abs_src "${src}" ABSOLUTE ${component_dir})
|
|
|
|
if("${exclude}" STREQUAL "${abs_src}") # compare as canonical paths
|
2018-06-06 06:27:44 +00:00
|
|
|
list(REMOVE_ITEM COMPONENT_SRCS "${src}")
|
2018-05-30 07:55:44 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
|
2018-03-22 06:27:10 +00:00
|
|
|
# add as a PUBLIC library (if there are source files) or INTERFACE (if header only)
|
2018-02-27 04:45:30 +00:00
|
|
|
if(COMPONENT_SRCS OR embed_binaries)
|
2018-11-11 07:36:10 +00:00
|
|
|
add_library(${COMPONENT_TARGET} STATIC ${COMPONENT_SRCS})
|
2018-02-27 04:45:30 +00:00
|
|
|
set(include_type PUBLIC)
|
2018-11-11 07:36:10 +00:00
|
|
|
|
|
|
|
set_property(TARGET ${COMPONENT_TARGET} PROPERTY OUTPUT_NAME ${COMPONENT_NAME})
|
2018-11-27 05:26:15 +00:00
|
|
|
|
|
|
|
ldgen_generate_sections_info(${COMPONENT_TARGET})
|
2018-02-27 04:45:30 +00:00
|
|
|
else()
|
2018-11-11 07:36:10 +00:00
|
|
|
add_library(${COMPONENT_TARGET} INTERFACE) # header-only component
|
2018-02-27 04:45:30 +00:00
|
|
|
set(include_type INTERFACE)
|
2018-01-12 02:49:13 +00:00
|
|
|
endif()
|
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
# binaries to embed directly in library
|
|
|
|
spaces2list(COMPONENT_EMBED_FILES)
|
|
|
|
spaces2list(COMPONENT_EMBED_TXTFILES)
|
|
|
|
foreach(embed_data ${COMPONENT_EMBED_FILES} ${COMPONENT_EMBED_TXTFILES})
|
|
|
|
if(embed_data IN_LIST COMPONENT_EMBED_TXTFILES)
|
|
|
|
set(embed_type "TEXT")
|
|
|
|
else()
|
|
|
|
set(embed_type "BINARY")
|
|
|
|
endif()
|
2018-11-11 07:36:10 +00:00
|
|
|
target_add_binary_data("${COMPONENT_TARGET}" "${embed_data}" "${embed_type}")
|
2018-02-27 04:45:30 +00:00
|
|
|
endforeach()
|
|
|
|
|
2018-03-22 06:27:10 +00:00
|
|
|
# add component public includes
|
2018-02-27 04:45:30 +00:00
|
|
|
foreach(include_dir ${COMPONENT_ADD_INCLUDEDIRS})
|
|
|
|
get_filename_component(abs_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir})
|
|
|
|
if(NOT IS_DIRECTORY ${abs_dir})
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: "
|
|
|
|
"COMPONENT_ADD_INCLUDEDIRS entry '${include_dir}' not found")
|
|
|
|
endif()
|
2018-11-11 07:36:10 +00:00
|
|
|
target_include_directories(${COMPONENT_TARGET} ${include_type} ${abs_dir})
|
2018-02-27 04:45:30 +00:00
|
|
|
endforeach()
|
|
|
|
|
2018-03-22 06:27:10 +00:00
|
|
|
# add component private includes
|
2018-02-27 04:45:30 +00:00
|
|
|
foreach(include_dir ${COMPONENT_PRIV_INCLUDEDIRS})
|
|
|
|
if(${include_type} STREQUAL INTERFACE)
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE} "
|
|
|
|
"sets no component source files but sets COMPONENT_PRIV_INCLUDEDIRS")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_filename_component(abs_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir})
|
|
|
|
if(NOT IS_DIRECTORY ${abs_dir})
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: "
|
|
|
|
"COMPONENT_PRIV_INCLUDEDIRS entry '${include_dir}' does not exist")
|
|
|
|
endif()
|
2018-11-11 07:36:10 +00:00
|
|
|
target_include_directories(${COMPONENT_TARGET} PRIVATE ${abs_dir})
|
2018-02-27 04:45:30 +00:00
|
|
|
endforeach()
|
2018-08-27 02:48:16 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
if(${COMPONENT_NAME} IN_LIST BUILD_TEST_COMPONENTS)
|
|
|
|
target_link_libraries(${COMPONENT_TARGET} "-L${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
target_link_libraries(${COMPONENT_TARGET} "-Wl,--whole-archive -l${COMPONENT_NAME} -Wl,--no-whole-archive")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(COMPONENT_SRCS OR embed_binaries)
|
|
|
|
target_include_directories(${COMPONENT_TARGET} PUBLIC ${IDF_INCLUDE_DIRECTORIES})
|
|
|
|
target_compile_options(${COMPONENT_TARGET} PUBLIC ${IDF_COMPILE_OPTIONS})
|
|
|
|
target_compile_options(${COMPONENT_TARGET} PUBLIC $<$<COMPILE_LANGUAGE:C>:${IDF_C_COMPILE_OPTIONS}>)
|
|
|
|
target_compile_options(${COMPONENT_TARGET} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:${IDF_CXX_COMPILE_OPTIONS}>)
|
|
|
|
target_compile_definitions(${COMPONENT_TARGET} PUBLIC ${IDF_COMPILE_DEFINITIONS})
|
2018-08-27 02:48:16 +00:00
|
|
|
endif()
|
2018-04-18 02:57:45 +00:00
|
|
|
|
|
|
|
if(COMPONENT_ADD_LDFRAGMENTS)
|
|
|
|
spaces2list(COMPONENT_ADD_LDFRAGMENTS)
|
2018-11-11 07:36:10 +00:00
|
|
|
ldgen_add_fragment_files(${COMPONENT_TARGET} "${COMPONENT_ADD_LDFRAGMENTS}")
|
2018-08-27 02:48:16 +00:00
|
|
|
endif()
|
2019-06-25 03:00:30 +00:00
|
|
|
|
|
|
|
set(COMPONENT_TARGET ${COMPONENT_NAME} PARENT_SCOPE)
|
2018-02-27 04:45:30 +00:00
|
|
|
endfunction()
|
2018-01-12 02:49:13 +00:00
|
|
|
|
|
|
|
function(register_config_only_component)
|
2018-02-27 04:45:30 +00:00
|
|
|
get_filename_component(component_dir ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
|
|
|
|
get_filename_component(component ${component_dir} NAME)
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
# No-op for now...
|
|
|
|
endfunction()
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-03-22 06:27:10 +00:00
|
|
|
function(add_component_dependencies target dep dep_type)
|
|
|
|
get_target_property(target_type ${target} TYPE)
|
|
|
|
get_target_property(target_imported ${target} IMPORTED)
|
|
|
|
|
|
|
|
if(${target_type} STREQUAL STATIC_LIBRARY OR ${target_type} STREQUAL EXECUTABLE)
|
|
|
|
if(TARGET ${dep})
|
|
|
|
# Add all compile options exported by dep into target
|
|
|
|
target_include_directories(${target} ${dep_type}
|
|
|
|
$<TARGET_PROPERTY:${dep},INTERFACE_INCLUDE_DIRECTORIES>)
|
|
|
|
target_compile_definitions(${target} ${dep_type}
|
|
|
|
$<TARGET_PROPERTY:${dep},INTERFACE_COMPILE_DEFINITIONS>)
|
|
|
|
target_compile_options(${target} ${dep_type}
|
|
|
|
$<TARGET_PROPERTY:${dep},INTERFACE_COMPILE_OPTIONS>)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2018-10-19 03:51:51 +00:00
|
|
|
function(require_idf_targets)
|
|
|
|
if(NOT ${IDF_TARGET} IN_LIST ARGN)
|
|
|
|
message(FATAL_ERROR "Component ${COMPONENT_NAME} only supports targets: ${ARGN}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2018-03-01 06:02:08 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
# component_compile_options
|
|
|
|
#
|
|
|
|
# Wrapper around target_compile_options that passes the component name
|
|
|
|
function(component_compile_options)
|
|
|
|
target_compile_options(${COMPONENT_TARGET} PRIVATE ${ARGV})
|
|
|
|
endfunction()
|
2018-01-19 04:47:49 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
# component_compile_definitions
|
|
|
|
#
|
|
|
|
# Wrapper around target_compile_definitions that passes the component name
|
|
|
|
function(component_compile_definitions)
|
|
|
|
target_compile_definitions(${COMPONENT_TARGET} PRIVATE ${ARGV})
|
2018-02-27 04:45:30 +00:00
|
|
|
endfunction()
|
2018-02-22 04:05:05 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
# component_get_target
|
|
|
|
#
|
|
|
|
# Get the library target created for the given component
|
|
|
|
function(component_get_target var component)
|
|
|
|
get_property(prefix GLOBAL PROPERTY __IDF_COMPONENTS_PREFIX)
|
|
|
|
set(${var} ${prefix}_${component} PARENT_SCOPE)
|
2018-02-27 04:45:30 +00:00
|
|
|
endfunction()
|