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) find_package(FLEX 2.5.31 REQUIRED)
bison_target(config_parser config_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc) 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) 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) add_flex_bison_dependency(config_lexer config_parser)
mkembedconfig_target(base-type.conf base-type.cpp) mkembedconfig_target(base-type.conf base-type.cpp)

View File

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

View File

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

View File

@ -22,16 +22,24 @@ set_target_properties (
FOLDER Bin 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) function(MKUNITY_TARGET Prefix UnityInputRef)
set(UnityInput ${${UnityInputRef}}) set(UnityInput ${${UnityInputRef}})
set(UnityOutput ${CMAKE_CURRENT_BINARY_DIR}/${Prefix}_unity.cpp) set(UnityOutput ${CMAKE_CURRENT_BINARY_DIR}/${Prefix}_unity.cpp)
set(RealSources "") set(RealSources "")
set(UnitySources "") set(UnitySources "")
foreach(UnitySource ${UnityInput}) foreach(UnitySource ${UnityInput})
if(${UnitySource} MATCHES "\\.cpp\$") get_property(SourceExcluded SOURCE ${UnitySource} PROPERTY EXCLUDE_UNITY_BUILD)
list(APPEND UnitySources ${UnitySource}) if(SourceExcluded MATCHES TRUE OR NOT ${UnitySource} MATCHES "\\.(cpp|cxx|cc)\$")
else()
list(APPEND RealSources ${UnitySource}) list(APPEND RealSources ${UnitySource})
else()
list(APPEND UnitySources ${UnitySource})
endif() endif()
endforeach() endforeach()
add_custom_command( add_custom_command(