diff options
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 19 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 8 | ||||
-rw-r--r-- | Tests/PrecompiledHeader/CMakeLists.txt | 48 |
3 files changed, 43 insertions, 32 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 2417b4a..b2b3fa1 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -517,6 +517,25 @@ cmMakefileTargetGenerator relativeObj.c_str(), depends, commands, false); + // Check for extra outputs created by the compilation. + if(const char* extra_outputs_str = + source.GetProperty("OBJECT_OUTPUTS")) + { + std::vector<std::string> extra_outputs; + cmSystemTools::ExpandListArgument(extra_outputs_str, extra_outputs); + for(std::vector<std::string>::const_iterator eoi = extra_outputs.begin(); + eoi != extra_outputs.end(); ++eoi) + { + // Register this as an extra output for the object file rule. + // This will cause the object file to be rebuilt if the extra + // output is missing. + this->GenerateExtraOutput(eoi->c_str(), relativeObj.c_str(), false); + + // Register this as an extra file to clean. + this->CleanFiles.push_back(eoi->c_str()); + } + } + bool lang_is_c_or_cxx = ((strcmp(lang, "C") == 0) || (strcmp(lang, "CXX") == 0)); bool do_preprocess_rules = lang_is_c_or_cxx && diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index c9d0c48..1468869 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -402,6 +402,14 @@ void cmSourceFile::DefineProperties(cmake *cm) "building this source file."); cm->DefineProperty + ("OBJECT_OUTPUTS", cmProperty::SOURCE_FILE, + "Additional outputs for a Makefile rule.", + "Additional outputs created by compilation of this source file. " + "If any of these outputs is missing the object will be recompiled. " + "This is supported only on Makefile generators and will be ignored " + "on other generators."); + + cm->DefineProperty ("SYMBOLIC", cmProperty::SOURCE_FILE, "Is this just a name for a rule.", "If SYMBOLIC (boolean) is set to true the build system will be " diff --git a/Tests/PrecompiledHeader/CMakeLists.txt b/Tests/PrecompiledHeader/CMakeLists.txt index 7b7f26c..8b76eb4 100644 --- a/Tests/PrecompiledHeader/CMakeLists.txt +++ b/Tests/PrecompiledHeader/CMakeLists.txt @@ -13,14 +13,13 @@ ELSE(CMAKE_CONFIGURATION_TYPES) ENDIF(CMAKE_CONFIGURATION_TYPES) FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH) -# The VS6 IDE does not support renaming .pch files so we cannot use a -# separate target. +# The VS6 IDE does not support renaming .pch files with /Fp. IF("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6") - SET(PCH_USE_TARGET 0) SET(PCH_USE_INCLUDE_DIR 1) + SET(PCH_FILE) ELSE("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6") - SET(PCH_USE_TARGET 1) SET(PCH_USE_INCLUDE_DIR 0) + SET(PCH_FILE "\"/Fp${PCH_DIR}/foo_precompiled.pch\"") ENDIF("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6") # Choose between an explicit include path and using /I during @@ -34,37 +33,22 @@ ENDIF(PCH_USE_INCLUDE_DIR) # Create a target that will use a precompiled header. SET(foo_SRCS foo1.c foo2.c) -IF(PCH_USE_TARGET) - ADD_EXECUTABLE(foo ${foo_SRCS}) - - # Create a target to precompile the header for the executable. - ADD_LIBRARY(foo_precompile foo_precompile.c include/foo_precompiled.h) - SET_TARGET_PROPERTIES(foo_precompile PROPERTIES OUTPUT_NAME foo) - ADD_DEPENDENCIES(foo foo_precompile) - - SET(PCH_TARGETS foo foo_precompile) - SET(PCH_FILE "\"/Fp${PCH_DIR}/foo_precompiled.pch\"") -ELSE(PCH_USE_TARGET) - # Put the precompiled header source directly in the target. - ADD_EXECUTABLE(foo foo_precompile.c ${foo_SRCS}) - SET(PCH_TARGETS foo) -ENDIF(PCH_USE_TARGET) - -# Add the PCH to the list of files to clean. It is created as a -# side-effect so CMake does not know about it. -SET_DIRECTORY_PROPERTIES(PROPERTIES - ADDITIONAL_MAKE_CLEAN_FILES ${PCH_DIR}/foo_precompiled.pch - ) +ADD_EXECUTABLE(foo foo_precompile.c ${foo_SRCS}) -# Setup flags on the two targets to create and use the precompiled header. -SET_TARGET_PROPERTIES(${PCH_TARGETS} PROPERTIES COMPILE_FLAGS - "/Yufoo_precompiled.h /FIfoo_precompiled.h ${PCH_FILE}") -SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES COMPILE_FLAGS - "/Ycfoo_precompiled.h ${PCH_INCLUDE_DIR}") +# Setup flags on the target to create and use the precompiled header. +SET_TARGET_PROPERTIES(foo PROPERTIES + COMPILE_FLAGS "/Yufoo_precompiled.h /FIfoo_precompiled.h ${PCH_FILE}") +SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES + COMPILE_FLAGS "/Ycfoo_precompiled.h ${PCH_INCLUDE_DIR}") -# Make sure the object files rebuild when their precompiled header has changed. -# The VS IDE takes care of this automatically. +# Setup dependencies for precompiled header creation and use. The VS +# IDE takes care of this automatically. IF("${CMAKE_GENERATOR}" MATCHES "Makefile") + # This source file creates the precompiled header as a side-effect. + SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES + OBJECT_OUTPUTS "${PCH_DIR}/foo_precompiled.pch") + + # These source files use the precompiled header. SET_SOURCE_FILES_PROPERTIES(${foo_SRCS} PROPERTIES OBJECT_DEPENDS "${PCH_DIR}/foo_precompiled.pch") ENDIF("${CMAKE_GENERATOR}" MATCHES "Makefile") |