From f486a9dece2272eef6a1875ada36f0f6963769ed Mon Sep 17 00:00:00 2001 From: Sascha Kratky Date: Sun, 13 Oct 2013 19:23:15 +0200 Subject: [PATCH] cotire 1.5.0 --- CMake/cotire.cmake | 194 ++++++++++++++++++++++++++---------- HISTORY.md | 11 ++ MANUAL.md | 52 +++++++++- Patches/clang-3.3.src.patch | 46 +++++++++ Patches/llvm-3.3.src.patch | 128 ++++++++++++++++++++++++ README.md | 10 +- 6 files changed, 382 insertions(+), 59 deletions(-) create mode 100644 Patches/clang-3.3.src.patch create mode 100644 Patches/llvm-3.3.src.patch diff --git a/CMake/cotire.cmake b/CMake/cotire.cmake index 77ffa5b..c17783b 100644 --- a/CMake/cotire.cmake +++ b/CMake/cotire.cmake @@ -45,7 +45,7 @@ if (NOT CMAKE_SCRIPT_MODE_FILE) endif() set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}") -set (COTIRE_CMAKE_MODULE_VERSION "1.4.3") +set (COTIRE_CMAKE_MODULE_VERSION "1.5.0") include(CMakeParseArguments) include(ProcessorCount) @@ -228,7 +228,7 @@ function (cotire_get_source_file_property_values _valuesVar _property) set (${_valuesVar} ${_values} PARENT_SCOPE) endfunction() -function (cotrie_resolve_config_properites _configurations _propertiesVar) +function (cotire_resolve_config_properites _configurations _propertiesVar) set (_properties "") foreach (_property ${ARGN}) if ("${_property}" MATCHES "") @@ -244,8 +244,8 @@ function (cotrie_resolve_config_properites _configurations _propertiesVar) set (${_propertiesVar} ${_properties} PARENT_SCOPE) endfunction() -function (cotrie_copy_set_properites _configurations _type _source _target) - cotrie_resolve_config_properites("${_configurations}" _properties ${ARGN}) +function (cotire_copy_set_properites _configurations _type _source _target) + cotire_resolve_config_properites("${_configurations}" _properties ${ARGN}) foreach (_property ${_properties}) get_property(_isSet ${_type} ${_source} PROPERTY ${_property} SET) if (_isSet) @@ -362,6 +362,10 @@ function (cotire_get_target_compile_flags _config _language _directory _target _ if (_targetflags) set (_compileFlags "${_compileFlags} ${_targetflags}") endif() + get_target_property(_targetOptions ${_target} COMPILE_OPTIONS) + if (_targetOptions) + set (_compileFlags "${_compileFlags} ${_targetOptions}") + endif() endif() if (UNIX) separate_arguments(_compileFlags UNIX_COMMAND "${_compileFlags}") @@ -447,11 +451,15 @@ function (cotire_get_target_include_directories _config _language _targetSourceD endfunction() macro (cotire_make_C_identifier _identifierVar _str) - # mimic CMake SystemTools::MakeCindentifier behavior - if ("${_str}" MATCHES "^[0-9].+$") - set (_str "_${str}") + if (CMAKE_VERSION VERSION_LESS "2.8.12") + # mimic CMake SystemTools::MakeCindentifier behavior + if ("${_str}" MATCHES "^[0-9].+$") + set (_str "_${str}") + endif() + string (REGEX REPLACE "[^a-zA-Z0-9]" "_" ${_identifierVar} "${_str}") + else() + string (MAKE_C_IDENTIFIER "${_identifierVar}" "${_str}") endif() - string (REGEX REPLACE "[^a-zA-Z0-9]" "_" ${_identifierVar} "${_str}") endmacro() function (cotire_get_target_export_symbol _target _exportSymbolVar) @@ -1141,7 +1149,7 @@ function (cotire_generate_prefix_header _prefixFile) endif() string (REPLACE ";" "\n" _unparsedLines "${_unparsedLines}") endif() - file (WRITE "${_unparsedLinesFile}" "${_unparsedLines}\n") + file (WRITE "${_unparsedLinesFile}" "${_unparsedLines}") endfunction() function (cotire_add_makedep_flags _language _compilerID _compilerVersion _flagsVar) @@ -1378,10 +1386,10 @@ function (cotire_add_prefix_pch_inclusion_flags _language _compilerID _compilerV # -Qunused-arguments don't emit warning for unused driver arguments if (_flags) # append to list - list (APPEND _flags "-include" "${_prefixFile}" "-Qunused-arguments") + list (APPEND _flags "-Qunused-arguments" "-include" "${_prefixFile}") else() # return as a flag string - set (_flags "-include \"${_prefixFile}\" -Qunused-arguments") + set (_flags "-Qunused-arguments -include \"${_prefixFile}\"") endif() elseif (_compilerID MATCHES "Intel") if (WIN32) @@ -1983,7 +1991,7 @@ function (cotire_setup_target_pch_usage _languages _targetSourceDir _target _who cotire_add_prefix_pch_inclusion_flags( "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${COTIRE_${_language}_COMPILER_VERSION}" "${_prefixFile}" "${_pchFile}" _flags) - set_property (TARGET ${_target} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ") + set_property(TARGET ${_target} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ") endif() endif() endif() @@ -2099,6 +2107,10 @@ function (cotire_init_cotire_target_properties _target) if (NOT _isSet) set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS "") endif() + get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT SET) + if (NOT _isSet) + set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT "") + endif() get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES SET) if (NOT _isSet) if (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES) @@ -2113,7 +2125,14 @@ function (cotire_make_target_message _target _languages _disableMsg _targetMsgVa get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER) get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD) string (REPLACE ";" " " _languagesStr "${_languages}") - string (REPLACE ";" ", " _excludedStr "${ARGN}") + math (EXPR _numberOfExcludedFiles "${ARGC} - 4") + if (_numberOfExcludedFiles EQUAL 0) + set (_excludedStr "") + elseif (COTIRE_VERBOSE OR _numberOfExcludedFiles LESS 4) + string (REPLACE ";" ", " _excludedStr "excluding ${ARGN}") + else() + set (_excludedStr "excluding ${_numberOfExcludedFiles} files") + endif() set (_targetMsg "") if (NOT _languages) set (_targetMsg "Target ${_target} cannot be cotired.") @@ -2126,8 +2145,8 @@ function (cotire_make_target_message _target _languages _disableMsg _targetMsgVa set (_targetMsg "${_targetMsg} ${_disableMsg}") endif() elseif (NOT _targetUsePCH) - if (_allExcludedSourceFiles) - set (_targetMsg "${_languagesStr} target ${_target} cotired excluding files ${_excludedStr} without precompiled header.") + if (_excludedStr) + set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header ${_excludedStr}.") else() set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header.") endif() @@ -2135,14 +2154,14 @@ function (cotire_make_target_message _target _languages _disableMsg _targetMsgVa set (_targetMsg "${_targetMsg} ${_disableMsg}") endif() elseif (NOT _targetAddSCU) - if (_allExcludedSourceFiles) - set (_targetMsg "${_languagesStr} target ${_target} cotired excluding files ${_excludedStr} without unity build.") + if (_excludedStr) + set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build ${_excludedStr}.") else() set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build.") endif() else() - if (_allExcludedSourceFiles) - set (_targetMsg "${_languagesStr} target ${_target} cotired excluding files ${_excludedStr}.") + if (_excludedStr) + set (_targetMsg "${_languagesStr} target ${_target} cotired ${_excludedStr}.") else() set (_targetMsg "${_languagesStr} target ${_target} cotired.") endif() @@ -2165,7 +2184,7 @@ function (cotire_choose_target_languages _targetSourceDir _target _targetLanguag get_target_property(_prefixHeader ${_target} COTIRE_${_language}_PREFIX_HEADER) get_target_property(_unityBuildFile ${_target} COTIRE_${_language}_UNITY_SOURCE) if (_prefixHeader OR _unityBuildFile) - message (WARNING "Target ${_target} has already been cotired.") + message (STATUS "Target ${_target} has already been cotired.") set (${_targetLanguagesVar} "" PARENT_SCOPE) return() endif() @@ -2377,15 +2396,7 @@ function (cotire_setup_unity_build_target _languages _configurations _targetSour # determine unity target sub type get_target_property(_targetType ${_target} TYPE) if ("${_targetType}" STREQUAL "EXECUTABLE") - get_target_property(_isWin32 ${_target} WIN32_EXECUTABLE) - get_target_property(_isMacOSX_Bundle ${_target} MACOSX_BUNDLE) - if (_isWin32) - set (_unityTargetSubType WIN32) - elseif (_isMacOSX_Bundle) - set (_unityTargetSubType MACOSX_BUNDLE) - else() - set (_unityTargetSubType "") - endif() + set (_unityTargetSubType "") elseif (_targetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY") set (_unityTargetSubType "${CMAKE_MATCH_1}") else() @@ -2445,8 +2456,8 @@ function (cotire_setup_unity_build_target _languages _configurations _targetSour if (IS_ABSOLUTE "${COTIRE_UNITY_OUTPUT_DIRECTORY}") set (_outputDir "${COTIRE_UNITY_OUTPUT_DIRECTORY}") else() - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties}) - cotrie_resolve_config_properites("${_configurations}" _properties ${_outputDirProperties}) + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties}) + cotire_resolve_config_properites("${_configurations}" _properties ${_outputDirProperties}) foreach (_property ${_properties}) get_property(_outputDir TARGET ${_target} PROPERTY ${_property}) if (_outputDir) @@ -2466,24 +2477,31 @@ function (cotire_setup_unity_build_target _languages _configurations _targetSour RUNTIME_OUTPUT_DIRECTORY "${_outputDir}") endif() else() - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties}) + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties}) endif() # copy output name - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_ LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_ OUTPUT_NAME OUTPUT_NAME_ RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_ PREFIX _POSTFIX SUFFIX) # copy compile stuff - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} COMPILE_DEFINITIONS COMPILE_DEFINITIONS_ - COMPILE_FLAGS Fortran_FORMAT + COMPILE_FLAGS COMPILE_OPTIONS + Fortran_FORMAT Fortran_MODULE_DIRECTORY INCLUDE_DIRECTORIES INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_ - POSITION_INDEPENDENT_CODE) + POSITION_INDEPENDENT_CODE + C_VISIBILITY_PRESET CXX_VISIBILITY_PRESET VISIBILITY_INLINES_HIDDEN) + # copy interface stuff + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_STRING + INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES + INTERFACE_LINK_LIBRARIES INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) # copy link stuff - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} BUILD_WITH_INSTALL_RPATH INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH SKIP_BUILD_RPATH LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED LINK_FLAGS LINK_FLAGS_ @@ -2493,24 +2511,22 @@ function (cotire_setup_unity_build_target _languages _configurations _targetSour STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_ NO_SONAME SOVERSION VERSION) # copy Qt stuff - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} AUTOMOC AUTOMOC_MOC_OPTIONS) # copy cmake stuff - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} IMPLICIT_DEPENDS_INCLUDE_TRANSFORM RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK) - # copy platform stuff - if (APPLE) - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} - BUNDLE BUNDLE_EXTENSION FRAMEWORK INSTALL_NAME_DIR MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST - OSX_ARCHITECTURES OSX_ARCHITECTURES_ PRIVATE_HEADER PUBLIC_HEADER RESOURCE) - elseif (WIN32) - cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} - GNUtoMS - PDB_NAME PDB_NAME_ PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_ - VS_DOTNET_REFERENCES VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_KEYWORD - VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER - VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES) - endif() + # copy Apple platform specific stuff + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + BUNDLE BUNDLE_EXTENSION FRAMEWORK INSTALL_NAME_DIR MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST + MACOSX_RPATH OSX_ARCHITECTURES OSX_ARCHITECTURES_ PRIVATE_HEADER PUBLIC_HEADER RESOURCE) + # copy Windows platform specific stuff + cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} + GNUtoMS + PDB_NAME PDB_NAME_ PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_ + VS_DOTNET_REFERENCES VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE VS_KEYWORD + VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER + VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES WIN32_EXECUTABLE) # use output name from original target get_target_property(_targetOutputName ${_unityTargetName} OUTPUT_NAME) if (NOT _targetOutputName) @@ -2558,6 +2574,14 @@ function (cotire_target _target) message (WARNING "Imported target ${_target} cannot be cotired.") return() endif() + # resolve alias + get_target_property(_aliasName ${_target} ALIASED_TARGET) + if (_aliasName) + if (COTIRE_DEBUG) + message (STATUS "${_target} is an alias. Applying cotire to aliased target ${_aliasName} instead.") + endif() + set (_target ${_aliasName}) + endif() # check if target needs to be cotired for build type # when using configuration types, the test is performed at build time cotire_init_cotire_target_properties(${_target}) @@ -2606,7 +2630,46 @@ function (cotire_target _target) if (_targetAddCleanTarget) cotire_setup_clean_target(${_target}) endif() -endfunction() +endfunction(cotire_target) + +function(cotire_target_link_libraries _target) + get_target_property(_unityTargetName ${_target} COTIRE_UNITY_TARGET_NAME) + if (TARGET "${_unityTargetName}") + get_target_property(_linkLibrariesStrategy ${_target} COTIRE_UNITY_LINK_LIBRARIES_INIT) + if (COTIRE_DEBUG) + message (STATUS "unity target ${_unityTargetName} link strategy: ${_linkLibrariesStrategy}") + endif() + if ("${_linkLibrariesStrategy}" MATCHES "^(COPY|COPY_UNITY)$") + if (CMAKE_VERSION VERSION_LESS "2.8.11") + message (WARNING "Unity target link strategy ${_linkLibrariesStrategy} requires CMake 2.8.11 or later. Defaulting to NONE for ${_target}.") + return() + endif() + get_target_property(_linkLibraries ${_target} LINK_LIBRARIES) + if (_linkLibraries) + if (COTIRE_DEBUG) + message (STATUS "target ${_target} link libraries: ${_linkLibraries}") + endif() + set (_unityTargetLibraries "") + foreach (_library ${_linkLibraries}) + if (TARGET "${_library}" AND "${_linkLibrariesStrategy}" MATCHES "COPY_UNITY") + get_target_property(_libraryUnityTargetName ${_library} COTIRE_UNITY_TARGET_NAME) + if (TARGET "${_libraryUnityTargetName}") + list (APPEND _unityTargetLibraries "${_libraryUnityTargetName}") + else() + list (APPEND _unityTargetLibraries "${_library}") + endif() + else() + list (APPEND _unityTargetLibraries "${_library}") + endif() + endforeach() + set_property(TARGET ${_unityTargetName} APPEND PROPERTY LINK_LIBRARIES ${_unityTargetLibraries}) + if (COTIRE_DEBUG) + message (STATUS "set unity target ${_unityTargetName} link libraries: ${_unityTargetLibraries}") + endif() + endif() + endif() + endif() +endfunction(cotire_target_link_libraries) function (cotire_cleanup _binaryDir _cotireIntermediateDirName _targetName) if (_targetName) @@ -2688,7 +2751,12 @@ function (cotire) cotire_target(${_target} LANGUAGES ${_option_LANGUAGES} CONFIGURATIONS ${_option_CONFIGURATIONS} SOURCE_DIR "${_option_SOURCE_DIR}" BINARY_DIR "${_option_BINARY_DIR}") else() - message (WARNING "${_target} is not a target") + message (WARNING "${_target} is not a target.") + endif() + endforeach() + foreach (_target ${_targets}) + if (TARGET ${_target}) + cotire_target_link_libraries(${_target}) endif() endforeach() endfunction() @@ -3034,6 +3102,13 @@ else() "See target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES." ) + define_property( + DIRECTORY PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT" + BRIEF_DOCS "Define strategy for setting up the unity target's link libraries." + FULL_DOCS + "See target property COTIRE_UNITY_LINK_LIBRARIES_INIT." + ) + # define cotire target properties define_property( @@ -3143,6 +3218,17 @@ else() "Defaults to empty." ) + define_property( + TARGET PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT" INHERITED + BRIEF_DOCS "Define strategy for setting up unity target's link libraries." + FULL_DOCS + "If this property is empty, the generated unity target's link libraries have to be set up manually." + "If this property is set to COPY, the unity target's link libraries will be copied from this target." + "If this property is set to COPY_UNITY, the unity target's link libraries will be copied from this target with considering existing unity targets." + "Inherited from directory." + "Defaults to empty." + ) + define_property( TARGET PROPERTY "COTIRE__UNITY_SOURCE" BRIEF_DOCS "Read-only property. The generated unity source file(s)." diff --git a/HISTORY.md b/HISTORY.md index b20f192..7762958 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,14 @@ +## 1.5.0 (2013-10-13) + +* CMake 2.8.12 compatibility fixes. +* Upon generation of a unity target, cotire can now be configured to automatically copy all the + linked libraries and targets from the original target. See the section on the new target property + `COTIRE_UNITY_LINK_LIBRARIES_INIT` in the cotire manual. +* fixed bug with copying target properties to generated unity target. +* cotire manual updates. +* add new examples to the `Patches` directory. +* fix typos. + ## 1.4.3 (2013-09-28) * fixed bug with generation of unity source file when `COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES` is diff --git a/MANUAL.md b/MANUAL.md index cb2b874..2ff95e1 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -99,9 +99,11 @@ files generated by cotire. The `example_unity` target produces the same output `example` target, but does so by performing a unity build. The `all_pch` and `all_unity` serve as pool targets for all cotired project targets. -The `example_unity` target inherits all build settings from the original target `example` except -for linked libraries and target dependencies. To get a linkable unity target, the required -libraries have to be added manually to the unity target with `target_link_libraries`. +By default, the `example_unity` target inherits all build settings from the original target +`example` except for linked libraries and target dependencies. To get a linkable unity target, +the required libraries have to be added manually to the unity target with `target_link_libraries`. +When using CMake 2.8.11 or later, it is possible to have the unity target inherit linked libraries +as well (see the section on the target property `COTIRE_UNITY_LINK_LIBRARIES_INIT` below). cotire generated files ---------------------- @@ -219,6 +221,17 @@ usable for the target and cannot be re-used for a different CMake target. cotire advanced usage --------------------- +### applying cotire to multiple targets at the same time + +The `cotire` function can be applied to multiple targets added in the same source directory in one +call: + + add_library(libA STATIC ...) + add_library(libB SHARED ...) + add_executable(example ...) + ... + cotire(example libA libB) + ### mixed-language targets Cotire is able to speed up the build process of mixed language targets, consisting of both C and @@ -418,7 +431,7 @@ the generated unity source file. ### configuring the generation of the unity source -By default cotire adds all target source file to the generated unity source. In most cases a +By default cotire adds all target source files to the generated unity source. In most cases a unity build will not work out of the box, because unity builds [break][EoUB] the use of some C and C++ language features. Unity build problems can be tackled in the following way: @@ -543,6 +556,37 @@ The `cotire` function can be applied to an object library target in a familiar f Because object library targets do not support `PRE_BUILD` actions, precompiled header usage cannot be enabled for them for Xcode projects generated with CMake. Unity builds work as expected, though. +### automatically setting up linked libraries in the unity target + +CMake 2.8.11 introduced a new target property `LINK_LIBRARIES`, which specifies the list of +libraries or targets which will be used for linking. Cotire can be configured to make use of this +property to automatically set up the linked libraries in the generated unity target. + +To have cotire copy the the list of linked libraries and targets from the original target to the +unity target, set the target property `COTIRE_UNITY_LINK_LIBRARIES_INIT` to `COPY`. + + cmake_minimum_required(VERSION 2.8.11) + ... + set_target_properties(example PROPERTIES COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY") + ... + cotire(example) + +If the target property `COTIRE_UNITY_LINK_LIBRARIES_INIT` is set to `COPY_UNITY` instead, cotire +will copy all linked libraries and targets from the original target, but instead of copying a +target verbatim, it will prefer the target's corresponding unity target, provided one exists. + +For reasons of backwards compatibility, the `COTIRE_UNITY_LINK_LIBRARIES_INIT` property is left +empty by default. The required libraries have to be added manually to the unity target with +subsequent `target_link_libraries` calls. + +The property `COTIRE_UNITY_LINK_LIBRARIES_INIT` can also be set on directories. A target inherits +the property value from its enclosing directory. To make all targets in the project use the +`COPY_UNITY` strategy, the directory property can be set in the outermost `CMakeList.txt` file: + + include(cotire) + ... + set_property(DIRECTORY PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY_UNITY") + cotire usage restrictions ------------------------- diff --git a/Patches/clang-3.3.src.patch b/Patches/clang-3.3.src.patch new file mode 100644 index 0000000..bbfc83d --- /dev/null +++ b/Patches/clang-3.3.src.patch @@ -0,0 +1,46 @@ +diff -rupN cfe-3.3.src/CMakeLists.txt cfe-3.3.src.cotire/CMakeLists.txt +--- cfe-3.3.src/CMakeLists.txt 2013-04-22 16:51:21.000000000 +0200 ++++ cfe-3.3.src.cotire/CMakeLists.txt 2013-10-13 12:02:05.000000000 +0200 +@@ -2,7 +2,7 @@ + # standalone project, using LLVM as an external library: + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) +- cmake_minimum_required(VERSION 2.8) ++ cmake_minimum_required(VERSION 2.8.11) + + set(CLANG_PATH_TO_LLVM_SOURCE "" CACHE PATH + "Path to LLVM source code. Not necessary if using an installed LLVM.") +@@ -36,6 +36,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR + include(TableGen) + include("${CLANG_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake") + include(HandleLLVMOptions) ++ include(cotire) ++ set_property(DIRECTORY PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY_UNITY") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") + +@@ -234,6 +236,12 @@ macro(add_clang_library name) + ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} + RUNTIME DESTINATION bin) + set_target_properties(${name} PROPERTIES FOLDER "Clang libraries") ++ if (COMMAND cotire) ++ if (NOT "${name}" MATCHES "libclang") ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++ endif() ++ endif() + endmacro(add_clang_library) + + macro(add_clang_executable name) +diff -rupN cfe-3.3.src/tools/libclang/CMakeLists.txt cfe-3.3.src.cotire/tools/libclang/CMakeLists.txt +--- cfe-3.3.src/tools/libclang/CMakeLists.txt 2013-03-29 22:51:40.000000000 +0100 ++++ cfe-3.3.src.cotire/tools/libclang/CMakeLists.txt 2013-10-13 11:32:48.000000000 +0200 +@@ -114,3 +114,8 @@ if( NOT BUILD_SHARED_LIBS AND NOT WIN32 + PROPERTIES + OUTPUT_NAME "clang") + endif() ++ ++if (COMMAND cotire) ++ cotire(libclang) ++ cotire(${LIBCLANG_STATIC_TARGET_NAME}) ++endif() diff --git a/Patches/llvm-3.3.src.patch b/Patches/llvm-3.3.src.patch new file mode 100644 index 0000000..f1109f4 --- /dev/null +++ b/Patches/llvm-3.3.src.patch @@ -0,0 +1,128 @@ +diff -rupN llvm-3.3.src/CMakeLists.txt llvm-3.3.src.cotire/CMakeLists.txt +--- llvm-3.3.src/CMakeLists.txt 2013-05-06 18:23:07.000000000 +0200 ++++ llvm-3.3.src.cotire/CMakeLists.txt 2013-10-13 10:05:20.000000000 +0200 +@@ -1,7 +1,7 @@ + # See docs/CMake.html for instructions about how to build LLVM with CMake. + + project(LLVM) +-cmake_minimum_required(VERSION 2.8) ++cmake_minimum_required(VERSION 2.8.11) + + # Add path for custom modules + set(CMAKE_MODULE_PATH +@@ -21,6 +21,8 @@ if ( LLVM_USE_FOLDERS ) + endif() + + include(VersionFromVCS) ++include(cotire) ++set_property(DIRECTORY PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY_UNITY") + + option(LLVM_APPEND_VC_REV + "Append the version control system revision id to LLVM version" OFF) +@@ -187,7 +189,7 @@ option(LLVM_USE_OPROFILE + # If enabled, verify we are on a platform that supports oprofile. + if( LLVM_USE_OPROFILE ) + if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) +- message(FATAL_ERROR "OProfile support is available on Linux only.") ++ message(FATAL_ERROR "OProfile support is available on Linux only.") + endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) + endif( LLVM_USE_OPROFILE ) + +diff -rupN llvm-3.3.src/cmake/modules/AddLLVM.cmake llvm-3.3.src.cotire/cmake/modules/AddLLVM.cmake +--- llvm-3.3.src/cmake/modules/AddLLVM.cmake 2013-04-21 11:04:59.000000000 +0200 ++++ llvm-3.3.src.cotire/cmake/modules/AddLLVM.cmake 2013-10-13 10:43:04.000000000 +0200 +@@ -34,6 +34,10 @@ macro(add_llvm_library name) + # property has been set to an empty value. + get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) + target_link_libraries(${name} ${lib_deps}) ++if (COMMAND cotire) ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++endif() + endmacro(add_llvm_library name) + + macro(add_llvm_loadable_module name) +@@ -69,6 +73,10 @@ ${name} ignored.") + LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} + ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) + endif() ++if (COMMAND cotire) ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++endif() + endif() + + set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") +@@ -101,6 +109,10 @@ macro(add_llvm_tool name) + install(TARGETS ${name} RUNTIME DESTINATION bin) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Tools") ++if (COMMAND cotire) ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++endif() + endmacro(add_llvm_tool name) + + +@@ -114,12 +126,20 @@ macro(add_llvm_example name) + install(TARGETS ${name} RUNTIME DESTINATION examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") ++if (COMMAND cotire) ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++endif() + endmacro(add_llvm_example name) + + + macro(add_llvm_utility name) + add_llvm_executable(${name} ${ARGN}) + set_target_properties(${name} PROPERTIES FOLDER "Utils") ++if (COMMAND cotire) ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++endif() + endmacro(add_llvm_utility name) + + +@@ -198,6 +218,10 @@ function(add_unittest test_suite test_na + set(target_compile_flags "${target_compile_flags} -Wno-variadic-macros") + endif () + set_property(TARGET ${test_name} PROPERTY COMPILE_FLAGS "${target_compile_flags}") ++if (COMMAND cotire) ++ set_target_properties(${name} PROPERTIES COTIRE_UNITY_SOURCE_POST_UNDEFS "DEBUG_TYPE") ++ cotire(${name}) ++endif() + endfunction() + + # This function provides an automatic way to 'configure'-like generate a file +diff -rupN llvm-3.3.src/include/llvm/Transforms/Utils/BlackList.h llvm-3.3.src.cotire/include/llvm/Transforms/Utils/BlackList.h +--- llvm-3.3.src/include/llvm/Transforms/Utils/BlackList.h 2013-04-11 15:20:00.000000000 +0200 ++++ llvm-3.3.src.cotire/include/llvm/Transforms/Utils/BlackList.h 2013-10-13 11:52:41.000000000 +0200 +@@ -30,6 +30,9 @@ + //===----------------------------------------------------------------------===// + // + ++#ifndef LLVM_TRANSFORMS_UTILS_BLACKLIST_H ++#define LLVM_TRANSFORMS_UTILS_BLACKLIST_H ++ + #include "llvm/ADT/StringMap.h" + + namespace llvm { +@@ -57,3 +60,5 @@ class BlackList { + }; + + } // namespace llvm ++ ++#endif +diff -rupN llvm-3.3.src/lib/Support/CMakeLists.txt llvm-3.3.src.cotire/lib/Support/CMakeLists.txt +--- llvm-3.3.src/lib/Support/CMakeLists.txt 2013-04-23 10:28:39.000000000 +0200 ++++ llvm-3.3.src.cotire/lib/Support/CMakeLists.txt 2013-10-13 10:25:45.000000000 +0200 +@@ -1,3 +1,7 @@ ++if (COMMAND cotire) ++ set_source_files_properties (IsInf.cpp IsNAN.cpp PROPERTIES COTIRE_EXCLUDED TRUE) ++endif() ++ + add_llvm_library(LLVMSupport + APFloat.cpp + APInt.cpp diff --git a/README.md b/README.md index d155ca2..2a15ad7 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,14 @@ target, add another `target_link_libraries` call: cotire(MyExecutable) target_link_libraries(MyExecutable_unity ${MyExecutableLibraries}) +If CMake version 2.8.11 or later is used, it is possible to also inherit linked libraries from +the original target by setting the property `COTIRE_UNITY_LINK_LIBRARIES_INIT`: + + set_target_properties(MyExecutable PROPERTIES COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY") + cotire(MyExecutable) + +See the [cotire manual][manual] for more information. + For Makefile based generators you can then invoke a unity build that produces the same output as the original target, but does so much faster by entering: @@ -135,4 +143,4 @@ known issues [EoUB]:http://leewinder.co.uk/blog/?p=394 [jom]:http://qt-project.org/wiki/jom [intel]:http://software.intel.com/en-us/c-compilers -[XGE]:http://www.incredibuild.com \ No newline at end of file +[XGE]:http://www.incredibuild.com