Implement support for excluding files from unity builds

refs #7034
This commit is contained in:
Gunnar Beutner 2014-09-01 09:19:21 +02:00
parent 2a65c7821c
commit 46f26024dc
4 changed files with 18 additions and 3 deletions

View File

@ -19,7 +19,11 @@ find_package(BISON 2.3.0 REQUIRED)
find_package(FLEX 2.5.31 REQUIRED)
bison_target(config_parser config_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc)
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY EXCLUDE_UNITY_BUILD TRUE)
flex_target(config_lexer config_lexer.ll ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc)
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc PROPERTY EXCLUDE_UNITY_BUILD TRUE)
add_flex_bison_dependency(config_lexer config_parser)
mkembedconfig_target(base-type.conf base-type.cpp)

View File

@ -25,6 +25,8 @@ set(base_test_SOURCES
icinga-perfdata.cpp test.cpp
)
set_property(SOURCE test.cpp PROPERTY EXCLUDE_UNITY_BUILD TRUE)
if(ICINGA2_UNITY_BUILD)
mkunity_target(test base_test_SOURCES)
endif()

View File

@ -41,4 +41,5 @@ macro(MKCLASS_TARGET ClassInput ClassOutput)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS mkclass ${ClassInput}
)
set_property(SOURCE ${ClassOutput} PROPERTY EXCLUDE_UNITY_BUILD)
endmacro()

View File

@ -22,16 +22,24 @@ set_target_properties (
FOLDER Bin
)
define_property(
SOURCE
PROPERTY EXCLUDE_UNITY_BUILD
BRIEF_DOCS "Whether to exclude the source file from unity builds"
FULL_DOCS "Specified whether a source file should be excluded from unity builds and should be built separately"
)
function(MKUNITY_TARGET Prefix UnityInputRef)
set(UnityInput ${${UnityInputRef}})
set(UnityOutput ${CMAKE_CURRENT_BINARY_DIR}/${Prefix}_unity.cpp)
set(RealSources "")
set(UnitySources "")
foreach(UnitySource ${UnityInput})
if(${UnitySource} MATCHES "\\.cpp\$")
list(APPEND UnitySources ${UnitySource})
else()
get_property(SourceExcluded SOURCE ${UnitySource} PROPERTY EXCLUDE_UNITY_BUILD)
if(SourceExcluded MATCHES TRUE OR NOT ${UnitySource} MATCHES "\\.(cpp|cxx|cc)\$")
list(APPEND RealSources ${UnitySource})
else()
list(APPEND UnitySources ${UnitySource})
endif()
endforeach()
add_custom_command(