diff options
34 files changed, 454 insertions, 204 deletions
diff --git a/Help/command/if.rst b/Help/command/if.rst index 72d328d..c51d2bc 100644 --- a/Help/command/if.rst +++ b/Help/command/if.rst @@ -47,7 +47,8 @@ as ``EXISTS``, ``COMMAND``, and ``DEFINED``. Then binary tests such as and ``MATCHES``. Then the boolean operators in the order ``NOT``, ``AND``, and finally ``OR``. -Possible conditions are: +Basic Expressions +""""""""""""""""" ``if(<constant>)`` True if the constant is ``1``, ``ON``, ``YES``, ``TRUE``, ``Y``, @@ -62,6 +63,9 @@ Possible conditions are: True if given a variable that is defined to a value that is not a false constant. False otherwise. (Note macro arguments are not variables.) +Logic Operators +""""""""""""""" + ``if(NOT <condition>)`` True if the condition is not true. @@ -71,6 +75,15 @@ Possible conditions are: ``if(<cond1> OR <cond2>)`` True if either condition would be considered true individually. +``if((condition) AND (condition OR (condition)))`` + The conditions inside the parenthesis are evaluated first and then + the remaining condition is evaluated as in the other examples. + Where there are nested parenthesis the innermost are evaluated as part + of evaluating the condition that contains them. + +Existence Checks +"""""""""""""""" + ``if(COMMAND command-name)`` True if the given name is a command, macro or function that can be invoked. @@ -89,6 +102,21 @@ Possible conditions are: True if the given name is an existing test name created by the :command:`add_test` command. +``if(DEFINED <name>|CACHE{<name>}|ENV{<name>})`` + True if a variable, cache variable or environment variable + with given ``<name>`` is defined. The value of the variable + does not matter. Note that macro arguments are not variables. + + .. versionadded:: 3.14 + Added support for ``CACHE{<name>}`` variables. + +``if(<variable|string> IN_LIST <variable>)`` + .. versionadded:: 3.3 + True if the given element is contained in the named list variable. + +File Operations +""""""""""""""" + ``if(EXISTS path-to-file-or-directory)`` True if the named file or directory exists. Behavior is well-defined only for full paths. Resolves symbolic links, i.e. if the named file or @@ -114,6 +142,9 @@ Possible conditions are: ``if(IS_ABSOLUTE path)`` True if the given path is an absolute path. +Comparisons +""""""""""" + ``if(<variable|string> MATCHES regex)`` True if the given string or variable's value matches the given regular condition. See :ref:`Regex Specification` for regex format. @@ -165,6 +196,9 @@ Possible conditions are: True if the given string or variable's value is lexicographically greater than or equal to the string or variable on the right. +Version Comparisons +""""""""""""""""""" + ``if(<variable|string> VERSION_LESS <variable|string>)`` Component-wise integer version number comparison (version format is ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero). @@ -197,24 +231,6 @@ Possible conditions are: Any non-integer version component or non-integer trailing part of a version component effectively truncates the string at that point. -``if(<variable|string> IN_LIST <variable>)`` - .. versionadded:: 3.3 - True if the given element is contained in the named list variable. - -``if(DEFINED <name>|CACHE{<name>}|ENV{<name>})`` - True if a variable, cache variable or environment variable - with given ``<name>`` is defined. The value of the variable - does not matter. Note that macro arguments are not variables. - - .. versionadded:: 3.14 - Added support for ``CACHE{<name>}`` variables. - -``if((condition) AND (condition OR (condition)))`` - The conditions inside the parenthesis are evaluated first and then - the remaining condition is evaluated as in the previous examples. - Where there are nested parenthesis the innermost are evaluated as part - of evaluating the condition that contains them. - Variable Expansion ^^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Ninja Multi-Config.rst b/Help/generator/Ninja Multi-Config.rst index d1df42b..8901192 100644 --- a/Help/generator/Ninja Multi-Config.rst +++ b/Help/generator/Ninja Multi-Config.rst @@ -130,3 +130,34 @@ output config using the ``Release`` command config. The ``Release`` build of the ``generator`` target is called with ``Debug.txt Debug Release`` as arguments. The command depends on the ``Release`` builds of ``tgt1`` and ``tgt4``, and the ``Debug`` builds of ``tgt2`` and ``tgt3``. + +``PRE_BUILD``, ``PRE_LINK``, and ``POST_BUILD`` custom commands for targets +only get run in their "native" configuration (the ``Release`` configuration in +the ``build-Release.ninja`` file) unless they have no ``BYPRODUCTS`` or their +``BYPRODUCTS`` are unique per config. Consider the following example: + +.. code-block:: cmake + + add_executable(exe main.c) + add_custom_command( + TARGET exe + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Running no-byproduct command" + ) + add_custom_command( + TARGET exe + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Running separate-byproduct command for $<CONFIG>" + BYPRODUCTS $<CONFIG>.txt + ) + add_custom_command( + TARGET exe + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Running common-byproduct command for $<CONFIG>" + BYPRODUCTS exe.txt + ) + +In this example, if you build ``exe:Debug`` in ``build-Release.ninja``, the +first and second custom commands get run, since their byproducts are unique +per-config, but the last custom command does not. However, if you build +``exe:Release`` in ``build-Release.ninja``, all three custom commands get run. diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index 85ed935..af9a8ab 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -23,15 +23,14 @@ in turn link to developer guides for CMake itself. Find Modules ============ -A "find module" is a ``Find<PackageName>.cmake`` file to be loaded -by the :command:`find_package` command when invoked for ``<PackageName>``. +A "find module" is a ``Find<PackageName>.cmake`` file to be loaded by the +:command:`find_package` command when invoked for ``<PackageName>``. -The primary task of a find module is to determine whether a package -exists on the system, set the ``<PackageName>_FOUND`` variable to reflect -this and provide any variables, macros and imported targets required to -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 primary task of a find module is to determine whether a package is +available, set the ``<PackageName>_FOUND`` variable to reflect this and +provide any variables, macros and imported targets required to 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 @@ -91,55 +90,92 @@ Standard Variable Names For a ``FindXxx.cmake`` module that takes the approach of setting variables (either instead of or in addition to creating imported targets), the following variable names should be used to keep things -consistent between find modules. Note that all variables start with -``Xxx_`` to make sure they do not interfere with other find modules; the -same consideration applies to macros, functions and imported targets. +consistent between Find modules. Note that all variables start with +``Xxx_``, which (unless otherwise noted) must match exactly the name +of the ``FindXxx.cmake`` file, including upper/lowercase. +This prefix on the variable names ensures that they do not conflict with +variables of other Find modules. The same pattern should also be followed +for any macros, functions and imported targets defined by the Find module. ``Xxx_INCLUDE_DIRS`` The final set of include directories listed in one variable for use by - client code. This should not be a cache entry. + client code. This should not be a cache entry (note that this also means + this variable should not be used as the result variable of a + :command:`find_path` command - see ``Xxx_INCLUDE_DIR`` below for that). ``Xxx_LIBRARIES`` - The libraries to link against to use Xxx. These should include full - paths. This should not be a cache entry. + The libraries to use with the module. These may be CMake targets, full + absolute paths to a library binary or the name of a library that the + linker must find in its search path. This should not be a cache entry + (note that this also means this variable should not be used as the + result variable of a :command:`find_library` command - see + ``Xxx_LIBRARY`` below for that). ``Xxx_DEFINITIONS`` - Definitions to use when compiling code that uses Xxx. This really - shouldn't include options such as ``-DHAS_JPEG`` that a client + The compile definitions to use when compiling code that uses the module. + This really shouldn't include options such as ``-DHAS_JPEG`` that a client source-code file uses to decide whether to ``#include <jpeg.h>`` ``Xxx_EXECUTABLE`` - Where to find the Xxx tool. - -``Xxx_Yyy_EXECUTABLE`` - Where to find the Yyy tool that comes with Xxx. + The full absolute path to an executable. In this case, ``Xxx`` might not + be the name of the module, it might be the name of the tool (usually + converted to all uppercase), assuming that tool has such a well-known name + that it is unlikely that another tool with the same name exists. It would + be appropriate to use this as the result variable of a + :command:`find_program` command. + +``Xxx_YYY_EXECUTABLE`` + Similar to ``Xxx_EXECUTABLE`` except here the ``Xxx`` is always the module + name and ``YYY`` is the tool name (again, usually fully uppercase). + Prefer this form if the tool name is not very widely known or has the + potential to clash with another tool. For greater consistency, also + prefer this form if the module provides more than one executable. ``Xxx_LIBRARY_DIRS`` Optionally, the final set of library directories listed in one - variable for use by client code. This should not be a cache entry. + variable for use by client code. This should not be a cache entry. ``Xxx_ROOT_DIR`` - Where to find the base directory of Xxx. - -``Xxx_VERSION_Yy`` - Expect Version Yy if true. Make sure at most one of these is ever true. - -``Xxx_WRAP_Yy`` - If False, do not try to use the relevant CMake wrapping command. + Where to find the base directory of the module. + +``Xxx_VERSION_VV`` + Variables of this form specify whether the ``Xxx`` module being provided + is version ``VV`` of the module. There should not be more than one + variable of this form set to true for a given module. For example, a + module ``Barry`` might have evolved over many years and gone through a + number of different major versions. Version 3 of the ``Barry`` module + might set the variable ``Barry_VERSION_3`` to true, whereas an older + version of the module might set ``Barry_VERSION_2`` to true instead. + It would be an error for both ``Barry_VERSION_3`` and ``Barry_VERSION_2`` + to both be set to true. + +``Xxx_WRAP_YY`` + When a variable of this form is set to false, it indicates that the + relevant wrapping command should not be used. The wrapping command + depends on the module, it may be implied by the module name or it might + be specified by the ``YY`` part of the variable. ``Xxx_Yy_FOUND`` - If False, optional Yy part of Xxx system is not available. + For variables of this form, ``Yy`` is the name of a component for the + module. It should match exactly one of the valid component names that + may be passed to the :command:`find_package` command for the module. + If a variable of this form is set to false, it means that the ``Yy`` + component of module ``Xxx`` was not found or is not available. + Variables of this form would typically be used for optional components + so that the caller can check whether an optional component is available. ``Xxx_FOUND`` - Set to false, or undefined, if we haven't found, or don't want to use - Xxx. + When the :command:`find_package` command returns to the caller, this + variable will be set to true if the module was deemed to have been found + successfully. ``Xxx_NOT_FOUND_MESSAGE`` Should be set by config-files in the case that it has set ``Xxx_FOUND`` to FALSE. The contained message will be printed by the :command:`find_package` command and by - ``find_package_handle_standard_args()`` to inform the user about the - problem. + :command:`find_package_handle_standard_args` to inform the user about the + problem. Use this instead of calling :command:`message` directly to + report a reason for failing to find the module or package. ``Xxx_RUNTIME_LIBRARY_DIRS`` Optionally, the runtime library search path for use when running an @@ -160,23 +196,36 @@ same consideration applies to macros, functions and imported targets. ``Xxx_VERSION_PATCH`` The patch version of the package found, if any. -The following names should not usually be used in CMakeLists.txt files, but -are typically cache variables for users to edit and control the -behaviour of find modules (like entering the path to a library manually) +The following names should not usually be used in ``CMakeLists.txt`` files. +They are intended for use by Find modules to specify and cache the locations +of specific files or directories. Users are typically able to set and edit +these variables to control the behavior of Find modules (like entering the +path to a library manually): ``Xxx_LIBRARY`` - The path of the Xxx library (as used with :command:`find_library`, for - example). + The path of the library. Use this form only when the module provides a + single library. It is appropriate to use this as the result variable + in a :command:`find_library` command. ``Xxx_Yy_LIBRARY`` - The path of the Yy library that is part of the Xxx system. It may or - may not be required to use Xxx. + The path of library ``Yy`` provided by the module ``Xxx``. Use this form + when the module provides more than one library or where other modules may + also provide a library of the same name. It is also appropriate to use + this form as the result variable in a :command:`find_library` command. ``Xxx_INCLUDE_DIR`` - Where to find headers for using the Xxx library. + When the module provides only a single library, this variable can be used + to specify where to find headers for using the library (or more accurately, + the path that consumers of the library should add to their header search + path). It would be appropriate to use this as the result variable in a + :command:`find_path` command. ``Xxx_Yy_INCLUDE_DIR`` - Where to find headers for using the Yy library of the Xxx system. + If the module provides more than one library or where other modules may + also provide a library of the same name, this form is recommended for + specifying where to find headers for using library ``Yy`` provided by + the module. Again, it would be appropriate to use this as the result + variable in a :command:`find_path` command. 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 @@ -185,7 +234,8 @@ not-found library (e.g. ``Xxx_ROOT_DIR``). For the same reason, mark 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``. +``Foo_LIBRARY_DEBUG``. The :module:`SelectLibraryConfigurations` module +can be helpful for such cases. While these are the standard variable names, you should provide backwards compatibility for any old names that were actually in use. diff --git a/Help/release/dev/cuda-nvcc-ccache-symlink.rst b/Help/release/dev/cuda-nvcc-ccache-symlink.rst new file mode 100644 index 0000000..4d38047 --- /dev/null +++ b/Help/release/dev/cuda-nvcc-ccache-symlink.rst @@ -0,0 +1,9 @@ +cuda-nvcc-ccache-symlink +------------------------ + +* ``CUDA`` language support now works when ``nvcc`` is a symbolic link, + for example due to a ``ccache`` or ``colornvcc`` wrapper script. + +* The :module:`FindCUDAToolkit` module gained support for finding CUDA + toolkits when ``nvcc`` is a symbolic link, + for example due to a ``ccache`` or ``colornvcc`` wrapper script. diff --git a/Help/variable/CMAKE_CUDA_ARCHITECTURES.rst b/Help/variable/CMAKE_CUDA_ARCHITECTURES.rst index 7f7e679..d885516 100644 --- a/Help/variable/CMAKE_CUDA_ARCHITECTURES.rst +++ b/Help/variable/CMAKE_CUDA_ARCHITECTURES.rst @@ -18,3 +18,18 @@ and compiler versions. This variable is used to initialize the :prop_tgt:`CUDA_ARCHITECTURES` property on all targets. See the target property for additional information. + +Examples +^^^^^^^^ + +.. code-block:: cmake + + cmake_minimum_required(VERSION) + + if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + set(CMAKE_CUDA_ARCHITECTURES 75) + endif() + + project(example LANGUAGES CUDA) + +``CMAKE_CUDA_ARCHITECTURES`` will default to ``75`` unless overridden by the user. diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index ae3abe9..ab33b40 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -161,9 +161,10 @@ if (NOT _CMAKE_TOOLCHAIN_PREFIX) if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME) - if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$") + if (COMPILER_BASENAME MATCHES "^(.+-)?(clang|g?cc)(-cl)?(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$") set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) - set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5}) + set(_CMAKE_TOOLCHAIN_SUFFIX ${CMAKE_MATCH_4}) + set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_6}) elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") if(CMAKE_C_COMPILER_TARGET) set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_C_COMPILER_TARGET}-) diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 578729c..c77fc3a 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -172,7 +172,20 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) endif() endif() - get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) + # If NVCC is a symlink due to a wrapper script (e.g. ccache or colornvcc), then invoke it to find the + # real non-scattered toolkit. + if(IS_SYMLINK ${_CUDA_NVCC_EXECUTABLE}) + execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) + if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)") + set(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not execute nvcc with -v.") + endif() + unset(NVCC_ERR) + else() + get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) + endif() + set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/nvlink${CMAKE_EXECUTABLE_SUFFIX}") set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/fatbinary${CMAKE_EXECUTABLE_SUFFIX}") get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 905eb25..7283bc2 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -160,8 +160,9 @@ if (NOT _CMAKE_TOOLCHAIN_PREFIX) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME) - if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$") + if (COMPILER_BASENAME MATCHES "^(.+-)?(clang\\+\\+|g\\+\\+|clang-cl)(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$") set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) + set(_CMAKE_TOOLCHAIN_SUFFIX ${CMAKE_MATCH_3}) set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5}) elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if(CMAKE_CXX_COMPILER_TARGET) diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index d81fd11..ff178f6 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -70,17 +70,18 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND OR (CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")) + set(_CMAKE_LINKER_NAMES "link") + set(_CMAKE_AR_NAMES "lib") + set(_CMAKE_MT_NAMES "mt") if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang") - find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm llvm-nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - set(_CMAKE_ADDITIONAL_LINKER_NAMES "lld-link") - set(_CMAKE_ADDITIONAL_AR_NAMES "llvm-lib") + set(_CMAKE_NM_NAMES "llvm-nm" "nm") + list(APPEND _CMAKE_AR_NAMES "lib" "llvm-lib") + list(APPEND _CMAKE_MT_NAMES "mt" "llvm-mt") + list(APPEND _CMAKE_LINKER_NAMES "lld-link") + list(APPEND _CMAKE_TOOL_VARS NM) endif() - find_program(CMAKE_LINKER NAMES ${_CMAKE_ADDITIONAL_LINKER_NAMES} link HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_AR NAMES ${_CMAKE_ADDITIONAL_AR_NAMES} lib HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_MT NAMES mt HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - - list(APPEND _CMAKE_TOOL_VARS LINKER MT) + list(APPEND _CMAKE_TOOL_VARS LINKER MT AR) # in all other cases search for ar, ranlib, etc. else() @@ -92,55 +93,54 @@ else() endif() if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL Clang) - set(_CMAKE_ADDITIONAL_AR_NAMES "llvm-ar") - set(_CMAKE_ADDITIONAL_RANLIB_NAMES "llvm-ranlib") - set(_CMAKE_ADDITIONAL_STRIP_NAMES "llvm-strip") if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC") - set(_CMAKE_ADDITIONAL_LINKER_NAMES "lld-link") + set(_CMAKE_LINKER_NAMES "lld-link") else() - set(_CMAKE_ADDITIONAL_LINKER_NAMES "ld.lld") + set(_CMAKE_LINKER_NAMES "ld.lld") endif() - set(_CMAKE_ADDITIONAL_NM_NAMES "llvm-nm") - set(_CMAKE_ADDITIONAL_OBJDUMP_NAMES "llvm-objdump") - set(_CMAKE_ADDITIONAL_OBJCOPY_NAMES "llvm-objcopy") - set(_CMAKE_ADDITIONAL_READELF_NAMES "llvm-readelf") - set(_CMAKE_ADDITIONAL_DLLTOOL_NAMES "llvm-dlltool") - set(_CMAKE_ADDITIONAL_ADDR2LINE_NAMES "llvm-addr2line") + list(APPEND _CMAKE_AR_NAMES "llvm-ar") + list(APPEND _CMAKE_NM_NAMES "llvm-nm") + list(APPEND _CMAKE_OBJDUMP_NAMES "llvm-objdump") + list(APPEND _CMAKE_OBJCOPY_NAMES "llvm-objcopy") + list(APPEND _CMAKE_READELF_NAMES "llvm-readelf") + list(APPEND _CMAKE_DLLTOOL_NAMES "llvm-dlltool") + list(APPEND _CMAKE_ADDR2LINE_NAMES "llvm-addr2line") endif() - if(NOT CMAKE_CROSSCOMPILING AND NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "") - list(APPEND _CMAKE_ADDITIONAL_AR_NAMES "ar") - list(APPEND _CMAKE_ADDITIONAL_RANLIB_NAMES "ranlib") - list(APPEND _CMAKE_ADDITIONAL_STRIP_NAMES "strip") - list(APPEND _CMAKE_ADDITIONAL_LINKER_NAMES "ld") - list(APPEND _CMAKE_ADDITIONAL_NM_NAMES "nm") - list(APPEND _CMAKE_ADDITIONAL_OBJDUMP_NAMES "objdump") - list(APPEND _CMAKE_ADDITIONAL_OBJCOPY_NAMES "objcopy") - list(APPEND _CMAKE_ADDITIONAL_READELF_NAMES "readelf") - list(APPEND _CMAKE_ADDITIONAL_DLLTOOL_NAMES "dlltool") - list(APPEND _CMAKE_ADDITIONAL_ADDR2LINE_NAMES "addr2line") - endif() + list(APPEND _CMAKE_AR_NAMES "ar") + list(APPEND _CMAKE_RANLIB_NAMES "ranlib") + list(APPEND _CMAKE_STRIP_NAMES "strip") + list(APPEND _CMAKE_LINKER_NAMES "ld") + list(APPEND _CMAKE_NM_NAMES "nm") + list(APPEND _CMAKE_OBJDUMP_NAMES "objdump") + list(APPEND _CMAKE_OBJCOPY_NAMES "objcopy") + list(APPEND _CMAKE_READELF_NAMES "readelf") + list(APPEND _CMAKE_DLLTOOL_NAMES "dlltool") + list(APPEND _CMAKE_ADDR2LINE_NAMES "addr2line") + + list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE) +endif() - find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_AR_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) +foreach(TOOL IN LISTS _CMAKE_TOOL_VARS) + foreach(NAME IN LISTS _CMAKE_${TOOL}_NAMES) + if(NOT _CMAKE_TOOLCHAIN_PREFIX STREQUAL "") + if(NOT _CMAKE_TOOLCHAIN_SUFFIX STREQUAL "") + list(PREPEND _CMAKE_${TOOL}_NAMES ${NAME}${_CMAKE_TOOLCHAIN_SUFFIX}) + endif() + list(PREPEND _CMAKE_${TOOL}_NAMES ${_CMAKE_TOOLCHAIN_PREFIX}${NAME}) + endif() + if(NOT _CMAKE_TOOLCHAIN_SUFFIX STREQUAL "") + list(PREPEND _CMAKE_${TOOL}_NAMES ${_CMAKE_TOOLCHAIN_PREFIX}${NAME}${_CMAKE_TOOLCHAIN_SUFFIX}) + endif() + endforeach() + find_program(CMAKE_${TOOL} NAMES ${_CMAKE_${TOOL}_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) +endforeach() - find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib ${_CMAKE_ADDITIONAL_RANLIB_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - if(NOT CMAKE_RANLIB) +if(NOT CMAKE_RANLIB) set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib") - endif() - - - find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_STRIP_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld ${_CMAKE_ADDITIONAL_LINKER_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm ${_CMAKE_ADDITIONAL_NM_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump ${_CMAKE_ADDITIONAL_OBJDUMP_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy ${_CMAKE_ADDITIONAL_OBJCOPY_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_READELF NAMES ${_CMAKE_TOOLCHAIN_PREFIX}readelf ${_CMAKE_ADDITIONAL_READELF_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_DLLTOOL NAMES ${_CMAKE_TOOLCHAIN_PREFIX}dlltool ${_CMAKE_ADDITIONAL_DLLTOOL_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_ADDR2LINE NAMES ${_CMAKE_TOOLCHAIN_PREFIX}addr2line ${_CMAKE_ADDITIONAL_ADDR2LINE_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - - list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE) endif() + if(CMAKE_PLATFORM_HAS_INSTALLNAME) find_program(CMAKE_INSTALL_NAME_TOOL NAMES ${_CMAKE_TOOLCHAIN_PREFIX}install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) @@ -157,7 +157,7 @@ foreach(var IN LISTS _CMAKE_TOOL_VARS) if(_CMAKE_TOOL_CACHED) mark_as_advanced(CMAKE_${var}) endif() - unset(_CMAKE_ADDITIONAL_${var}_NAMES) + unset(_CMAKE_${var}_NAMES) endforeach() unset(_CMAKE_TOOL_VARS) unset(_CMAKE_TOOL_CACHED) diff --git a/Modules/Compiler/Clang-FindBinUtils.cmake b/Modules/Compiler/Clang-FindBinUtils.cmake index b852660..e6c469a 100644 --- a/Modules/Compiler/Clang-FindBinUtils.cmake +++ b/Modules/Compiler/Clang-FindBinUtils.cmake @@ -2,6 +2,12 @@ if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set") endif() +# Ubuntu: +# * /usr/bin/llvm-ar-9 +# * /usr/bin/llvm-ranlib-9 +string(REGEX MATCH "^([0-9]+)" __version_x + "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}") + # Debian: # * /usr/bin/llvm-ar-4.0 # * /usr/bin/llvm-ranlib-4.0 @@ -19,6 +25,7 @@ set(__clang_hints ${__clang_hint_1} ${__clang_hint_2}) # http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ar.1.html find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x_y}" + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x}" "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar" HINTS ${__clang_hints} DOC "LLVM archiver" @@ -28,6 +35,7 @@ mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR) # http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ranlib.1.html find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x_y}" + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x}" "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib" HINTS ${__clang_hints} DOC "Generate index for LLVM archive" diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 6daf81d..240f0a5 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -834,7 +834,20 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) ) if (CUDA_TOOLKIT_ROOT_DIR_NVCC) - get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + # If NVCC is a symlink due to a wrapper script (e.g. ccache or colornvcc), then invoke it to find the + # real non-scattered toolkit. + if(IS_SYMLINK ${CUDA_TOOLKIT_ROOT_DIR_NVCC}) + execute_process(COMMAND ${CUDA_TOOLKIT_ROOT_DIR_NVCC} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) + if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)") + set(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not execute nvcc with -v.") + endif() + unset(NVCC_ERR) + else() + get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + endif() + get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR}" DIRECTORY CACHE) string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) # We need to force this back into the cache. diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index 61e264b..0d80c80 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -519,7 +519,19 @@ else() endif() if(CUDAToolkit_NVCC_EXECUTABLE) - get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) + # If NVCC is a symlink due to a wrapper script (e.g. ccache or colornvcc), then invoke it to find the + # real non-scattered toolkit. + if(IS_SYMLINK ${CUDAToolkit_NVCC_EXECUTABLE}) + execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) + if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)") + set(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not execute nvcc with -v.") + endif() + unset(NVCC_ERR) + else() + get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) + endif() set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE) mark_as_advanced(CUDAToolkit_BIN_DIR) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index 05696ae..f64f72f 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -116,15 +116,22 @@ also be defined. With all components enabled, the following variables will be d With all components enabled, the following targets will be defined: -:: - - ``hdf5::hdf5`` - ``hdf5::hdf5_hl_cpp`` - ``hdf5::hdf5_fortran`` - ``hdf5::hdf5_hl`` - ``hdf5::hdf5_hl_cpp`` - ``hdf5::hdf5_hl_fortran`` - ``hdf5::h5diff`` +``HDF5::HDF5`` + All detected ``HDF5_LIBRARIES``. +``hdf5::hdf5`` + C library. +``hdf5::hdf5_cpp`` + C++ library. +``hdf5::hdf5_fortran`` + Fortran library. +``hdf5::hdf5_hl`` + High-level C library. +``hdf5::hdf5_hl_cpp`` + High-level C++ library. +``hdf5::hdf5_hl_fortran`` + High-level Fortran library. +``hdf5::h5diff`` + ``h5diff`` executable. Hints ^^^^^ @@ -1147,6 +1154,21 @@ if (HDF5_FIND_DEBUG) message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") endforeach() + message(STATUS "Defined targets (if any):") + foreach(_lang IN ITEMS "" "_cpp" "_fortran") + foreach(_hl IN ITEMS "" "_hl") + foreach(_prefix IN ITEMS "hdf5::" "") + foreach(_suffix IN ITEMS "-static" "-shared" "") + set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix}) + if (TARGET ${_target}) + message(STATUS "... ${_target}") + else() + #message(STATUS "... ${_target} does not exist") + endif() + endforeach() + endforeach() + endforeach() + endforeach() endif() unset(_lang) unset(_HDF5_NEED_TO_SEARCH) diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index 3f243de..add2486 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -58,7 +58,7 @@ Obsolete variables find_path(JPEG_INCLUDE_DIR jpeglib.h) -set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static) +set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static turbojpeg turbojpeg-static) foreach(name ${jpeg_names}) list(APPEND jpeg_names_debug "${name}d") endforeach() diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake index cd50d8c..911210f 100644 --- a/Modules/FindPostgreSQL.cmake +++ b/Modules/FindPostgreSQL.cmake @@ -247,7 +247,7 @@ endif() # Did we find anything? include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(PostgreSQL - REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR + REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR VERSION_VAR PostgreSQL_VERSION_STRING) set(PostgreSQL_FOUND ${POSTGRESQL_FOUND}) @@ -271,16 +271,19 @@ endfunction() # Now try to get the include and library path. if(PostgreSQL_FOUND) + set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR}) + if(PostgreSQL_TYPE_INCLUDE_DIR) + list(APPEND PostgreSQL_INCLUDE_DIRS ${PostgreSQL_TYPE_INCLUDE_DIR}) + endif() + set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} ) if (NOT TARGET PostgreSQL::PostgreSQL) add_library(PostgreSQL::PostgreSQL UNKNOWN IMPORTED) set_target_properties(PostgreSQL::PostgreSQL PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIR};${PostgreSQL_TYPE_INCLUDE_DIR}") + INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIRS}") __postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "") __postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "RELEASE") __postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "DEBUG") endif () - set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} ) - set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} ) endif() mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 3d136ad..d439eeb 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 19) -set(CMake_VERSION_PATCH 20210108) +set(CMake_VERSION_PATCH 20210113) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index d8f89d6..0c263bb 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -213,6 +213,7 @@ else() qt_wrap_cpp(MOC_BUILT_SRCS ${MOC_SRCS}) qt_add_resources(QRC_BUILT_SRCS ${QRC_SRCS}) endif() +add_library(CMakeGUIQRCLib OBJECT ${QRC_BUILT_SRCS}) if (FALSE) # CMake's bootstrap binary does not support automoc set(CMAKE_AUTOMOC 1) @@ -221,8 +222,7 @@ if (FALSE) # CMake's bootstrap binary does not support automoc else () list(APPEND SRCS ${UI_BUILT_SRCS} - ${MOC_BUILT_SRCS} - ${QRC_BUILT_SRCS}) + ${MOC_BUILT_SRCS}) endif () if(USE_LGPL) @@ -246,6 +246,7 @@ target_link_libraries(CMakeGUIMainLib PUBLIC CMakeGUILib) add_executable(cmake-gui WIN32 MACOSX_BUNDLE CMakeGUIExec.cxx ${MANIFEST_FILE}) target_link_libraries(cmake-gui CMakeGUIMainLib Qt${INSTALLED_QT_VERSION}::Core) +target_sources(CMakeGUIMainLib INTERFACE $<TARGET_OBJECTS:CMakeGUIQRCLib>) if(WIN32) target_sources(CMakeGUIMainLib INTERFACE $<TARGET_OBJECTS:CMakeVersion> CMakeSetup.rc) endif() diff --git a/Source/cmGccDepfileReader.cxx b/Source/cmGccDepfileReader.cxx index 96a562e..8253375 100644 --- a/Source/cmGccDepfileReader.cxx +++ b/Source/cmGccDepfileReader.cxx @@ -12,40 +12,33 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath) -{ - cmGccDepfileLexerHelper helper; - if (helper.readFile(filePath)) { - return cm::make_optional(std::move(helper).extractContent()); - } - return cm::nullopt; -} - cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath, const std::string& prefix) { - auto deps = cmReadGccDepfile(filePath); - - if (prefix.empty() || !deps) { - return deps; + cmGccDepfileLexerHelper helper; + if (!helper.readFile(filePath)) { + return cm::nullopt; } + auto deps = cm::make_optional(std::move(helper).extractContent()); for (auto& dep : *deps) { for (auto& rule : dep.rules) { - if (!cmSystemTools::FileIsFullPath(rule)) { + if (!prefix.empty() && !cmSystemTools::FileIsFullPath(rule)) { rule = cmStrCat(prefix, rule); } if (cmSystemTools::FileIsFullPath(rule)) { rule = cmSystemTools::CollapseFullPath(rule); } + cmSystemTools::ConvertToLongPath(rule); } for (auto& path : dep.paths) { - if (!cmSystemTools::FileIsFullPath(path)) { + if (!prefix.empty() && !cmSystemTools::FileIsFullPath(path)) { path = cmStrCat(prefix, path); } if (cmSystemTools::FileIsFullPath(path)) { path = cmSystemTools::CollapseFullPath(path); } + cmSystemTools::ConvertToLongPath(path); } } diff --git a/Source/cmGccDepfileReader.h b/Source/cmGccDepfileReader.h index 66ff75d..c8a3748 100644 --- a/Source/cmGccDepfileReader.h +++ b/Source/cmGccDepfileReader.h @@ -8,10 +8,8 @@ #include "cmGccDepfileReaderTypes.h" -cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath); - /* * Read dependencies file and append prefix to all relative paths */ -cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath, - const std::string& prefix); +cm::optional<cmGccDepfileContent> cmReadGccDepfile( + const char* filePath, const std::string& prefix = {}); diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index c4bec23..36f583f 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -21,6 +21,8 @@ cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator(cmake* cm) this->PassMakeflags = true; this->UnixCD = false; this->MakeSilentFlag = "/nologo"; + // nmake breaks on '!' in long-line dependencies + this->ToolSupportsLongLineDependencies = false; } void cmGlobalNMakeMakefileGenerator::EnableLanguage( diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 5a747e5..7229101 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -693,13 +693,11 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( } } -namespace { -bool HasUniqueByproducts(cmLocalGenerator& lg, - std::vector<std::string> const& byproducts, - cmListFileBacktrace const& bt) +bool cmLocalNinjaGenerator::HasUniqueByproducts( + std::vector<std::string> const& byproducts, cmListFileBacktrace const& bt) { std::vector<std::string> configs = - lg.GetMakefile()->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + this->GetMakefile()->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); cmGeneratorExpression ge(bt); for (std::string const& p : byproducts) { if (cmGeneratorExpression::Find(p) == std::string::npos) { @@ -709,7 +707,7 @@ bool HasUniqueByproducts(cmLocalGenerator& lg, std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(p); for (std::string const& config : configs) { for (std::string const& b : - lg.ExpandCustomCommandOutputPaths(*cge, config)) { + this->ExpandCustomCommandOutputPaths(*cge, config)) { if (!seen.insert(b).second) { return false; } @@ -719,6 +717,7 @@ bool HasUniqueByproducts(cmLocalGenerator& lg, return true; } +namespace { bool HasUniqueOutputs(std::vector<cmCustomCommandGenerator> const& ccgs) { std::set<std::string> allOutputs; @@ -746,7 +745,7 @@ std::string cmLocalNinjaGenerator::CreateUtilityOutput( // In Ninja Multi-Config, we can only produce cross-config utility // commands if all byproducts are per-config. if (!this->GetGlobalGenerator()->IsMultiConfig() || - !HasUniqueByproducts(*this, byproducts, bt)) { + !this->HasUniqueByproducts(byproducts, bt)) { return this->cmLocalGenerator::CreateUtilityOutput(targetName, byproducts, bt); } diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index 87d5e53..5b850f3 100644 --- a/Source/cmLocalNinjaGenerator.h +++ b/Source/cmLocalNinjaGenerator.h @@ -86,6 +86,9 @@ public: cmNinjaDeps& ninjaDeps, const std::string& config); + bool HasUniqueByproducts(std::vector<std::string> const& byproducts, + cmListFileBacktrace const& bt); + protected: std::string ConvertToIncludeReference( std::string const& path, diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e4c8e4b..cea20ad 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -303,7 +303,7 @@ void cmMakefile::PrintCommandTrace( args.reserve(lff.Arguments().size()); for (cmListFileArgument const& arg : lff.Arguments()) { - if (expand) { + if (expand && arg.Delim != cmListFileArgument::Bracket) { temp = arg.Value; this->ExpandVariablesInString(temp); args.push_back(temp); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index c33fabd..adf40b0 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -345,27 +345,51 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules() this->LocalGenerator->GetBinaryDirectory(), compilerDependFile)) << "\n\n"; - if (!cmSystemTools::FileExists(compilerDependFile)) { - // Write an empty dependency file. - cmGeneratedFileStream depFileStream( - compilerDependFile, false, - this->GlobalGenerator->GetMakefileEncoding()); - depFileStream << "# Empty compiler generated dependencies file for " - << this->GeneratorTarget->GetName() << ".\n" - << "# This may be replaced when dependencies are built.\n"; - } + // Write an empty dependency file. + cmGeneratedFileStream depFileStream( + compilerDependFile, false, this->GlobalGenerator->GetMakefileEncoding()); + depFileStream << "# Empty compiler generated dependencies file for " + << this->GeneratorTarget->GetName() << ".\n" + << "# This may be replaced when dependencies are built.\n"; + // remove internal dependency file + cmSystemTools::RemoveFile( + cmStrCat(this->TargetBuildDirectoryFull, "/compiler_depend.internal")); std::string compilerDependTimestamp = cmStrCat(this->TargetBuildDirectoryFull, "/compiler_depend.ts"); if (!cmSystemTools::FileExists(compilerDependTimestamp)) { // Write a dependency timestamp file. - cmGeneratedFileStream depFileStream( + cmGeneratedFileStream timestampFileStream( compilerDependTimestamp, false, this->GlobalGenerator->GetMakefileEncoding()); - depFileStream << "# CMAKE generated file: DO NOT EDIT!\n" - << "# Timestamp file for compiler generated dependencies " - "management for " - << this->GeneratorTarget->GetName() << ".\n"; + timestampFileStream + << "# CMAKE generated file: DO NOT EDIT!\n" + << "# Timestamp file for compiler generated dependencies " + "management for " + << this->GeneratorTarget->GetName() << ".\n"; + } + + // deactivate no longer needed legacy dependency files + // Write an empty dependency file. + cmGeneratedFileStream legacyDepFileStream( + dependFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding()); + legacyDepFileStream + << "# Empty dependencies file for " << this->GeneratorTarget->GetName() + << ".\n" + << "# This may be replaced when dependencies are built.\n"; + // remove internal dependency file + cmSystemTools::RemoveFile( + cmStrCat(this->TargetBuildDirectoryFull, "/depend.internal")); + } else { + // make sure the depend file exists + if (!cmSystemTools::FileExists(dependFileNameFull)) { + // Write an empty dependency file. + cmGeneratedFileStream depFileStream( + dependFileNameFull, false, + this->GlobalGenerator->GetMakefileEncoding()); + depFileStream << "# Empty dependencies file for " + << this->GeneratorTarget->GetName() << ".\n" + << "# This may be replaced when dependencies are built.\n"; } } @@ -381,16 +405,6 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules() << "\n\n"; } - // make sure the depend file exists - if (!cmSystemTools::FileExists(dependFileNameFull)) { - // Write an empty dependency file. - cmGeneratedFileStream depFileStream( - dependFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding()); - depFileStream << "# Empty dependencies file for " - << this->GeneratorTarget->GetName() << ".\n" - << "# This may be replaced when dependencies are built.\n"; - } - // Open the flags file. This should be copy-if-different because the // rules may depend on this file itself. this->FlagFileNameFull = @@ -855,6 +869,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( shellDependencyFile = this->LocalGenerator->ConvertToOutputFormat( depFile, cmOutputConverter::SHELL); vars.DependencyFile = shellDependencyFile.c_str(); + this->CleanFiles.insert(depFile); dependencyTimestamp = this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetBinaryDirectory(), diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 620b8ff..49e5e4c 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -12,6 +12,7 @@ #include <utility> #include <cm/memory> +#include <cm/optional> #include <cm/vector> #include "cmComputeLinkInformation.h" @@ -1238,14 +1239,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( std::vector<std::string> preLinkCmdLines; std::vector<std::string> postBuildCmdLines; - if (config == fileConfig) { - std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines, - &preLinkCmdLines, - &postBuildCmdLines }; - - for (unsigned i = 0; i != 3; ++i) { - for (cmCustomCommand const& cc : *cmdLists[i]) { - cmCustomCommandGenerator ccg(cc, config, this->GetLocalGenerator()); + std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines, + &preLinkCmdLines, + &postBuildCmdLines }; + + for (unsigned i = 0; i != 3; ++i) { + for (cmCustomCommand const& cc : *cmdLists[i]) { + if (config == fileConfig || + this->GetLocalGenerator()->HasUniqueByproducts(cc.GetByproducts(), + cc.GetBacktrace())) { + cmCustomCommandGenerator ccg(cc, fileConfig, this->GetLocalGenerator(), + true, config); localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]); std::vector<std::string> const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 6a705f4..024356f 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1255,6 +1255,30 @@ void cmSystemTools::ConvertToOutputSlashes(std::string& path) #endif } +void cmSystemTools::ConvertToLongPath(std::string& path) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + // Try to convert path to a long path only if the path contains character '~' + if (path.find('~') == std::string::npos) { + return; + } + + std::wstring wPath = cmsys::Encoding::ToWide(path); + DWORD ret = GetLongPathNameW(wPath.c_str(), nullptr, 0); + std::vector<wchar_t> buffer(ret); + if (ret != 0) { + ret = GetLongPathNameW(wPath.c_str(), buffer.data(), + static_cast<DWORD>(buffer.size())); + } + + if (ret != 0) { + path = cmsys::Encoding::ToNarrow(buffer.data()); + } +#else + static_cast<void>(path); +#endif +} + std::string cmSystemTools::ConvertToRunCommandPath(const std::string& path) { #if defined(_WIN32) && !defined(__CYGWIN__) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 1100f05..5bbbb0c 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -287,6 +287,12 @@ public: // running cmake needs paths to be in its format static std::string ConvertToRunCommandPath(const std::string& path); + /** + * For windows computes the long path for the given path, + * For Unix, it is a noop + */ + static void ConvertToLongPath(std::string& path); + /** compute the relative path from local to remote. local must be a directory. remote can be a file or a directory. Both remote and local must be full paths. Basically, if diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 4c0fbeb..851205e 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -231,11 +231,10 @@ private: bool ProcessLine() override { if (cmHasPrefix(this->Line, this->IncludePrefix)) { - this->DepFile << cmCMakePath( - cmTrimWhitespace(this->Line.c_str() + - this->IncludePrefix.size())) - .GenericString() - << std::endl; + auto path = + cmTrimWhitespace(this->Line.c_str() + this->IncludePrefix.size()); + cmSystemTools::ConvertToLongPath(path); + this->DepFile << cmCMakePath(path).GenericString() << std::endl; } else { this->Output << this->Line << std::endl << std::flush; } diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt index d980a52..d4c19c7 100644 --- a/Tests/IncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/CMakeLists.txt @@ -67,13 +67,7 @@ else() endif() # Test escaping of special characters in include directory paths. -set(special_chars "~@&{}()'") -if(NOT (CMAKE_GENERATOR STREQUAL "NMake Makefiles" AND - "x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC" AND - "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 13.0)) - # NMake from VS 6 mistakes '!' in a path after a line continuation for a directive. - string(APPEND special_chars "!") -endif() +set(special_chars "~@&{}()!'") if(NOT CMAKE_GENERATOR MATCHES "(Unix|MinGW|MSYS) Makefiles") # when compiler is used for dependencies, special characters for make are not escaped string(APPEND special_chars "%") diff --git a/Tests/RunCMake/CommandLine/trace-expand.cmake b/Tests/RunCMake/CommandLine/trace-expand.cmake index e69de29..24da02a 100644 --- a/Tests/RunCMake/CommandLine/trace-expand.cmake +++ b/Tests/RunCMake/CommandLine/trace-expand.cmake @@ -0,0 +1 @@ +set(a [[\B]]) diff --git a/Tests/RunCMake/NinjaMultiConfig/PostBuild-debug-in-release-graph-build-stdout.txt b/Tests/RunCMake/NinjaMultiConfig/PostBuild-debug-in-release-graph-build-stdout.txt new file mode 100644 index 0000000..fad923a --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/PostBuild-debug-in-release-graph-build-stdout.txt @@ -0,0 +1,2 @@ +Running post-build command with Debug +Generating Debug\.txt diff --git a/Tests/RunCMake/NinjaMultiConfig/PostBuild-release-build-stdout.txt b/Tests/RunCMake/NinjaMultiConfig/PostBuild-release-build-stdout.txt new file mode 100644 index 0000000..485a52c --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/PostBuild-release-build-stdout.txt @@ -0,0 +1,3 @@ +Running post-build command with Release +Generating out\.txt with Release +Generating Release\.txt diff --git a/Tests/RunCMake/NinjaMultiConfig/PostBuild.cmake b/Tests/RunCMake/NinjaMultiConfig/PostBuild.cmake new file mode 100644 index 0000000..5fcff74 --- /dev/null +++ b/Tests/RunCMake/NinjaMultiConfig/PostBuild.cmake @@ -0,0 +1,6 @@ +enable_language(C) + +add_executable(Exe main.c) +add_custom_command(TARGET Exe POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Running post-build command with $<CONFIG>") +add_custom_command(TARGET Exe POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Generating out.txt with $<CONFIG>" BYPRODUCTS out.txt) +add_custom_command(TARGET Exe POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Generating $<CONFIG>.txt" BYPRODUCTS $<CONFIG>.txt) diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index dc2db57..480d628 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake @@ -187,6 +187,12 @@ run_ninja(SimpleCrossConfigs clean-all-in-release-graph build-Release.ninja clea run_cmake_build(SimpleCrossConfigs all-all-in-release-graph Release all:all) run_cmake_build(SimpleCrossConfigs all-relwithdebinfo-in-release-graph Release all:RelWithDebInfo) +set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/PostBuild-build) +set(RunCMake_TEST_OPTIONS "-DCMAKE_CROSS_CONFIGS=all") +run_cmake_configure(PostBuild) +run_cmake_build(PostBuild release Release Exe) +run_cmake_build(PostBuild debug-in-release-graph Release Exe:Debug) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Framework-build) set(RunCMake_TEST_OPTIONS "-DCMAKE_CROSS_CONFIGS=all") run_cmake_configure(Framework) |