From 17ced7d38a9f1fcefc723420038470b4382f6dad Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 12 Sep 2016 00:13:59 +0200 Subject: o Working version back to listing everything in the cmake file but some help from the cmake libs. --- mcu_include_directories_from_sources.cmake | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 mcu_include_directories_from_sources.cmake (limited to 'mcu_include_directories_from_sources.cmake') diff --git a/mcu_include_directories_from_sources.cmake b/mcu_include_directories_from_sources.cmake new file mode 100644 index 0000000..792b239 --- /dev/null +++ b/mcu_include_directories_from_sources.cmake @@ -0,0 +1,47 @@ +function(mcu_include_directories_from_sources) + set(options) + set(oneValueArgs SOURCES_VAR HEADERS_VAR INCLUDES_VAR) + set(multiValueArgs SOURCE_DIR EXCLUDE) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(ALL_SOURCES) + set(ALL_HEADERS) + set(ALL_INCLUDES) + + foreach (DIR IN LISTS ARGS_SOURCE_DIR) + file(GLOB_RECURSE SOURCES ${DIR}/*.c) + + foreach (E IN LISTS ARGS_EXCLUDE) + list(FILTER SOURCES EXCLUDE REGEX ${E}) + endforeach () + list(APPEND ALL_SOURCES ${SOURCES}) + + file(GLOB_RECURSE HEADERS LIST_DIRECTORIES TRUE ${DIR}/*.h) + list(APPEND ALL_HEADERS ${HEADERS}) + + # Add all directories that contain header files as private include directories + foreach (H IN LISTS HEADERS) + get_filename_component(D ${H} DIRECTORY) + list(APPEND INCLUDES ${D}) + endforeach () + list(APPEND ALL_INCLUDES ${INCLUDES}) + endforeach () + + if (ARGS_SOURCES_VAR AND ALL_SOURCES) + list(SORT ALL_SOURCES) + list(REMOVE_DUPLICATES ALL_SOURCES) + set(${ARGS_SOURCES_VAR} ${ALL_SOURCES} PARENT_SCOPE) + endif () + + if (ARGS_HEADERS_VAR AND ALL_HEADERS) + list(SORT ALL_HEADERS) + list(REMOVE_DUPLICATES ALL_HEADERS) + set(${ARGS_HEADERS_VAR} ${ALL_HEADERS} PARENT_SCOPE) + endif () + + if (ARGS_INCLUDES_VAR AND ALL_INCLUDES) + list(SORT ALL_INCLUDES) + list(REMOVE_DUPLICATES ALL_INCLUDES) + set(${ARGS_INCLUDES_VAR} ${ALL_INCLUDES} PARENT_SCOPE) + endif () +endfunction() -- cgit v1.2.3