diff options
66 files changed, 625 insertions, 163 deletions
diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index 7fcdc72..fa4f60a 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -2199,6 +2199,7 @@ syn keyword cmakeGeneratorExpressions contained \ COMPILE_DEFINITIONS \ COMPILE_FEATURES \ COMPILE_LANGUAGE + \ COMPILE_LANG_AND_ID \ COMPILING_CUDA \ COMPILING_CXX \ CONFIG diff --git a/Help/command/file.rst b/Help/command/file.rst index 465e567..0664e7c 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -311,6 +311,7 @@ Create the given directories and their parents as needed. [FILE_PERMISSIONS <permissions>...] [DIRECTORY_PERMISSIONS <permissions>...] [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS] + [FOLLOW_SYMLINK_CHAIN] [FILES_MATCHING] [[PATTERN <pattern> | REGEX <regex>] [EXCLUDE] [PERMISSIONS <permissions>...]] [...]) @@ -324,6 +325,32 @@ at the destination with the same timestamp. Copying preserves input permissions unless explicit permissions or ``NO_SOURCE_PERMISSIONS`` are given (default is ``USE_SOURCE_PERMISSIONS``). +If ``FOLLOW_SYMLINK_CHAIN`` is specified, ``COPY`` will recursively resolve +the symlinks at the paths given until a real file is found, and install +a corresponding symlink in the destination for each symlink encountered. For +each symlink that is installed, the resolution is stripped of the directory, +leaving only the filename, meaning that the new symlink points to a file in +the same directory as the symlink. This feature is useful on some Unix systems, +where libraries are installed as a chain of symlinks with version numbers, with +less specific versions pointing to more specific versions. +``FOLLOW_SYMLINK_CHAIN`` will install all of these symlinks and the library +itself into the destination directory. For example, if you have the following +directory structure: + +* ``/opt/foo/lib/libfoo.so.1.2.3`` +* ``/opt/foo/lib/libfoo.so.1.2 -> libfoo.so.1.2.3`` +* ``/opt/foo/lib/libfoo.so.1 -> libfoo.so.1.2`` +* ``/opt/foo/lib/libfoo.so -> libfoo.so.1`` + +and you do: + +.. code-block:: cmake + + file(COPY /opt/foo/lib/libfoo.so DESTINATION lib FOLLOW_SYMLINK_CHAIN) + +This will install all of the symlinks and ``libfoo.so.1.2.3`` itself into +``lib``. + See the :command:`install(DIRECTORY)` command for documentation of permissions, ``FILES_MATCHING``, ``PATTERN``, ``REGEX``, and ``EXCLUDE`` options. Copying directories preserves the structure diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index ce62893..f2e6597 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -111,22 +111,22 @@ Variable Queries this expression when it is evaluated on a property on an :prop_tgt:`IMPORTED` target. ``$<PLATFORM_ID:platform_id>`` - ``1`` if the CMake-id of the platform matches ``platform_id`` + ``1`` if the CMake's platform id matches ``platform_id`` otherwise ``0``. See also the :variable:`CMAKE_SYSTEM_NAME` variable. ``$<C_COMPILER_ID:compiler_id>`` - ``1`` if the CMake-id of the C compiler matches ``compiler_id``, + ``1`` if the CMake's compiler id of the C compiler matches ``compiler_id``, otherwise ``0``. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<CXX_COMPILER_ID:compiler_id>`` - ``1`` if the CMake-id of the CXX compiler matches ``compiler_id``, + ``1`` if the CMake's compiler id of the CXX compiler matches ``compiler_id``, otherwise ``0``. ``$<CUDA_COMPILER_ID:compiler_id>`` - ``1`` if the CMake-id of the CUDA compiler matches ``compiler_id``, + ``1`` if the CMake's compiler id of the CUDA compiler matches ``compiler_id``, otherwise ``0``. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<Fortran_COMPILER_ID:compiler_id>`` - ``1`` if the CMake-id of the Fortran compiler matches ``compiler_id``, + ``1`` if the CMake's compiler id of the Fortran compiler matches ``compiler_id``, otherwise ``0``. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<C_COMPILER_VERSION:version>`` @@ -158,6 +158,42 @@ Variable Queries .. _`Boolean COMPILE_LANGUAGE Generator Expression`: +``$<COMPILE_LANG_AND_ID:language,compiler_id>`` + ``1`` when the language used for compilation unit matches ``language`` and + the CMake's compiler id of the language compiler matches ``compiler_id``, + otherwise ``0``. This expression is a short form for the combination of + ``$<COMPILE_LANGUAGE:language>`` and ``$<LANG_COMPILER_ID:compiler_id>``. + This expression may be used to specify compile options, + compile definitions, and include directories for source files of a + particular language and compiler combination in a target. For example: + + .. code-block:: cmake + + add_executable(myapp main.cpp foo.c bar.cpp zot.cu) + target_compile_definitions(myapp + PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,Clang>:COMPILING_CXX_WITH_CLANG> + $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL> + $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG> + ) + + This specifies the use of different compile definitions based on both + the compiler id and compilation language. This example will have a + ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX + compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler. + Likewise when the C compiler is Clang it will only see the ``COMPILING_C_WITH_CLANG`` + definition. + + Without the ``COMPILE_LANG_AND_ID`` generator expression the same logic + would be expressed as: + + .. code-block:: cmake + + target_compile_definitions(myapp + PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Clang>>:COMPILING_CXX_WITH_CLANG> + $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL> + $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG> + ) + ``$<COMPILE_LANGUAGE:language>`` ``1`` when the language used for compilation unit matches ``language``, otherwise ``0``. This expression may be used to specify compile options, @@ -348,19 +384,19 @@ Variable Queries ``$<CONFIGURATION>`` Configuration name. Deprecated since CMake 3.0. Use ``CONFIG`` instead. ``$<PLATFORM_ID>`` - The CMake-id of the platform. + The current system's CMake platform id. See also the :variable:`CMAKE_SYSTEM_NAME` variable. ``$<C_COMPILER_ID>`` - The CMake-id of the C compiler used. + The CMake's compiler id of the C compiler used. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<CXX_COMPILER_ID>`` - The CMake-id of the CXX compiler used. + The CMake's compiler id of the CXX compiler used. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<CUDA_COMPILER_ID>`` - The CMake-id of the CUDA compiler used. + The CMake's compiler id of the CUDA compiler used. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<Fortran_COMPILER_ID>`` - The CMake-id of the Fortran compiler used. + The CMake's compiler id of the Fortran compiler used. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<C_COMPILER_VERSION>`` The version of the C compiler used. diff --git a/Help/manual/cmake-language.7.rst b/Help/manual/cmake-language.7.rst index 5e5cfff..4ca8e3a 100644 --- a/Help/manual/cmake-language.7.rst +++ b/Help/manual/cmake-language.7.rst @@ -430,7 +430,7 @@ comments: a `Bracket Comment`_ and a `Line Comment`_. Bracket Comment ^^^^^^^^^^^^^^^ -A ``#`` immediately followed by a `Bracket Argument`_ forms a +A ``#`` immediately followed by a :token:`bracket_open` forms a *bracket comment* consisting of the entire bracket enclosure: .. raw:: latex @@ -461,7 +461,7 @@ For example: Line Comment ^^^^^^^^^^^^ -A ``#`` not immediately followed by a `Bracket Argument`_ forms a +A ``#`` not immediately followed by a :token:`bracket_open` forms a *line comment* that runs until the end of the line: .. raw:: latex @@ -469,7 +469,7 @@ A ``#`` not immediately followed by a `Bracket Argument`_ forms a \begin{small} .. productionlist:: - line_comment: '#' <any text not starting in a `bracket_argument` + line_comment: '#' <any text not starting in a `bracket_open` : and not containing a `newline`> .. raw:: latex diff --git a/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst b/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst index 8db6ede..909b14c 100644 --- a/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst +++ b/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst @@ -5,7 +5,7 @@ Directory where :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` generate files for the target. The directory is created on demand and automatically added to the -:prop_dir:`ADDITIONAL_MAKE_CLEAN_FILES`. +:prop_tgt:`ADDITIONAL_CLEAN_FILES` target property. When unset or empty the directory ``<dir>/<target-name>_autogen`` is used where ``<dir>`` is :variable:`CMAKE_CURRENT_BINARY_DIR` and ``<target-name>`` diff --git a/Help/release/dev/file-install-follow-symlink-chain.rst b/Help/release/dev/file-install-follow-symlink-chain.rst new file mode 100644 index 0000000..8d22512 --- /dev/null +++ b/Help/release/dev/file-install-follow-symlink-chain.rst @@ -0,0 +1,6 @@ +file-install-follow-symlink-chain +--------------------------------- + +* The :command:`file(INSTALL)` command learned a new argument, + ``FOLLOW_SYMLINK_CHAIN``, which can be used to recursively resolve and + install symlinks. diff --git a/Help/release/dev/genex-COMPILE_LANG_AND_ID.rst b/Help/release/dev/genex-COMPILE_LANG_AND_ID.rst new file mode 100644 index 0000000..27e0ebd --- /dev/null +++ b/Help/release/dev/genex-COMPILE_LANG_AND_ID.rst @@ -0,0 +1,7 @@ +genex-COMPILE_LANG_AND_ID +-------------------------- + +* A new ``COMPILE_LANG_AND_ID`` generator expression was introduced to + allow specification of compile options for target files based on the + :variable:`CMAKE_<LANG>_COMPILER_ID` and :prop_sf:`LANGUAGE` and of + each source file. diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake index 8d55ac7..65e5d1c 100644 --- a/Modules/FindBLAS.cmake +++ b/Modules/FindBLAS.cmake @@ -403,20 +403,19 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") endif () if (DEFINED ENV{MKLROOT}) - set(_BLAS_MKLROOT_LIB_DIR "$ENV{MKLROOT}") + if (BLA_VENDOR STREQUAL "Intel10_32") + set(_BLAS_MKLROOT_LIB_DIR "$ENV{MKLROOT}/lib/ia32") + elseif (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$") + set(_BLAS_MKLROOT_LIB_DIR "$ENV{MKLROOT}/lib/intel64") + endif () endif () if (_BLAS_MKLROOT_LIB_DIR) - if( SIZEOF_INTEGER EQUAL 8 ) - set( _BLAS_MKL_PATH_PREFIX "intel64" ) - else() - set( _BLAS_MKL_PATH_PREFIX "ia32" ) - endif() if (WIN32) - string(APPEND _BLAS_MKLROOT_LIB_DIR "/lib/${_BLAS_MKL_PATH_PREFIX}_win") + string(APPEND _BLAS_MKLROOT_LIB_DIR "_win") elseif (APPLE) - string(APPEND _BLAS_MKLROOT_LIB_DIR "/lib/${_BLAS_MKL_PATH_PREFIX}_mac") + string(APPEND _BLAS_MKLROOT_LIB_DIR "_mac") else () - string(APPEND _BLAS_MKLROOT_LIB_DIR "/lib/${_BLAS_MKL_PATH_PREFIX}_lin") + string(APPEND _BLAS_MKLROOT_LIB_DIR "_lin") endif () endif () diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake index 32b4aa2..ebd0b24 100644 --- a/Modules/FindDoxygen.cmake +++ b/Modules/FindDoxygen.cmake @@ -974,7 +974,7 @@ doxygen_add_docs() for target ${targetName}") "${DOXYGEN_OUTPUT_DIRECTORY}/${DOXYGEN_HTML_OUTPUT}") endif() set_property(DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES "${_args_clean_html_dir}") + ADDITIONAL_CLEAN_FILES "${_args_clean_html_dir}") endif() # Build up a list of files we can identify from the inputs so we can list diff --git a/Modules/UseEcos.cmake b/Modules/UseEcos.cmake index 1e82f16..60324b1 100644 --- a/Modules/UseEcos.cmake +++ b/Modules/UseEcos.cmake @@ -214,10 +214,10 @@ macro(ECOS_ADD_EXECUTABLE _exe_NAME ) ) #add the created files to the clean-files - set_directory_properties( - PROPERTIES - ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin;${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec;${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst;" - ) + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES + "${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin" + "${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec" + "${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst") add_custom_target(ecosclean ${CMAKE_COMMAND} -DECOS_DIR=${CMAKE_CURRENT_BINARY_DIR}/ecos/ -P ${ECOS_CMAKE_MODULE_DIR}/ecos_clean.cmake ) add_custom_target(normalclean ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index b0315b2..0798488 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -735,7 +735,8 @@ function(add_jar _TARGET_NAME) # this INTERFACE library depends on jar generation add_dependencies (${_GENERATE_NATIVE_HEADERS_TARGET} ${_TARGET_NAME}) - set_property (DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES + "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") endif() endfunction() diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index c136b05..78522da 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -708,9 +708,9 @@ function(SWIG_ADD_LIBRARY name) endif() endforeach() set_property (DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps}) + ADDITIONAL_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps}) if (UseSWIG_MODULE_VERSION VERSION_GREATER 1) - set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outputdir}") + set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${outputdir}") endif() add_library(${target_name} diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index dc4f5fd..63d5f3d 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 14) -set(CMake_VERSION_PATCH 20190517) +set(CMake_VERSION_PATCH 20190520) #set(CMake_VERSION_RC 1) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 2f62db1..f12ef0b 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -122,8 +122,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, } } - const char* sourceDirectory = argv[2].c_str(); - const char* projectName = nullptr; + std::string sourceDirectory = argv[2]; + std::string projectName; std::string targetName; std::vector<std::string> cmakeFlags(1, "CMAKE_FLAGS"); // fake argv[0] std::vector<std::string> compileDefs; @@ -309,7 +309,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, doing = DoingNone; } else if (i == 3) { this->SrcFileSignature = false; - projectName = argv[i].c_str(); + projectName = argv[i]; } else if (i == 4 && !this->SrcFileSignature) { targetName = argv[i]; } else { @@ -480,7 +480,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, // we need to create a directory and CMakeLists file etc... // first create the directories - sourceDirectory = this->BinaryDirectory.c_str(); + sourceDirectory = this->BinaryDirectory; // now create a CMakeLists.txt file in that directory FILE* fout = cmsys::SystemTools::Fopen(outFileName, "w"); @@ -950,7 +950,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, << " '" << copyFile << "'\n"; /* clang-format on */ if (!this->FindErrorMessage.empty()) { - emsg << this->FindErrorMessage.c_str(); + emsg << this->FindErrorMessage; } if (copyFileError.empty()) { this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str()); diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 93ff8f4..c6e44e3 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -280,8 +280,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( xml.StartElement("Build"); - this->AppendTarget(xml, "all", nullptr, make.c_str(), lgs[0], - compiler.c_str(), makeArgs); + this->AppendTarget(xml, "all", nullptr, make, lgs[0], compiler, makeArgs); // add all executable and library targets and some of the GLOBAL // and UTILITY targets @@ -294,8 +293,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // Only add the global targets from CMAKE_BINARY_DIR, // not from the subdirs if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) { - this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, targetName, nullptr, make, lg, compiler, + makeArgs); } } break; case cmStateEnums::UTILITY: @@ -310,8 +309,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( break; } - this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, targetName, nullptr, make, lg, compiler, + makeArgs); break; case cmStateEnums::EXECUTABLE: case cmStateEnums::STATIC_LIBRARY: @@ -319,12 +318,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::OBJECT_LIBRARY: { cmGeneratorTarget* gt = target; - this->AppendTarget(xml, targetName, gt, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, targetName, gt, make, lg, compiler, + makeArgs); std::string fastTarget = targetName; fastTarget += "/fast"; - this->AppendTarget(xml, fastTarget, gt, make.c_str(), lg, - compiler.c_str(), makeArgs); + this->AppendTarget(xml, fastTarget, gt, make, lg, compiler, + makeArgs); } break; default: break; @@ -378,7 +377,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( std::string const& fullPath = s->GetFullPath(); // Check file position relative to project root dir. - const std::string& relative = + const std::string relative = cmSystemTools::RelativePath(lg->GetSourceDirectory(), fullPath); // Do not add this file if it has ".." in relative path and // if CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable is on. @@ -454,7 +453,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( } // Add CMakeLists.txt - tree.BuildUnit(xml, std::string(mf->GetHomeDirectory()) + "/"); + tree.BuildUnit(xml, mf->GetHomeDirectory() + "/"); xml.EndElement(); // Project xml.EndElement(); // CodeBlocks_project_file @@ -489,8 +488,8 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile( // Generate the xml code for one target. void cmExtraCodeBlocksGenerator::AppendTarget( cmXMLWriter& xml, const std::string& targetName, cmGeneratorTarget* target, - const char* make, const cmLocalGenerator* lg, const char* compiler, - const std::string& makeFlags) + const std::string& make, const cmLocalGenerator* lg, + const std::string& compiler, const std::string& makeFlags) { cmMakefile const* makefile = lg->GetMakefile(); std::string makefileName = lg->GetCurrentBinaryDirectory(); @@ -613,25 +612,23 @@ void cmExtraCodeBlocksGenerator::AppendTarget( xml.StartElement("Build"); xml.Attribute( "command", - this->BuildMakeCommand(make, makefileName.c_str(), targetName, makeFlags)); + this->BuildMakeCommand(make, makefileName, targetName, makeFlags)); xml.EndElement(); xml.StartElement("CompileFile"); - xml.Attribute("command", - this->BuildMakeCommand(make, makefileName.c_str(), "\"$file\"", - makeFlags)); + xml.Attribute( + "command", + this->BuildMakeCommand(make, makefileName, "\"$file\"", makeFlags)); xml.EndElement(); xml.StartElement("Clean"); xml.Attribute( - "command", - this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)); + "command", this->BuildMakeCommand(make, makefileName, "clean", makeFlags)); xml.EndElement(); xml.StartElement("DistClean"); xml.Attribute( - "command", - this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)); + "command", this->BuildMakeCommand(make, makefileName, "clean", makeFlags)); xml.EndElement(); xml.EndElement(); // MakeCommands @@ -725,8 +722,8 @@ int cmExtraCodeBlocksGenerator::GetCBTargetType(cmGeneratorTarget* target) // Create the command line for building the given target using the selected // make std::string cmExtraCodeBlocksGenerator::BuildMakeCommand( - const std::string& make, const char* makefile, const std::string& target, - const std::string& makeFlags) + const std::string& make, const std::string& makefile, + const std::string& target, const std::string& makeFlags) { std::string command = make; if (!makeFlags.empty()) { @@ -747,7 +744,7 @@ std::string cmExtraCodeBlocksGenerator::BuildMakeCommand( } else if (generator == "MinGW Makefiles") { // no escaping of spaces in this case, see // https://gitlab.kitware.com/cmake/cmake/issues/10014 - std::string makefileName = makefile; + std::string const& makefileName = makefile; command += " -f \""; command += makefileName; command += "\" "; diff --git a/Source/cmExtraCodeBlocksGenerator.h b/Source/cmExtraCodeBlocksGenerator.h index be3af25..173e284 100644 --- a/Source/cmExtraCodeBlocksGenerator.h +++ b/Source/cmExtraCodeBlocksGenerator.h @@ -42,12 +42,13 @@ private: std::string GetCBCompilerId(const cmMakefile* mf); int GetCBTargetType(cmGeneratorTarget* target); - std::string BuildMakeCommand(const std::string& make, const char* makefile, + std::string BuildMakeCommand(const std::string& make, + const std::string& makefile, const std::string& target, const std::string& makeFlags); void AppendTarget(cmXMLWriter& xml, const std::string& targetName, - cmGeneratorTarget* target, const char* make, - const cmLocalGenerator* lg, const char* compiler, + cmGeneratorTarget* target, const std::string& make, + const cmLocalGenerator* lg, const std::string& compiler, const std::string& makeFlags); }; diff --git a/Source/cmFileCopier.cxx b/Source/cmFileCopier.cxx index 8913e6d..972cd6e 100644 --- a/Source/cmFileCopier.cxx +++ b/Source/cmFileCopier.cxx @@ -31,6 +31,7 @@ cmFileCopier::cmFileCopier(cmFileCommand* command, const char* name) , UseGivenPermissionsFile(false) , UseGivenPermissionsDir(false) , UseSourcePermissions(true) + , FollowSymlinkChain(false) , Doing(DoingNone) { } @@ -249,6 +250,9 @@ bool cmFileCopier::CheckKeyword(std::string const& arg) this->Doing = DoingPattern; } else if (arg == "REGEX") { this->Doing = DoingRegex; + } else if (arg == "FOLLOW_SYMLINK_CHAIN") { + this->FollowSymlinkChain = true; + this->Doing = DoingNone; } else if (arg == "EXCLUDE") { // Add this property to the current match rule. if (this->CurrentMatchRule) { @@ -464,16 +468,69 @@ bool cmFileCopier::Install(const std::string& fromFile, if (cmSystemTools::SameFile(fromFile, toFile)) { return true; } - if (cmSystemTools::FileIsSymlink(fromFile)) { - return this->InstallSymlink(fromFile, toFile); + + std::string newFromFile = fromFile; + std::string newToFile = toFile; + + if (this->FollowSymlinkChain && + !this->InstallSymlinkChain(newFromFile, newToFile)) { + return false; } - if (cmSystemTools::FileIsDirectory(fromFile)) { - return this->InstallDirectory(fromFile, toFile, match_properties); + + if (cmSystemTools::FileIsSymlink(newFromFile)) { + return this->InstallSymlink(newFromFile, newToFile); } - if (cmSystemTools::FileExists(fromFile)) { - return this->InstallFile(fromFile, toFile, match_properties); + if (cmSystemTools::FileIsDirectory(newFromFile)) { + return this->InstallDirectory(newFromFile, newToFile, match_properties); } - return this->ReportMissing(fromFile); + if (cmSystemTools::FileExists(newFromFile)) { + return this->InstallFile(newFromFile, newToFile, match_properties); + } + return this->ReportMissing(newFromFile); +} + +bool cmFileCopier::InstallSymlinkChain(std::string& fromFile, + std::string& toFile) +{ + std::string newFromFile; + std::string toFilePath = cmSystemTools::GetFilenamePath(toFile); + while (cmSystemTools::ReadSymlink(fromFile, newFromFile)) { + if (!cmSystemTools::FileIsFullPath(newFromFile)) { + std::string fromFilePath = cmSystemTools::GetFilenamePath(fromFile); + newFromFile = fromFilePath + "/" + newFromFile; + } + + std::string symlinkTarget = cmSystemTools::GetFilenameName(newFromFile); + + bool copy = true; + if (!this->Always) { + std::string oldSymlinkTarget; + if (cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget)) { + if (symlinkTarget == oldSymlinkTarget) { + copy = false; + } + } + } + + this->ReportCopy(toFile, TypeLink, copy); + + if (copy) { + cmSystemTools::RemoveFile(toFile); + cmSystemTools::MakeDirectory(toFilePath); + + if (!cmSystemTools::CreateSymlink(symlinkTarget, toFile)) { + std::ostringstream e; + e << this->Name << " cannot create symlink \"" << toFile << "\"."; + this->FileCommand->SetError(e.str()); + return false; + } + } + + fromFile = newFromFile; + toFile = toFilePath + "/" + symlinkTarget; + } + + return true; } bool cmFileCopier::InstallSymlink(const std::string& fromFile, diff --git a/Source/cmFileCopier.h b/Source/cmFileCopier.h index 003b8f6..a79a60b 100644 --- a/Source/cmFileCopier.h +++ b/Source/cmFileCopier.h @@ -64,6 +64,7 @@ protected: // Translate an argument to a permissions bit. bool CheckPermissions(std::string const& arg, mode_t& permissions); + bool InstallSymlinkChain(std::string& fromFile, std::string& toFile); bool InstallSymlink(const std::string& fromFile, const std::string& toFile); bool InstallFile(const std::string& fromFile, const std::string& toFile, MatchProperties match_properties); @@ -86,6 +87,7 @@ protected: bool UseGivenPermissionsFile; bool UseGivenPermissionsDir; bool UseSourcePermissions; + bool FollowSymlinkChain; std::string Destination; std::string FilesFromDir; std::vector<std::string> Files; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 8c6fb34..709355a 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -981,6 +981,51 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode } } languageNode; +static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode +{ + CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default) + + int NumExpectedParameters() const override { return 2; } + + std::string Evaluate( + const std::vector<std::string>& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override + { + if (!context->HeadTarget || context->Language.empty()) { + // reportError(context, content->GetOriginalExpression(), ""); + reportError( + context, content->GetOriginalExpression(), + "$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets " + "to specify include directories, compile definitions, and compile " + "options. It may not be used with the add_custom_command, " + "add_custom_target, or file(GENERATE) commands."); + return std::string(); + } + cmGlobalGenerator* gg = context->LG->GetGlobalGenerator(); + std::string genName = gg->GetName(); + if (genName.find("Makefiles") == std::string::npos && + genName.find("Ninja") == std::string::npos && + genName.find("Visual Studio") == std::string::npos && + genName.find("Xcode") == std::string::npos && + genName.find("Watcom WMake") == std::string::npos) { + reportError( + context, content->GetOriginalExpression(), + "$<COMPILE_LANG_AND_ID:lang,id> not supported for this generator."); + return std::string(); + } + + const std::string& lang = context->Language; + if (lang == parameters.front()) { + std::vector<std::string> idParameter = { parameters[1] }; + return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage( + idParameter, context, content, dagChecker, lang); + } + return "0"; + } +} languageAndIdNode; + #define TRANSITIVE_PROPERTY_NAME(PROPERTY) , "INTERFACE_" #PROPERTY static const char* targetPropertyTransitiveWhitelist[] = { @@ -2285,6 +2330,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( { "INSTALL_PREFIX", &installPrefixNode }, { "JOIN", &joinNode }, { "LINK_ONLY", &linkOnlyNode }, + { "COMPILE_LANG_AND_ID", &languageAndIdNode }, { "COMPILE_LANGUAGE", &languageNode }, { "SHELL_PATH", &shellPathNode } }; diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index 606febe..7b58389 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -48,7 +48,7 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( const std::string& makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::vector<std::string> locations; - std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str()); + std::string makeloc = cmSystemTools::GetProgramPath(makeProgram); locations.push_back(this->FindMinGW(makeloc)); locations.push_back(makeloc); locations.push_back("/mingw/bin"); @@ -77,8 +77,8 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( if (!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile() && !(1 == l.size() && l[0] == "NONE")) { cmSystemTools::Error( - "CMAKE_AR was not found, please set to archive program. ", - mf->GetDefinition("CMAKE_AR")); + "CMAKE_AR was not found, please set to archive program. " + + mf->GetSafeDefinition("CMAKE_AR")); } } diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 00276f8..5ddaaa3 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -574,7 +574,7 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures() static std::string const k_DYNDEP_ = ".dyndep-"; std::string::size_type pos = this->NinjaVersion.find(k_DYNDEP_); if (pos != std::string::npos) { - const char* fv = this->NinjaVersion.c_str() + pos + k_DYNDEP_.size(); + const char* fv = &this->NinjaVersion[pos + k_DYNDEP_.size()]; cmSystemTools::StringToULong(fv, &this->NinjaSupportsDyndeps); } } @@ -1254,7 +1254,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) for (std::string const& i : unknownExplicitDepends) { // verify the file is in the build directory std::string const absDepPath = - cmSystemTools::CollapseFullPath(i, rootBuildDirectory.c_str()); + cmSystemTools::CollapseFullPath(i, rootBuildDirectory); bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath, rootBuildDirectory); if (inBuildDir) { diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 65d816e..1ea3673 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -169,7 +169,7 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand( { if (this->CommandDatabase == nullptr) { std::string commandDatabaseName = - std::string(this->GetCMakeInstance()->GetHomeOutputDirectory()) + + this->GetCMakeInstance()->GetHomeOutputDirectory() + "/compile_commands.json"; this->CommandDatabase = new cmGeneratedFileStream(commandDatabaseName); *this->CommandDatabase << "[" << std::endl; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index c31dbf4..8764ee4 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -45,7 +45,6 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( cmake* cm, std::string const& platformInGeneratorName) : cmGlobalVisualStudioGenerator(cm, platformInGeneratorName) { - this->IntelProjectVersion = 0; this->DevEnvCommandInitialized = false; this->MasmEnabled = false; this->NasmEnabled = false; @@ -54,21 +53,20 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator() { - free(this->IntelProjectVersion); } // Package GUID of Intel Visual Fortran plugin to VS IDE #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}" -const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion() +const std::string& cmGlobalVisualStudio7Generator::GetIntelProjectVersion() { - if (!this->IntelProjectVersion) { + if (this->IntelProjectVersion.empty()) { // Compute the version of the Intel plugin to the VS IDE. // If the key does not exist then use a default guess. std::string intelVersion; std::string vskey = this->GetRegistryBase(); vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion"; - cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion, + cmSystemTools::ReadRegistryValue(vskey, intelVersion, cmSystemTools::KeyWOW64_32); unsigned int intelVersionNumber = ~0u; sscanf(intelVersion.c_str(), "%u", &intelVersionNumber); @@ -81,7 +79,7 @@ const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion() } else { // Version <= 9: use ProductVersion from registry. } - this->IntelProjectVersion = strdup(intelVersion.c_str()); + this->IntelProjectVersion = intelVersion; } return this->IntelProjectVersion; } @@ -237,7 +235,7 @@ cmGlobalVisualStudio7Generator::GenerateBuildCommand( GeneratedMakeCommand makeCommand; makeCommand.RequiresOutputForward = requiresOutputForward; makeCommand.Add(makeProgramSelected); - makeCommand.Add(std::string(projectName) + ".sln"); + makeCommand.Add(projectName + ".sln"); makeCommand.Add((clean ? "/clean" : "/build")); makeCommand.Add((config.empty() ? "Debug" : config)); makeCommand.Add("/project"); @@ -270,7 +268,7 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s, cmMakefile* mf) { mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION", - this->GetIntelProjectVersion()); + this->GetIntelProjectVersion().c_str()); return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf); } @@ -615,7 +613,7 @@ std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name) { std::string const& guidStoreName = name + "_GUID_CMAKE"; if (const char* storedGUID = - this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) { + this->CMakeInstance->GetCacheDefinition(guidStoreName)) { return std::string(storedGUID); } // Compute a GUID that is deterministic but unique to the build tree. diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 1e76383..f004afb 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -86,7 +86,7 @@ public: return false; } - const char* GetIntelProjectVersion(); + const std::string& GetIntelProjectVersion(); bool FindMakeProgram(cmMakefile* mf) override; @@ -163,7 +163,7 @@ protected: bool NasmEnabled; private: - char* IntelProjectVersion; + std::string IntelProjectVersion; std::string DevEnvCommand; bool DevEnvCommandInitialized; std::string GetVSMakeProgram() override { return this->GetDevEnvCommand(); } diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 21abdf7..0da9986 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -188,8 +188,8 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() commandLine.push_back("--check-stamp-list"); commandLine.push_back(stampList.c_str()); commandLine.push_back("--vs-solution-file"); - std::string const sln = std::string(lg->GetBinaryDirectory()) + "/" + - lg->GetProjectName() + ".sln"; + std::string const sln = + lg->GetBinaryDirectory() + "/" + lg->GetProjectName() + ".sln"; commandLine.push_back(sln); cmCustomCommandLines commandLines; commandLines.push_back(commandLine); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index d5a59c7..f2eb0ce 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -202,7 +202,7 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( } } } - if (!versionFile.empty() && cmSystemTools::FileExists(versionFile.c_str())) { + if (!versionFile.empty() && cmSystemTools::FileExists(versionFile)) { parser.ParseFile(versionFile.c_str()); } else if (cmSystemTools::FileExists( "/Applications/Xcode.app/Contents/version.plist")) { @@ -479,7 +479,7 @@ void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root) this->CurrentXCodeHackMakefile = root->GetCurrentBinaryDirectory(); this->CurrentXCodeHackMakefile += "/CMakeScripts"; - cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str()); + cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile); this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make"; } @@ -600,7 +600,7 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( this->CurrentReRunCMakeMakefile = root->GetCurrentBinaryDirectory(); this->CurrentReRunCMakeMakefile += "/CMakeScripts"; - cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str()); + cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile); this->CurrentReRunCMakeMakefile += "/ReRunCMake.make"; cmGeneratedFileStream makefileStream(this->CurrentReRunCMakeMakefile); makefileStream.SetCopyIfDifferent(true); @@ -1026,8 +1026,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath( std::string path = this->RelativeToSource(fullpath); std::string name = cmSystemTools::GetFilenameName(path); const char* sourceTree = - (cmSystemTools::FileIsFullPath(path.c_str()) ? "<absolute>" - : "SOURCE_ROOT"); + cmSystemTools::FileIsFullPath(path) ? "<absolute>" : "SOURCE_ROOT"; fileRef->AddAttribute("name", this->CreateString(name)); fileRef->AddAttribute("path", this->CreateString(path)); fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree)); @@ -1588,7 +1587,7 @@ std::string cmGlobalXCodeGenerator::ExtractFlagRegex(const char* exp, std::string::size_type offset = 0; - while (regex.find(flags.c_str() + offset)) { + while (regex.find(&flags[offset])) { const std::string::size_type startPos = offset + regex.start(matchIndex); const std::string::size_type endPos = offset + regex.end(matchIndex); const std::string::size_type size = endPos - startPos; @@ -1641,7 +1640,7 @@ void cmGlobalXCodeGenerator::AddCommandsToBuildPhase( { std::string dir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory(); dir += "/CMakeScripts"; - cmSystemTools::MakeDirectory(dir.c_str()); + cmSystemTools::MakeDirectory(dir); std::string makefile = dir; makefile += "/"; makefile += target->GetName(); @@ -1700,7 +1699,7 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } else { std::ostringstream str; str << "_buildpart_" << count++; - tname[&ccg.GetCC()] = std::string(target->GetName()) + str.str(); + tname[&ccg.GetCC()] = target->GetName() + str.str(); makefileStream << "\\\n\t" << tname[&ccg.GetCC()]; } } @@ -1824,8 +1823,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::string llang = gtgt->GetLinkerLanguage(configName); if (binary && llang.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - gtgt->GetName().c_str()); + "CMake can not determine linker language for target: " + + gtgt->GetName()); return; } std::string const& langForPreprocessor = llang; @@ -3014,10 +3013,11 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO")); cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (auto& CurrentConfigurationType : this->CurrentConfigurationTypes) { + for (const std::string& CurrentConfigurationType : + this->CurrentConfigurationTypes) { cmXCodeObject* buildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle); - const char* name = CurrentConfigurationType.c_str(); + const std::string& name = CurrentConfigurationType; buildStyle->AddAttribute("name", this->CreateString(name)); buildStyle->SetComment(name); cmXCodeObject* sgroup = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); @@ -3263,8 +3263,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( { cmGeneratedFileStream makefileStream(this->CurrentXCodeHackMakefile); if (!makefileStream) { - cmSystemTools::Error("Could not create", - this->CurrentXCodeHackMakefile.c_str()); + cmSystemTools::Error("Could not create " + this->CurrentXCodeHackMakefile); return; } makefileStream.SetCopyIfDifferent(true); @@ -3401,7 +3400,7 @@ void cmGlobalXCodeGenerator::OutputXCodeProject( xcodeDir += "/"; xcodeDir += root->GetProjectName(); xcodeDir += ".xcodeproj"; - cmSystemTools::MakeDirectory(xcodeDir.c_str()); + cmSystemTools::MakeDirectory(xcodeDir); std::string xcodeProjFile = xcodeDir + "/project.pbxproj"; cmGeneratedFileStream fout(xcodeProjFile); fout.SetCopyIfDifferent(true); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 7f7ee71..9b651a4 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -70,7 +70,7 @@ void cmLocalNinjaGenerator::Generate() this->WritePools(this->GetRulesFileStream()); - const std::string showIncludesPrefix = + const std::string& showIncludesPrefix = this->GetMakefile()->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"); if (!showIncludesPrefix.empty()) { cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(), diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index beabf91..9b21739 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -108,7 +108,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( // Get the language to use for linking this library. std::string linkLanguage = "CUDA"; - std::string const objExt = + std::string const& objExt = this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); // Build list of dependencies. diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index a751b24..e62b107 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1430,7 +1430,7 @@ void cmMakefileTargetGenerator::AppendTargetDepends( } // Loop over all library dependencies. - const char* cfg = this->LocalGenerator->GetConfigName().c_str(); + const std::string& cfg = this->LocalGenerator->GetConfigName(); if (cmComputeLinkInformation* cli = this->GeneratorTarget->GetLinkInformation(cfg)) { std::vector<std::string> const& libDeps = cli->GetDepends(); @@ -1635,7 +1635,8 @@ void cmMakefileTargetGenerator::CreateLinkLibs( { std::string frameworkPath; std::string linkPath; - std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + const std::string& config = + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmComputeLinkInformation* pcli = this->GeneratorTarget->GetLinkInformation(config); this->LocalGenerator->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 680f881..dd63a54 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -605,7 +605,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() // First and very important step is to make sure while inside this // step our link language is set to CUDA std::string cudaLinkLanguage = "CUDA"; - std::string const objExt = + std::string const& objExt = this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); std::string const cfgName = this->GetConfigName(); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 8afac70..e5f5bf2 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -813,7 +813,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) << " target " << this->GetTargetName() << "\n\n"; - std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + const std::string& config = + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); std::vector<cmSourceFile const*> customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, config); for (cmSourceFile const* sf : customCommands) { @@ -1093,7 +1094,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (compilePP) { // In case compilation requires flags that are incompatible with // preprocessing, include them here. - std::string const postFlag = this->Makefile->GetSafeDefinition( + std::string const& postFlag = this->Makefile->GetSafeDefinition( "CMAKE_" + language + "_POSTPROCESS_FLAG"); this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag); } @@ -1342,8 +1343,7 @@ void cmNinjaTargetGenerator::EnsureDirectoryExists( cmSystemTools::MakeDirectory(path); } else { cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator(); - std::string fullPath = - std::string(gg->GetCMakeInstance()->GetHomeOutputDirectory()); + std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory(); // Also ensures their is a trailing slash. gg->StripNinjaOutputPathPrefixAsSuffix(fullPath); fullPath += path; diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index cb9433f..4ed5581 100644 --- a/Source/cmOutputRequiredFilesCommand.cxx +++ b/Source/cmOutputRequiredFilesCommand.cxx @@ -293,8 +293,8 @@ protected: // Make sure we don't visit the same file more than once. info->DependDone = true; - const char* path = info->FullPath.c_str(); - if (!path) { + const std::string& path = info->FullPath; + if (path.empty()) { cmSystemTools::Error( "Attempt to find dependencies for file without path!"); return; @@ -356,7 +356,7 @@ protected: if (!found) { // Couldn't find any dependency information. if (this->ComplainFileRegularExpression.find(info->IncludeName)) { - cmSystemTools::Error("error cannot find dependencies for ", path); + cmSystemTools::Error("error cannot find dependencies for " + path); } else { // Destroy the name of the file so that it won't be output as a // dependency. diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 38f39fb..a5e0f32 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -52,12 +52,6 @@ static std::size_t GetParallelCPUCount() return count; } -static void AddCleanFile(cmMakefile* makefile, std::string const& fileName) -{ - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fileName.c_str(), - false); -} - static std::string FileProjectRelativePath(cmMakefile* makefile, std::string const& fileName) { @@ -320,7 +314,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } cmSystemTools::ConvertToUnixSlashes(this->Dir.Build); // Cleanup build directory - AddCleanFile(makefile, this->Dir.Build); + this->AddCleanFile(this->Dir.Build); // Working directory this->Dir.Work = cbd; @@ -381,15 +375,15 @@ bool cmQtAutoGenInitializer::InitCustomTargets() std::string& filename = this->AutogenTarget.ConfigSettingsFile[cfg]; filename = AppendFilenameSuffix(this->AutogenTarget.SettingsFile, "_" + cfg); - AddCleanFile(makefile, filename); + this->AddCleanFile(filename); } } else { - AddCleanFile(makefile, this->AutogenTarget.SettingsFile); + this->AddCleanFile(this->AutogenTarget.SettingsFile); } this->AutogenTarget.ParseCacheFile = this->Dir.Info; this->AutogenTarget.ParseCacheFile += "/ParseCache.txt"; - AddCleanFile(makefile, this->AutogenTarget.ParseCacheFile); + this->AddCleanFile(this->AutogenTarget.ParseCacheFile); } // Autogen target: Compute user defined dependencies @@ -1528,6 +1522,12 @@ bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName, return true; } +void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName) +{ + Target->Target->AppendProperty("ADDITIONAL_CLEAN_FILES", fileName.c_str(), + false); +} + static unsigned int CharPtrToUInt(const char* const input) { unsigned long tmp = 0; diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 153f56d..6d2dcb6 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -145,6 +145,7 @@ private: bool prepend = false); bool AddToSourceGroup(std::string const& fileName, std::string const& genNameUpper); + void AddCleanFile(std::string const& fileName); bool GetQtExecutable(GenVarsT& genVars, const std::string& executable, bool ignoreMissingTarget, std::string* output) const; diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 4b0707b..a92c2a0 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -146,7 +146,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, const char* compileOutput = this->Makefile->GetDefinition(this->OutputVariable); if (compileOutput) { - runOutputContents = std::string(compileOutput) + runOutputContents; + runOutputContents = compileOutput + runOutputContents; } this->Makefile->AddDefinition(this->OutputVariable, runOutputContents.c_str()); @@ -167,7 +167,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, int retVal = -1; std::string finalCommand; - const std::string emulator = + const std::string& emulator = this->Makefile->GetSafeDefinition("CMAKE_CROSSCOMPILING_EMULATOR"); if (!emulator.empty()) { std::vector<std::string> emulatorWithArgs; @@ -233,7 +233,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, this->RunResultVariable + "__TRYRUN_OUTPUT"; bool error = false; - if (this->Makefile->GetDefinition(this->RunResultVariable) == nullptr) { + if (!this->Makefile->GetDefinition(this->RunResultVariable)) { // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment; @@ -255,8 +255,8 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, } // is the output from the executable used ? - if (out != nullptr) { - if (this->Makefile->GetDefinition(internalRunOutputName) == nullptr) { + if (out) { + if (!this->Makefile->GetDefinition(internalRunOutputName)) { // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment; @@ -304,7 +304,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, comment += " to\n" " the exit code (in many cases 0 for success), otherwise " "enter \"FAILED_TO_RUN\".\n"; - if (out != nullptr) { + if (out) { comment += internalRunOutputName; comment += "\n contains the text the executable " @@ -335,7 +335,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, << this->Makefile->GetDefinition(this->RunResultVariable) << "\"\n CACHE STRING \"Result from TRY_RUN\" FORCE)\n\n"; - if (out != nullptr) { + if (out) { file << "set( " << internalRunOutputName << " \n \"" << this->Makefile->GetDefinition(internalRunOutputName) << "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n"; @@ -348,7 +348,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, "please set the following cache variables " "appropriately:\n"; errorMessage += " " + this->RunResultVariable + " (advanced)\n"; - if (out != nullptr) { + if (out) { errorMessage += " " + internalRunOutputName + " (advanced)\n"; } errorMessage += detailsString; @@ -356,7 +356,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, return; } - if (out != nullptr) { + if (out) { (*out) = this->Makefile->GetDefinition(internalRunOutputName); } } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c60706d..ab9ef79 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2858,7 +2858,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( // Get compile flags for CUDA in this directory. std::string CONFIG = cmSystemTools::UpperCase(configName); - std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG; + std::string configFlagsVar = "CMAKE_CUDA_FLAGS_" + CONFIG; std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") + " " + this->Makefile->GetSafeDefinition(configFlagsVar); this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA", @@ -3075,7 +3075,7 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( Options& masmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); - std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG; + std::string configFlagsVar = "CMAKE_ASM_MASM_FLAGS_" + CONFIG; std::string flags = this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS") + " " + this->Makefile->GetSafeDefinition(configFlagsVar); @@ -3428,7 +3428,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string standardLibsVar = "CMAKE_"; standardLibsVar += linkLanguage; standardLibsVar += "_STANDARD_LIBRARIES"; - std::string const libs = this->Makefile->GetSafeDefinition(standardLibsVar); + std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar); cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec); linkOptions.AddFlag("AdditionalDependencies", libVec); diff --git a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt index 1dedbae..a24cd53 100644 --- a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(target_compile_options ) target_compile_options(target_compile_options PRIVATE $<$<CXX_COMPILER_ID:GNU>:-DMY_PRIVATE_DEFINE> - PUBLIC $<$<CXX_COMPILER_ID:GNU>:-DMY_PUBLIC_DEFINE> + PUBLIC $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-DMY_PUBLIC_DEFINE> INTERFACE $<$<CXX_COMPILER_ID:GNU>:-DMY_INTERFACE_DEFINE> ) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index d992986..852b00f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2525,24 +2525,17 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release FAIL_REGULAR_EXPRESSION "CMakeLists.txt:5 \\(set\\):") list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedUnusedViaUnset") - if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND NOT WIN32) - # Ninja does not support ADDITIONAL_MAKE_CLEAN_FILES and therefore fails - # this test. (See #13371) - # Apparently Visual Studio does not support it either. As the MakeClean - # test above is only run with the Makefiles generator, only run this - # test with the Makefiles generator also. - add_test(WarnUnusedCliUnused ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMake_SOURCE_DIR}/Tests/WarnUnusedCliUnused" - "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused" - ${build_generator_args} - --build-project WarnUnusedCliUnused - --build-options ${build_options} - "-DUNUSED_CLI_VARIABLE=Unused") - set_tests_properties(WarnUnusedCliUnused PROPERTIES - PASS_REGULAR_EXPRESSION "CMake Warning:.*Manually-specified variables were not used by the project:.* UNUSED_CLI_VARIABLE") - list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused") - endif() + add_test(WarnUnusedCliUnused ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/WarnUnusedCliUnused" + "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused" + ${build_generator_args} + --build-project WarnUnusedCliUnused + --build-options ${build_options} + "-DUNUSED_CLI_VARIABLE=Unused") + set_tests_properties(WarnUnusedCliUnused PROPERTIES + PASS_REGULAR_EXPRESSION "CMake Warning:.*Manually-specified variables were not used by the project:.* UNUSED_CLI_VARIABLE") + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused") add_test(WarnUnusedCliUsed ${CMAKE_CTEST_COMMAND} --build-and-test diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt index 15a993c..18896bf 100644 --- a/Tests/CompileOptions/CMakeLists.txt +++ b/Tests/CompileOptions/CMakeLists.txt @@ -25,6 +25,7 @@ set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS "-DTEST_DEFINE" "-DNEEDS_ESCAPE=\"E$CAPE\"" "$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE_GNU>" + "$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-DTEST_DEFINE_CXX_AND_GNU>" "SHELL:" # produces no options ${c_tests} ${cxx_tests} diff --git a/Tests/CompileOptions/main.cpp b/Tests/CompileOptions/main.cpp index d94a169..ebc1017 100644 --- a/Tests/CompileOptions/main.cpp +++ b/Tests/CompileOptions/main.cpp @@ -10,6 +10,9 @@ # ifndef TEST_DEFINE_GNU # error Expected definition TEST_DEFINE_GNU # endif +# ifndef TEST_DEFINE_CXX_AND_GNU +# error Expected definition TEST_DEFINE_CXX_AND_GNU +# endif #endif #ifndef NO_DEF_TESTS diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt new file mode 100644 index 0000000..fc3c3de --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at COMPILE_LANG_AND_ID-add_custom_command.cmake:2 \(add_custom_command\): + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID> + + \$<COMPILE_LANG_AND_ID> expression requires 2 comma separated parameters, + but got 0 instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command.cmake new file mode 100644 index 0000000..9bd5e8e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command.cmake @@ -0,0 +1,4 @@ +add_custom_target(drive) +add_custom_command(TARGET drive PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANG_AND_ID> +) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target-stderr.txt new file mode 100644 index 0000000..589e64b --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at COMPILE_LANG_AND_ID-add_custom_target.cmake:2 \(add_custom_target\): + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID:LANG,ID> + + \$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets to + specify include directories, compile definitions, and compile options. It + may not be used with the add_custom_command, add_custom_target, or + file\(GENERATE\) commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target.cmake new file mode 100644 index 0000000..398db19 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_target.cmake @@ -0,0 +1,4 @@ + +add_custom_target(drive + COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANG_AND_ID:LANG,ID> +) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable-stderr.txt new file mode 100644 index 0000000..3b3f38d --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at COMPILE_LANG_AND_ID-add_executable.cmake:1 \(add_executable\): + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID:C,MSVC> + + \$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets to + specify include directories, compile definitions, and compile options. It + may not be used with the add_custom_command, add_custom_target, or + file\(GENERATE\) commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable.cmake new file mode 100644 index 0000000..2245f50 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_executable.cmake @@ -0,0 +1,5 @@ +add_executable(empty main.c + $<$<COMPILE_LANG_AND_ID:C,MSVC>:empty.c> + $<$<COMPILE_LANG_AND_ID:C,GNU>:empty2.c> + $<$<COMPILE_LANG_AND_ID:C,Clang>:empty3.c> + ) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library-stderr.txt new file mode 100644 index 0000000..4cbf000 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at COMPILE_LANG_AND_ID-add_library.cmake:2 \(add_library\): + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID:C,MSVC> + + \$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets to + specify include directories, compile definitions, and compile options. It + may not be used with the add_custom_command, add_custom_target, or + file\(GENERATE\) commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library.cmake new file mode 100644 index 0000000..044962a --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_library.cmake @@ -0,0 +1,2 @@ + +add_library(empty empty.$<COMPILE_LANG_AND_ID:C,MSVC>) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test-stderr.txt new file mode 100644 index 0000000..26a5940 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at COMPILE_LANG_AND_ID-add_test.cmake:5 \(add_test\): + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID:CXX,GNU> + + \$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets to + specify include directories, compile definitions, and compile options. It + may not be used with the add_custom_command, add_custom_target, or + file\(GENERATE\) commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test.cmake new file mode 100644 index 0000000..b5b6c2b --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_test.cmake @@ -0,0 +1,5 @@ + +include(CTest) +enable_testing() + +add_test(NAME dummy COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANG_AND_ID:CXX,GNU>) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install-stderr.txt new file mode 100644 index 0000000..0c4ecd0 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install-stderr.txt @@ -0,0 +1,9 @@ +CMake Error: + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID:C,MSVC> + + \$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets to + specify include directories, compile definitions, and compile options. It + may not be used with the add_custom_command, add_custom_target, or + file\(GENERATE\) commands. diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install.cmake new file mode 100644 index 0000000..c13eda6 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-install.cmake @@ -0,0 +1,5 @@ + +install(FILES + empty.$<COMPILE_LANG_AND_ID:C,MSVC> + DESTINATION src +) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt new file mode 100644 index 0000000..44d8684 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at COMPILE_LANG_AND_ID-target_sources.cmake:2 \(target_sources\): + Error evaluating generator expression: + + \$<COMPILE_LANG_AND_ID> + + \$<COMPILE_LANG_AND_ID> expression requires 2 comma separated parameters, + but got 0 instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources.cmake new file mode 100644 index 0000000..a2c9b03 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources.cmake @@ -0,0 +1,2 @@ +add_library(empty) +target_sources(empty PRIVATE empty.$<COMPILE_LANG_AND_ID>) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-unknown-lang.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-unknown-lang.cmake new file mode 100644 index 0000000..b9e840b --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-unknown-lang.cmake @@ -0,0 +1,4 @@ + +enable_language(C) +add_executable(empty empty.c) +target_compile_options(empty PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,GNU>:$<TARGET_EXISTS:too,many,parameters>>) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index a491e99..8abf70d 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -31,6 +31,14 @@ run_cmake(COMPILE_LANGUAGE-add_executable) run_cmake(COMPILE_LANGUAGE-add_library) run_cmake(COMPILE_LANGUAGE-add_test) run_cmake(COMPILE_LANGUAGE-unknown-lang) +run_cmake(COMPILE_LANG_AND_ID-add_custom_target) +run_cmake(COMPILE_LANG_AND_ID-add_custom_command) +run_cmake(COMPILE_LANG_AND_ID-install) +run_cmake(COMPILE_LANG_AND_ID-target_sources) +run_cmake(COMPILE_LANG_AND_ID-add_executable) +run_cmake(COMPILE_LANG_AND_ID-add_library) +run_cmake(COMPILE_LANG_AND_ID-add_test) +run_cmake(COMPILE_LANG_AND_ID-unknown-lang) run_cmake(TARGET_FILE-recursion) run_cmake(OUTPUT_NAME-recursion) run_cmake(TARGET_FILE_PREFIX) diff --git a/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN.cmake b/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN.cmake new file mode 100644 index 0000000..d8a12eb --- /dev/null +++ b/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN.cmake @@ -0,0 +1,168 @@ +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/dest1") + +file(TOUCH "${CMAKE_BINARY_DIR}/file1.txt") +file(CREATE_LINK file1.txt "${CMAKE_BINARY_DIR}/file1.txt.sym" SYMBOLIC) +file(TOUCH "${CMAKE_BINARY_DIR}/dest1/file1.txt.sym") + +file(TOUCH "${CMAKE_BINARY_DIR}/file2.txt") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file2") +file(CREATE_LINK ../file2.txt "${CMAKE_BINARY_DIR}/file2/file2.txt.sym" SYMBOLIC) + +file(TOUCH "${CMAKE_BINARY_DIR}/file3.txt") +file(CREATE_LINK "${CMAKE_BINARY_DIR}/file3.txt" "${CMAKE_BINARY_DIR}/file3.txt.sym" SYMBOLIC) + +file(TOUCH "${CMAKE_BINARY_DIR}/file4.txt") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file4") +file(CREATE_LINK "${CMAKE_BINARY_DIR}/file4.txt" "${CMAKE_BINARY_DIR}/file4/file4.txt.sym" SYMBOLIC) + +file(TOUCH "${CMAKE_BINARY_DIR}/file5.txt") + +file(TOUCH "${CMAKE_BINARY_DIR}/file6.txt") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file6/file6") +file(CREATE_LINK file6.txt "${CMAKE_BINARY_DIR}/file6.txt.sym.1" SYMBOLIC) +file(CREATE_LINK ../file6.txt.sym.1 "${CMAKE_BINARY_DIR}/file6/file6.txt.sym.2" SYMBOLIC) +file(CREATE_LINK "${CMAKE_BINARY_DIR}/file6/file6.txt.sym.2" "${CMAKE_BINARY_DIR}/file6/file6/file6.txt.sym.3" SYMBOLIC) +file(CREATE_LINK file6.txt.sym.3 "${CMAKE_BINARY_DIR}/file6/file6/file6.txt.sym.4" SYMBOLIC) + +file(TOUCH "${CMAKE_BINARY_DIR}/file7.txt") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file7") + +file(TOUCH "${CMAKE_BINARY_DIR}/file8.txt") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file8") +file(CREATE_LINK "${CMAKE_BINARY_DIR}/file8/../file8.txt" "${CMAKE_BINARY_DIR}/file8/file8.txt.sym" SYMBOLIC) + +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file9") +file(TOUCH "${CMAKE_BINARY_DIR}/file9/file9.txt") +file(CREATE_LINK "${CMAKE_BINARY_DIR}/file9" "${CMAKE_BINARY_DIR}/file9.sym" SYMBOLIC) + +file(TOUCH "${CMAKE_BINARY_DIR}/file10.txt") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/file10") +file(CREATE_LINK "." "${CMAKE_BINARY_DIR}/file10/file10" SYMBOLIC) +file(CREATE_LINK "${CMAKE_BINARY_DIR}/file10/file10/../file10.txt" "${CMAKE_BINARY_DIR}/file10/file10.txt.sym" SYMBOLIC) + +file(INSTALL + "${CMAKE_BINARY_DIR}/file1.txt.sym" + DESTINATION "${CMAKE_BINARY_DIR}/dest1" + FOLLOW_SYMLINK_CHAIN + ) + +file(INSTALL + "${CMAKE_BINARY_DIR}/file1.txt.sym" + "${CMAKE_BINARY_DIR}/file2/file2.txt.sym" + "${CMAKE_BINARY_DIR}/file3.txt.sym" + "${CMAKE_BINARY_DIR}/file4/file4.txt.sym" + "${CMAKE_BINARY_DIR}/file5.txt" + "${CMAKE_BINARY_DIR}/file6/file6/file6.txt.sym.4" + "${CMAKE_BINARY_DIR}/file8/file8.txt.sym" + "${CMAKE_BINARY_DIR}/file7/../file7.txt" + "${CMAKE_BINARY_DIR}/file8.txt" + "${CMAKE_BINARY_DIR}/file9.sym/file9.txt" + "${CMAKE_BINARY_DIR}/file10/file10/file10.txt.sym" + DESTINATION "${CMAKE_BINARY_DIR}/dest2" + FOLLOW_SYMLINK_CHAIN + ) + +set(resolved_file1.txt.sym file1.txt) +set(resolved_file10.txt.sym file10.txt) +set(resolved_file2.txt.sym file2.txt) +set(resolved_file3.txt.sym file3.txt) +set(resolved_file4.txt.sym file4.txt) +set(resolved_file6.txt.sym.1 file6.txt) +set(resolved_file6.txt.sym.2 file6.txt.sym.1) +set(resolved_file6.txt.sym.3 file6.txt.sym.2) +set(resolved_file6.txt.sym.4 file6.txt.sym.3) +set(resolved_file8.txt.sym file8.txt) +set(syms) +foreach(f + file1.txt + file1.txt.sym + file10.txt + file10.txt.sym + file2.txt + file2.txt.sym + file3.txt + file3.txt.sym + file4.txt + file4.txt.sym + file5.txt + file6.txt + file6.txt.sym.1 + file6.txt.sym.2 + file6.txt.sym.3 + file6.txt.sym.4 + file7.txt + file8.txt + file8.txt.sym + file9.txt + ) + string(REPLACE "." "\\." r "${f}") + list(APPEND syms "[^;]*/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN-build/dest2/${r}") + set(filename "${CMAKE_BINARY_DIR}/dest2/${f}") + if(DEFINED resolved_${f}) + file(READ_SYMLINK "${filename}" resolved) + if(NOT resolved STREQUAL "${resolved_${f}}") + message(SEND_ERROR "Expected symlink resolution for ${f}: ${resolved_${f}}\nActual resolution: ${resolved}") + endif() + elseif(NOT EXISTS "${filename}" OR IS_SYMLINK "${filename}" OR IS_DIRECTORY "${filename}") + message(SEND_ERROR "${f} should be a regular file") + endif() +endforeach() + +file(GLOB_RECURSE actual_syms LIST_DIRECTORIES true "${CMAKE_BINARY_DIR}/dest2/*") +if(NOT actual_syms MATCHES "^${syms}$") + message(SEND_ERROR "Expected files:\n\n ^${syms}$\n\nActual files:\n\n ${actual_syms}") +endif() + +file(INSTALL + "${CMAKE_BINARY_DIR}/file1.txt.sym" + "${CMAKE_BINARY_DIR}/file2/file2.txt.sym" + "${CMAKE_BINARY_DIR}/file3.txt.sym" + "${CMAKE_BINARY_DIR}/file4/file4.txt.sym" + "${CMAKE_BINARY_DIR}/file5.txt" + "${CMAKE_BINARY_DIR}/file6/file6/file6.txt.sym.4" + "${CMAKE_BINARY_DIR}/file8/file8.txt.sym" + "${CMAKE_BINARY_DIR}/file7/../file7.txt" + "${CMAKE_BINARY_DIR}/file8.txt" + "${CMAKE_BINARY_DIR}/file9.sym/file9.txt" + "${CMAKE_BINARY_DIR}/file10/file10/file10.txt.sym" + DESTINATION "${CMAKE_BINARY_DIR}/dest3" + ) + +set(resolved_file1.txt.sym [[^file1\.txt$]]) +set(resolved_file10.txt.sym [[/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN-build/file10/file10/\.\./file10\.txt$]]) +set(resolved_file2.txt.sym [[^\.\./file2\.txt$]]) +set(resolved_file3.txt.sym [[/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN-build/file3\.txt$]]) +set(resolved_file4.txt.sym [[/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN-build/file4\.txt$]]) +set(resolved_file6.txt.sym.4 [[^file6\.txt\.sym\.3$]]) +set(resolved_file8.txt.sym [[/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN-build/file8/\.\./file8\.txt$]]) +set(syms) +foreach(f + file1.txt.sym + file10.txt.sym + file2.txt.sym + file3.txt.sym + file4.txt.sym + file5.txt + file6.txt.sym.4 + file7.txt + file8.txt + file8.txt.sym + file9.txt + ) + string(REPLACE "." "\\." r "${f}") + list(APPEND syms "[^;]*/Tests/RunCMake/file/INSTALL-FOLLOW_SYMLINK_CHAIN-build/dest3/${r}") + set(filename "${CMAKE_BINARY_DIR}/dest3/${f}") + if(DEFINED resolved_${f}) + file(READ_SYMLINK "${filename}" resolved) + if(NOT resolved MATCHES "${resolved_${f}}") + message(SEND_ERROR "Expected symlink resolution for ${f}: ${resolved_${f}}\nActual resolution: ${resolved}") + endif() + elseif(NOT EXISTS "${filename}" OR IS_SYMLINK "${filename}" OR IS_DIRECTORY "${filename}") + message(SEND_ERROR "${f} should be a regular file") + endif() +endforeach() + +file(GLOB_RECURSE actual_syms LIST_DIRECTORIES true "${CMAKE_BINARY_DIR}/dest3/*") +if(NOT actual_syms MATCHES "^${syms}$") + message(SEND_ERROR "Expected files:\n\n ^${syms}$\n\nActual files:\n\n ${actual_syms}") +endif() diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake index 128e8f3..996d1c5 100644 --- a/Tests/RunCMake/file/RunCMakeTest.cmake +++ b/Tests/RunCMake/file/RunCMakeTest.cmake @@ -64,6 +64,7 @@ if(NOT WIN32 OR CYGWIN) run_cmake(READ_SYMLINK) run_cmake(READ_SYMLINK-noexist) run_cmake(READ_SYMLINK-notsymlink) + run_cmake(INSTALL-FOLLOW_SYMLINK_CHAIN) endif() if(RunCMake_GENERATOR STREQUAL "Ninja") diff --git a/Tests/WarnUnusedCliUnused/CMakeLists.txt b/Tests/WarnUnusedCliUnused/CMakeLists.txt index 7ed69bf..a149f04 100644 --- a/Tests/WarnUnusedCliUnused/CMakeLists.txt +++ b/Tests/WarnUnusedCliUnused/CMakeLists.txt @@ -1,9 +1,9 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.14) project(WarnUnusedCliUnused) -set_directory_properties(PROPERTIES - ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/CMakeCache.txt" -) +# Remove UNUSED_CLI_VARIABLE from the cache to trigger the +# CMake warning message on re-builds as well. +unset(UNUSED_CLI_VARIABLE CACHE) add_library(dummy empty.cpp) |