diff options
23 files changed, 288 insertions, 78 deletions
diff --git a/Help/command/file.rst b/Help/command/file.rst index 600464e..b0d4792 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -247,7 +247,9 @@ the ``<format>`` and ``UTC`` options. :: - file(GENERATE <options>...) + file(GENERATE OUTPUT output-file + <INPUT input-file|CONTENT content> + [CONDITION expression]) Generate an output file for each build configuration supported by the current :manual:`CMake Generator <cmake-generators(7)>`. Evaluate diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index 672c9b7..3b9b921 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -720,7 +720,9 @@ by the :command:`find_package` command when invoked for ``<package>``. The primary task of a find module is to determine whether a package exists on the system, set the ``<package>_FOUND`` variable to reflect this and provide any variables, macros and imported targets required to -use the package. +use the package. A find module is useful in cases where an upstream +library does not provide a +:ref:`config file package <Config File Packages>`. The traditional approach is to use variables for everything, including libraries and executables: see the `Standard Variable Names`_ section @@ -728,13 +730,9 @@ below. This is what most of the existing find modules provided by CMake do. The more modern approach is to behave as much like -``<package>Config.cmake`` files as possible, by providing imported -targets. As well as matching how ``*Config.cmake`` files work, the -libraries, include directories and compile definitions are all set just -by using the target in a :command:`target_link_libraries` call. The -disadvantage is that ``*Config.cmake`` files of projects that use -imported targets from find modules may require more work to make sure -those imported targets that are in the link interface are available. +:ref:`config file packages <Config File Packages>` files as possible, by +providing :ref:`imported target <Imported targets>`. This has the advantage +of propagating :ref:`Target Usage Requirements` to consumers. In either case (or even when providing both variables and imported targets), find modules should provide backwards compatibility with old @@ -878,7 +876,10 @@ To prevent users being overwhelmed with settings to configure, try to keep as many options as possible out of the cache, leaving at least one option which can be used to disable use of the module, or locate a not-found library (e.g. ``Xxx_ROOT_DIR``). For the same reason, mark -most cache options as advanced. +most cache options as advanced. For packages which provide both debug +and release binaries, it is common to create cache variables with a +``_LIBRARY_<CONFIG>`` suffix, such as ``Foo_LIBRARY_RELEASE`` and +``Foo_LIBRARY_DEBUG``. While these are the standard variable names, you should provide backwards compatibility for any old names that were actually in use. @@ -945,16 +946,6 @@ licence notice block # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -If the module is new to CMake, you may want to provide a warning for -projects that do not require a high enough CMake version. - -.. code-block:: cmake - - if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 3.0.0) - message(AUTHOR_WARNING - "Your project should require at least CMake 3.0.0 to use FindFoo.cmake") - endif() - Now the actual libraries and so on have to be found. The code here will obviously vary from module to module (dealing with that, after all, is the point of find modules), but there tends to be a common pattern for libraries. @@ -1061,6 +1052,47 @@ not any of its dependencies. Instead, those dependencies should also be targets, and CMake should be told that they are dependencies of this target. CMake will then combine all the necessary information automatically. +The type of the :prop_tgt:`IMPORTED` target created in the +:command:`add_library` command can always be specified as ``UNKNOWN`` +type. This simplifies the code in cases where static or shared variants may +be found, and CMake will determine the type by inspecting the files. + +If the library is available with multiple configurations, the +:prop_tgt:`IMPORTED_CONFIGURATIONS` target property should also be +populated: + +.. code-block:: cmake + + if(Foo_FOUND) + if (NOT TARGET Foo::Foo) + add_library(Foo::Foo UNKNOWN IMPORTED) + endif() + if (Foo_LIBRARY_RELEASE) + set_property(TARGET Foo::Foo APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE + ) + set_target_properties(Foo::Foo PROPERTIES + IMPORTED_LOCATION_RELEASE "${Foo_LIBRARY_RELEASE}" + ) + endif() + if (Foo_LIBRARY_DEBUG) + set_property(TARGET Foo::Foo APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG + ) + set_target_properties(Foo::Foo PROPERTIES + IMPORTED_LOCATION_DEBUG "${Foo_LIBRARY_DEBUG}" + ) + endif() + set_target_properties(Foo::Foo PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_Foo_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Foo_INCLUDE_DIR}" + ) + endif() + +The ``RELEASE`` variant should be listed first in the property +so that that variant is chosen if the user uses a configuration which is +not an exact match for any listed ``IMPORTED_CONFIGURATIONS``. + We should also provide some information about the package, such as where to download it. diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst index 083ed7a..8337118 100644 --- a/Help/manual/cmake-modules.7.rst +++ b/Help/manual/cmake-modules.7.rst @@ -209,7 +209,7 @@ All Modules /module/FindWish /module/FindwxWidgets /module/FindwxWindows - /module/FindXerces + /module/FindXercesC /module/FindX11 /module/FindXMLRPC /module/FindZLIB diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst index 0d18fd7..fba1d61 100644 --- a/Help/manual/cmake-packages.7.rst +++ b/Help/manual/cmake-packages.7.rst @@ -76,6 +76,8 @@ By setting the :variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable to ``TRUE``, the ``PackageName`` package will not be searched, and will always be ``NOTFOUND``. +.. _`Config File Packages`: + Config-file Packages -------------------- diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 742fd63..96f39e6 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -113,3 +113,4 @@ All Policies /policy/CMP0053 /policy/CMP0054 /policy/CMP0055 + /policy/CMP0056 diff --git a/Help/module/FindXerces.rst b/Help/module/FindXerces.rst deleted file mode 100644 index 166d8dd..0000000 --- a/Help/module/FindXerces.rst +++ /dev/null @@ -1 +0,0 @@ -.. cmake-module:: ../../Modules/FindXerces.cmake diff --git a/Help/module/FindXercesC.rst b/Help/module/FindXercesC.rst new file mode 100644 index 0000000..4818071 --- /dev/null +++ b/Help/module/FindXercesC.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../Modules/FindXercesC.cmake diff --git a/Help/policy/CMP0056.rst b/Help/policy/CMP0056.rst new file mode 100644 index 0000000..3c75ff4 --- /dev/null +++ b/Help/policy/CMP0056.rst @@ -0,0 +1,32 @@ +CMP0056 +------- + +Honor link flags in :command:`try_compile` source-file signature. + +The :command:`try_compile` command source-file signature generates a +``CMakeLists.txt`` file to build the source file into an executable. +In order to compile the source the same way as it might be compiled +by the calling project, the generated project sets the value of the +:variable:`CMAKE_<LANG>_FLAGS` variable to that in the calling project. +The value of the :variable:`CMAKE_EXE_LINKER_FLAGS` variable may be +needed in some cases too, but CMake 3.1 and lower did not set it in +the generated project. CMake 3.2 and above prefer to set it so that +linker flags are honored as well as compiler flags. This policy +provides compatibility with the pre-3.2 behavior. + +The OLD behavior for this policy is to not set the value of the +:variable:`CMAKE_EXE_LINKER_FLAGS` variable in the generated test +project. The NEW behavior for this policy is to set the value of +the :variable:`CMAKE_EXE_LINKER_FLAGS` variable in the test project +to the same as it is in the calling project. + +If the project code does not set the policy explicitly, users may +set it on the command line by defining the +:variable:`CMAKE_POLICY_DEFAULT_CMP0056 <CMAKE_POLICY_DEFAULT_CMP<NNNN>>` +variable in the cache. + +This policy was introduced in CMake version 3.2. Unlike most policies, +CMake version |release| does *not* warn by default when this policy +is not set and simply uses OLD behavior. See documentation of the +:variable:`CMAKE_POLICY_WARNING_CMP0056 <CMAKE_POLICY_WARNING_CMP<NNNN>>` +variable to control the warning. diff --git a/Help/release/3.1.0.rst b/Help/release/3.1.0.rst index 96717c6..a5b3e8e 100644 --- a/Help/release/3.1.0.rst +++ b/Help/release/3.1.0.rst @@ -245,6 +245,8 @@ Modules * The :module:`FindPkgConfig` module learned to use the ``PKG_CONFIG`` environment variable value as the ``pkg-config`` executable, if set. +* The :module:`FindXercesC` module was introduced. + * The :module:`FindZLIB` module now provides imported targets. * The :module:`GenerateExportHeader` module ``generate_export_header`` diff --git a/Help/release/dev/try_compile-link-flags.rst b/Help/release/dev/try_compile-link-flags.rst new file mode 100644 index 0000000..d995e0b --- /dev/null +++ b/Help/release/dev/try_compile-link-flags.rst @@ -0,0 +1,6 @@ +try_compile-link-flags +---------------------- + +* The :command:`try_compile` command source file signature now honors + link flags (e.g. :variable:`CMAKE_EXE_LINKER_FLAGS`) in the generated + test project. See policy :policy:`CMP0056`. diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst index b563aea..a83c807 100644 --- a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst +++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst @@ -9,6 +9,8 @@ warn by default: policy :policy:`CMP0025`. * ``CMAKE_POLICY_WARNING_CMP0047`` controls the warning for policy :policy:`CMP0047`. +* ``CMAKE_POLICY_WARNING_CMP0056`` controls the warning for + policy :policy:`CMP0056`. This variable should not be set by a project in CMake code. Project developers running CMake may set this variable in their cache to diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index 4bc42dd..344ae47 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -26,7 +26,7 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin") set(CMAKE_FLAGS ) if(DEFINED CMAKE_${lang}_VERBOSE_FLAG) - set(CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}") + set(CMAKE_FLAGS "-DEXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}") endif() if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC") # Avoid adding our own platform standard libraries for compilers diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index ba4ea5b..6f6dcf3 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -188,6 +188,21 @@ foreach(SystemPrefixDir ${CMAKE_SYSTEM_PREFIX_PATH}) endforeach() endforeach() +function (_mpi_check_compiler compiler options cmdvar resvar) + execute_process( + COMMAND "${compiler}" ${options} + OUTPUT_VARIABLE cmdline OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE cmdline ERROR_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE success) + # Intel MPI 5.0.1 will return a zero return code even when the + # argument to the MPI compiler wrapper is unknown. Attempt to + # catch this case. + if("${cmdline}" MATCHES "undefined reference") + set(success 255 ) + endif() + set(${cmdvar} "${cmdline}" PARENT_SCOPE) + set(${resvar} "${success}" PARENT_SCOPE) +endfunction() # # interrogate_mpi_compiler(lang try_libs) @@ -220,12 +235,7 @@ function (interrogate_mpi_compiler lang try_libs) if (MPI_${lang}_COMPILER) # Check whether the -showme:compile option works. This indicates that we have either OpenMPI # or a newer version of LAM-MPI, and implies that -showme:link will also work. - execute_process( - COMMAND ${MPI_${lang}_COMPILER} -showme:compile - OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE MPI_COMPILER_RETURN) - + _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-showme:compile" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN) if (MPI_COMPILER_RETURN EQUAL 0) # If we appear to have -showme:compile, then we should # also have -showme:link. Try it. @@ -257,20 +267,12 @@ function (interrogate_mpi_compiler lang try_libs) # Older versions of LAM-MPI have "-showme". Try to find that. if (NOT MPI_COMPILER_RETURN EQUAL 0) - execute_process( - COMMAND ${MPI_${lang}_COMPILER} -showme - OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE MPI_COMPILER_RETURN) + _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-showme" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN) endif() # MVAPICH uses -compile-info and -link-info. Try them. if (NOT MPI_COMPILER_RETURN EQUAL 0) - execute_process( - COMMAND ${MPI_${lang}_COMPILER} -compile-info - OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE MPI_COMPILER_RETURN) + _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-compile-info" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN) # If we have compile-info, also have link-info. if (MPI_COMPILER_RETURN EQUAL 0) @@ -290,11 +292,7 @@ function (interrogate_mpi_compiler lang try_libs) # MPICH just uses "-show". Try it. if (NOT MPI_COMPILER_RETURN EQUAL 0) - execute_process( - COMMAND ${MPI_${lang}_COMPILER} -show - OUTPUT_VARIABLE MPI_COMPILE_CMDLINE OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_VARIABLE MPI_COMPILE_CMDLINE ERROR_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE MPI_COMPILER_RETURN) + _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-show" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN) endif() if (MPI_COMPILER_RETURN EQUAL 0) diff --git a/Modules/FindXerces.cmake b/Modules/FindXercesC.cmake index 6c6007a..5a8ea9d 100644 --- a/Modules/FindXerces.cmake +++ b/Modules/FindXercesC.cmake @@ -1,21 +1,21 @@ #.rst: -# FindXerces -# ---------- +# FindXercesC +# ----------- # # Find the Apache Xerces-C++ validating XML parser headers and libraries. # # This module reports information about the Xerces installation in # several variables. General variables:: # -# Xerces_FOUND - true if the Xerces headers and libraries were found -# Xerces_VERSION - Xerces release version -# Xerces_INCLUDE_DIRS - the directory containing the Xerces headers -# Xerces_LIBRARIES - Xerces libraries to be linked +# XercesC_FOUND - true if the Xerces headers and libraries were found +# XercesC_VERSION - Xerces release version +# XercesC_INCLUDE_DIRS - the directory containing the Xerces headers +# XercesC_LIBRARIES - Xerces libraries to be linked # # The following cache variables may also be set:: # -# Xerces_INCLUDE_DIR - the directory containing the Xerces headers -# Xerces_LIBRARY - the Xerces library +# XercesC_INCLUDE_DIR - the directory containing the Xerces headers +# XercesC_LIBRARY - the Xerces library # Written by Roger Leigh <rleigh@codelibre.net> @@ -32,54 +32,54 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -function(_Xerces_GET_VERSION version_hdr) +function(_XercesC_GET_VERSION version_hdr) file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*") if(_contents) - string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" Xerces_MAJOR "${_contents}") - string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" Xerces_MINOR "${_contents}") - string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" Xerces_PATCH "${_contents}") + string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XercesC_MAJOR "${_contents}") + string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XercesC_MINOR "${_contents}") + string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XercesC_PATCH "${_contents}") - if(NOT Xerces_MAJOR MATCHES "^[0-9]+$") + if(NOT XercesC_MAJOR MATCHES "^[0-9]+$") message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!") endif() - if(NOT Xerces_MINOR MATCHES "^[0-9]+$") + if(NOT XercesC_MINOR MATCHES "^[0-9]+$") message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!") endif() - if(NOT Xerces_PATCH MATCHES "^[0-9]+$") + if(NOT XercesC_PATCH MATCHES "^[0-9]+$") message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!") endif() - set(Xerces_VERSION "${Xerces_MAJOR}.${Xerces_MINOR}.${Xerces_PATCH}" PARENT_SCOPE) + set(XercesC_VERSION "${XercesC_MAJOR}.${XercesC_MINOR}.${XercesC_PATCH}" PARENT_SCOPE) else() message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information") endif() endfunction() # Find include directory -find_path(Xerces_INCLUDE_DIR +find_path(XercesC_INCLUDE_DIR NAMES "xercesc/util/PlatformUtils.hpp" DOC "Xerces-C++ include directory") -mark_as_advanced(Xerces_INCLUDE_DIR) +mark_as_advanced(XercesC_INCLUDE_DIR) -# Find all Xerces libraries -find_library(Xerces_LIBRARY "xerces-c" +# Find all XercesC libraries +find_library(XercesC_LIBRARY "xerces-c" DOC "Xerces-C++ libraries") -mark_as_advanced(Xerces_LIBRARY) +mark_as_advanced(XercesC_LIBRARY) -if(Xerces_INCLUDE_DIR) - _Xerces_GET_VERSION("${Xerces_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp") +if(XercesC_INCLUDE_DIR) + _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp") endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Xerces - FOUND_VAR Xerces_FOUND - REQUIRED_VARS Xerces_LIBRARY - Xerces_INCLUDE_DIR - Xerces_VERSION - VERSION_VAR Xerces_VERSION - FAIL_MESSAGE "Failed to find Xerces") +FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC + FOUND_VAR XercesC_FOUND + REQUIRED_VARS XercesC_LIBRARY + XercesC_INCLUDE_DIR + XercesC_VERSION + VERSION_VAR XercesC_VERSION + FAIL_MESSAGE "Failed to find XercesC") -if(Xerces_FOUND) - set(Xerces_INCLUDE_DIRS "${Xerces_INCLUDE_DIR}") - set(Xerces_LIBRARIES "${Xerces_LIBRARY}") +if(XercesC_FOUND) + set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}") + set(XercesC_LIBRARIES "${XercesC_LIBRARY}") endif() diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 3048b88..9dd227c 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 1) -set(CMake_VERSION_PATCH 20141205) +set(CMake_VERSION_PATCH 20141208) #set(CMake_VERSION_RC 1) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 512f5cf..0030b84 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -331,6 +331,42 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv) fprintf(fout, "set(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}" " ${COMPILE_DEFINITIONS}\")\n", li->c_str(), li->c_str()); } + switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0056)) + { + case cmPolicies::WARN: + if(this->Makefile->PolicyOptionalWarningEnabled( + "CMAKE_POLICY_WARNING_CMP0056")) + { + cmOStringStream w; + w << (this->Makefile->GetCMakeInstance()->GetPolicies() + ->GetPolicyWarning(cmPolicies::CMP0056)) << "\n" + "For compatibility with older versions of CMake, try_compile " + "is not honoring caller link flags (e.g. CMAKE_EXE_LINKER_FLAGS) " + "in the test project." + ; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + } + case cmPolicies::OLD: + // OLD behavior is to do nothing. + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + this->Makefile->IssueMessage( + cmake::FATAL_ERROR, + this->Makefile->GetCMakeInstance()->GetPolicies() + ->GetRequiredPolicyError(cmPolicies::CMP0056) + ); + case cmPolicies::NEW: + // NEW behavior is to pass linker flags. + { + const char* exeLinkFlags = + this->Makefile->GetDefinition("CMAKE_EXE_LINKER_FLAGS"); + fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS %s)\n", + lg->EscapeForCMake(exeLinkFlags?exeLinkFlags:"").c_str()); + } break; + } + fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}" + " ${EXE_LINKER_FLAGS}\")\n"); fprintf(fout, "include_directories(${INCLUDE_DIRECTORIES})\n"); fprintf(fout, "set(CMAKE_SUPPRESS_REGENERATION 1)\n"); fprintf(fout, "link_directories(${LINK_DIRECTORIES})\n"); diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 64b87b7..1a27a25 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -369,6 +369,11 @@ cmPolicies::cmPolicies() CMP0055, "CMP0055", "Strict checking for break() command.", 3,2,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0056, "CMP0056", + "Honor link flags in try_compile() source-file signature.", + 3,2,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 46ecc22..c393c2f 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -112,6 +112,7 @@ public: CMP0054, ///< Only interpret if() arguments as variables /// or keywords when unquoted. CMP0055, ///< Strict checking for break() command. + CMP0056, ///< Honor link flags in try_compile() source-file signature. /** \brief Always the last entry. * diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 68b6576..f903bdb 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1637,6 +1637,11 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( clOptions.AppendFlag("AdditionalIncludeDirectories", "%(AdditionalIncludeDirectories)"); } + if(clOptions.HasFlag("DisableSpecificWarnings")) + { + clOptions.AppendFlag("DisableSpecificWarnings", + "%(DisableSpecificWarnings)"); + } clOptions.AddDefines(configDefines.c_str()); clOptions.SetConfiguration((*config).c_str()); clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); diff --git a/Tests/RunCMake/try_compile/CMP0056-stderr.txt b/Tests/RunCMake/try_compile/CMP0056-stderr.txt new file mode 100644 index 0000000..5c1f0e4 --- /dev/null +++ b/Tests/RunCMake/try_compile/CMP0056-stderr.txt @@ -0,0 +1,13 @@ +before try_compile with CMP0056 WARN-default +after try_compile with CMP0056 WARN-default +* +CMake Warning \(dev\) at CMP0056.cmake:[0-9]+ \(try_compile\): + Policy CMP0056 is not set: Honor link flags in try_compile\(\) source-file + signature. Run "cmake --help-policy CMP0056" for policy details. Use the + cmake_policy command to set the policy and suppress this warning. + + For compatibility with older versions of CMake, try_compile is not honoring + caller link flags \(e.g. CMAKE_EXE_LINKER_FLAGS\) in the test project. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/try_compile/CMP0056-stdout.txt b/Tests/RunCMake/try_compile/CMP0056-stdout.txt new file mode 100644 index 0000000..89e7c43 --- /dev/null +++ b/Tests/RunCMake/try_compile/CMP0056-stdout.txt @@ -0,0 +1,4 @@ +-- try_compile with CMP0056 WARN-default worked as expected +-- try_compile with CMP0056 WARN-enabled worked as expected +-- try_compile with CMP0056 OLD worked as expected +-- try_compile with CMP0056 NEW worked as expected diff --git a/Tests/RunCMake/try_compile/CMP0056.cmake b/Tests/RunCMake/try_compile/CMP0056.cmake new file mode 100644 index 0000000..e8d3d4a --- /dev/null +++ b/Tests/RunCMake/try_compile/CMP0056.cmake @@ -0,0 +1,67 @@ +enable_language(C) +set(obj "${CMAKE_C_OUTPUT_EXTENSION}") +if(BORLAND) + set(pre -) +endif() +set(CMAKE_EXE_LINKER_FLAGS ${pre}BADFLAG${obj}) + +#----------------------------------------------------------------------------- +message("before try_compile with CMP0056 WARN-default") +try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src.c + OUTPUT_VARIABLE out + ) +string(REPLACE "\n" "\n " out " ${out}") +if(NOT RESULT) + message(FATAL_ERROR "try_compile failed but should have passed:\n${out}") +elseif("x${out}" MATCHES "BADFLAG") + message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}") +else() + message(STATUS "try_compile with CMP0056 WARN-default worked as expected") +endif() +message("after try_compile with CMP0056 WARN-default") + +#----------------------------------------------------------------------------- +set(CMAKE_POLICY_WARNING_CMP0056 ON) +try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src.c + OUTPUT_VARIABLE out + ) +string(REPLACE "\n" "\n " out " ${out}") +if(NOT RESULT) + message(FATAL_ERROR "try_compile failed but should have passed:\n${out}") +elseif("x${out}" MATCHES "BADFLAG") + message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}") +else() + message(STATUS "try_compile with CMP0056 WARN-enabled worked as expected") +endif() + +#----------------------------------------------------------------------------- +cmake_policy(SET CMP0056 OLD) +try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src.c + OUTPUT_VARIABLE out + ) +string(REPLACE "\n" "\n " out " ${out}") +if(NOT RESULT) + message(FATAL_ERROR "try_compile failed but should have passed:\n${out}") +elseif("x${out}" MATCHES "BADFLAG") + message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}") +else() + message(STATUS "try_compile with CMP0056 OLD worked as expected") +endif() + +#----------------------------------------------------------------------------- +cmake_policy(SET CMP0056 NEW) +try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src.c + OUTPUT_VARIABLE out + ) +string(REPLACE "\n" "\n " out " ${out}") +if(RESULT) + message(FATAL_ERROR "try_compile passed but should have failed:\n${out}") +elseif(NOT "x${out}" MATCHES "BADFLAG") + message(FATAL_ERROR "try_compile did not fail with BADFLAG:\n${out}") +else() + message(STATUS "try_compile with CMP0056 NEW worked as expected") +endif() diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index c934458..06096b2 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -15,3 +15,5 @@ run_cmake(BadSources1) run_cmake(BadSources2) run_cmake(NonSourceCopyFile) run_cmake(NonSourceCompileDefinitions) + +run_cmake(CMP0056) |