diff options
313 files changed, 4612 insertions, 716 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ed57278..6dc9dcf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -783,6 +783,20 @@ test:windows-borland5.8: variables: CMAKE_CI_JOB_NIGHTLY: "true" +test:windows-msvc-v71-nmake: + extends: + - .windows_msvc_v71_nmake + - .cmake_test_windows_nmake + - .windows_builder_ext_tags + - .cmake_junit_artifacts + - .run_dependent + dependencies: + - test:windows-vs2019-x64-ninja + needs: + - test:windows-vs2019-x64-ninja + variables: + CMAKE_CI_JOB_NIGHTLY: "true" + test:windows-openwatcom1.9: extends: - .windows_openwatcom1.9 diff --git a/.gitlab/ci/configure_windows_msvc_common.cmake b/.gitlab/ci/configure_windows_msvc_common.cmake new file mode 100644 index 0000000..6d66a05 --- /dev/null +++ b/.gitlab/ci/configure_windows_msvc_common.cmake @@ -0,0 +1,2 @@ +set(configure_no_sccache 1) +include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake") diff --git a/.gitlab/ci/configure_windows_msvc_v71_nmake.cmake b/.gitlab/ci/configure_windows_msvc_v71_nmake.cmake new file mode 100644 index 0000000..166690a --- /dev/null +++ b/.gitlab/ci/configure_windows_msvc_v71_nmake.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_msvc_common.cmake") diff --git a/.gitlab/ci/msvc.ps1 b/.gitlab/ci/msvc.ps1 new file mode 100755 index 0000000..e8388a4 --- /dev/null +++ b/.gitlab/ci/msvc.ps1 @@ -0,0 +1,31 @@ +$erroractionpreference = "stop" + +if ("$env:CMAKE_CONFIGURATION".Contains("msvc_v71")) { + # MSVC v71 Toolset from Visual Studio 7 .NET 2003 + $filename = "msvc-v71-1" + $sha256sum = "01637CDC670EA5D631E169E286ACDD1913A124E3C5AF4C3DFB37657ADE8BBA9F" + $vcvars = "Vc7\bin\vcvars32.bat" +} else { + throw ('unknown CMAKE_CONFIGURATION: ' + "$env:CMAKE_CONFIGURATION") +} +$tarball = "$filename.zip" + +$outdir = $pwd.Path +$outdir = "$outdir\.gitlab" +$ProgressPreference = 'SilentlyContinue' +# This URL is only visible inside of Kitware's network. See above filename table. +Invoke-WebRequest -Uri "https://cmake.org/files/dependencies/internal/$tarball" -OutFile "$outdir\$tarball" +$hash = Get-FileHash "$outdir\$tarball" -Algorithm SHA256 +if ($hash.Hash -ne $sha256sum) { + exit 1 +} + +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory("$outdir\$tarball", "$outdir") +Move-Item -Path "$outdir\$filename" -Destination "$outdir\msvc" + +$bat = Get-Content -path "$outdir\msvc\$vcvars.in" -Raw +$bat = $bat -replace "@VS_ROOT@","$outdir\msvc" +$bat | Set-Content -path "$outdir\msvc\$vcvars" + +Set-Item -Force -Path "env:VCVARSALL" -Value "$outdir\msvc\$vcvars" diff --git a/.gitlab/os-windows.yml b/.gitlab/os-windows.yml index 15d883d..7e12496 100644 --- a/.gitlab/os-windows.yml +++ b/.gitlab/os-windows.yml @@ -72,6 +72,20 @@ variables: CMAKE_CONFIGURATION: windows_borland5.8 +.windows_nmake: + extends: .windows + + variables: + CMAKE_GENERATOR: "NMake Makefiles" + CMAKE_CI_BUILD_TYPE: Release + CMAKE_CI_NIGHTLY_IGNORE_DEPS: "true" + +.windows_msvc_v71_nmake: + extends: .windows_nmake + + variables: + CMAKE_CONFIGURATION: windows_msvc_v71_nmake + .windows_openwatcom: extends: .windows @@ -171,6 +185,16 @@ interruptible: true +.cmake_test_windows_nmake: + stage: test-ext + + script: + - Invoke-Expression -Command .gitlab/ci/msvc.ps1 + - Invoke-Expression -Command .gitlab/ci/vcvarsall.ps1 + - build/install/bin/ctest --output-on-failure -V -S .gitlab/ci/ctest_test_external.cmake + + interruptible: true + .cmake_test_windows_openwatcom: stage: test-ext @@ -181,6 +205,7 @@ - Set-Item -Force -Path "env:INCLUDE" -Value "$pwdpath\.gitlab\watcom\h;$pwdpath\.gitlab\watcom\h\nt" - Set-Item -Force -Path "env:EDPATH" -Value "$pwdpath\.gitlab\watcom\eddat" - Set-Item -Force -Path "env:WATCOM" -Value "$pwdpath\.gitlab\watcom" + - Set-Item -Force -Path "env:WLINKTMP" -Value "." - build/install/bin/ctest --output-on-failure -V -S .gitlab/ci/ctest_test_external.cmake interruptible: true diff --git a/.gitlab/rules.yml b/.gitlab/rules.yml index 4846fea..a871b8f 100644 --- a/.gitlab/rules.yml +++ b/.gitlab/rules.yml @@ -15,9 +15,10 @@ when: never - if: '$CI_MERGE_REQUEST_ID' when: manual + - if: '$CI_PROJECT_PATH == "cmake/cmake" && $CI_PIPELINE_SOURCE == "schedule"' + when: on_success - if: '$CI_PROJECT_PATH == "cmake/cmake"' - when: delayed - start_in: 5 minutes + when: manual - when: never .run_automatically: @@ -34,6 +35,8 @@ when: never - if: '$CI_MERGE_REQUEST_ID' when: on_success + - if: '$CI_PROJECT_PATH == "cmake/cmake" && $CI_PIPELINE_SOURCE == "schedule"' + when: on_success - if: '$CI_PROJECT_PATH == "cmake/cmake"' when: delayed start_in: 5 minutes diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e63f44..1fe847f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,11 @@ cmake_minimum_required(VERSION 3.1...3.21 FATAL_ERROR) set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideC.cmake) set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideCXX.cmake) + +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) # CMake 3.23 +endif() + project(CMake) unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX) unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C) diff --git a/Help/command/configure_file.rst b/Help/command/configure_file.rst index 086668c..1d81423 100644 --- a/Help/command/configure_file.rst +++ b/Help/command/configure_file.rst @@ -96,6 +96,7 @@ The arguments are: with respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`. If the path names an existing directory the output file is placed in that directory with the same file name as the input file. + If the path contains non-existent directories, they are created. ``NO_SOURCE_PERMISSIONS`` .. versionadded:: 3.19 diff --git a/Help/command/install.rst b/Help/command/install.rst index 1236f1d..abde6e0 100644 --- a/Help/command/install.rst +++ b/Help/command/install.rst @@ -132,7 +132,7 @@ Installing Targets install(TARGETS targets... [EXPORT <export-name>] [RUNTIME_DEPENDENCIES args...|RUNTIME_DEPENDENCY_SET <set-name>] [[ARCHIVE|LIBRARY|RUNTIME|OBJECTS|FRAMEWORK|BUNDLE| - PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE] + PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE|FILE_SET <set-name>] [DESTINATION <dir>] [PERMISSIONS permissions...] [CONFIGURATIONS [Debug|Release|...]] @@ -204,6 +204,13 @@ that may be installed: Similar to ``PUBLIC_HEADER`` and ``PRIVATE_HEADER``, but for ``RESOURCE`` files. See :prop_tgt:`RESOURCE` for details. +``FILE_SET <set>`` + If the file set ``<set>`` exists and is ``PUBLIC`` or ``INTERFACE``, any + files added to the file set ``<set>`` created by + :command:`target_sources(FILE_SET)` are installed in the specified + destination, preserving their directory structure relative to the file set's + base directories. + For each of these arguments given, the arguments following them only apply to the target or file type specified in the argument. If none is given, the installation properties apply to all target types. If only one is given then @@ -225,15 +232,16 @@ end of this section). The following table shows the target types with their associated variables and built-in defaults that apply when no destination is given: -================== =============================== ====================== - Target Type GNUInstallDirs Variable Built-In Default -================== =============================== ====================== -``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin`` -``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib`` -``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib`` -``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include`` -``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include`` -================== =============================== ====================== +=============================== =============================== ====================== + Target Type GNUInstallDirs Variable Built-In Default +=============================== =============================== ====================== +``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin`` +``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib`` +``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib`` +``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include`` +``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include`` +``FILE_SET`` (type ``HEADERS``) ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include`` +=============================== =============================== ====================== Projects wishing to follow the common practice of installing headers into a project-specific subdirectory will need to provide a destination rather than @@ -338,6 +346,11 @@ top level: See documentation of the :prop_tgt:`EXPORT_NAME` target property to change the name of the exported target. + If ``EXPORT`` is used and the targets include ``PUBLIC`` or ``INTERFACE`` + file sets, all of them must be specified with ``FILE_SET`` arguments. All + ``PUBLIC`` or ``INTERFACE`` file sets associated with a target are included + in the export. + ``INCLUDES DESTINATION`` This option specifies a list of directories which will be added to the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property of the diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst index 520614a..2fded5e 100644 --- a/Help/command/target_sources.rst +++ b/Help/command/target_sources.rst @@ -46,3 +46,105 @@ Arguments to ``target_sources`` may use "generator expressions" with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual for available expressions. See the :manual:`cmake-buildsystem(7)` manual for more on defining buildsystem properties. + +.. code-block:: cmake + + target_sources(<target> + <INTERFACE|PUBLIC|PRIVATE> [FILE_SET set1] [TYPE type1] [BASE_DIRS dirs1...] [FILES files1...] + [<INTERFACE|PUBLIC|PRIVATE> [FILE_SET set2] [TYPE type2] [BASE_DIRS dirs2...] [FILES files2...]) + +Adds a file set to a target, or adds files to an existing file set. Targets +have zero or more named file sets. Each file set has a name, a type, a scope of +``INTERFACE``, ``PUBLIC``, or ``PRIVATE``, one or more base directories, and +files within those directories. The only acceptable type is ``HEADERS``. The +optional default file sets are named after their type. + +Files in a ``PRIVATE`` or ``PUBLIC`` file set are marked as source files for +the purposes of IDE integration. Additionally, files in ``HEADERS`` file sets +have their :prop_sf:`HEADER_FILE_ONLY` property set to ``TRUE``. Files in an +``INTERFACE`` or ``PUBLIC`` file set can be installed with the +:command:`install(TARGETS)` command, and exported with the +:command:`install(EXPORT)` and :command:`export` commands. + +Each ``target_sources(FILE_SET)`` entry starts with ``INTERFACE``, ``PUBLIC``, or +``PRIVATE`` and accepts the following arguments: + +``FILE_SET <set>`` + + A string representing the name of the file set to create or add to. This must + not start with a capital letter, unless its name is ``HEADERS``. + +``TYPE <type>`` + + A string representing the type of the file set. The only acceptable value is + ``HEADERS``. This may be omitted if the name of the file set is ``HEADERS``. + +``BASE_DIRS <dirs>`` + + An optional list of strings representing the base directories of the file + set. This argument supports + :manual:`generator expressions <cmake-generator-expressions(7)>`. No two + ``BASE_DIRS`` may be sub-directories of each other. If no ``BASE_DIRS`` are + specified when the file set is first created, the value of + :variable:`CMAKE_CURRENT_SOURCE_DIR` is added. + +``FILES <files>`` + + An optional list of strings representing files in the file set. Each file + must be in one of the ``BASE_DIRS``. This argument supports + :manual:`generator expressions <cmake-generator-expressions(7)>`. If relative + paths are specified, they are considered relative to + :variable:`CMAKE_CURRENT_SOURCE_DIR` at the time ``target_sources()`` is + called, unless they start with ``$<``, in which case they are computed + relative to the target's source directory after genex evaluation. + +The following target properties are set by ``target_sources(FILE_SET)``: + +:prop_tgt:`HEADER_SETS` + + List of ``PRIVATE`` and ``PUBLIC`` header sets associated with a target. + Headers listed in these header sets are treated as source files for the + purposes of IDE integration, and have their :prop_sf:`HEADER_FILE_ONLY` + property set to ``TRUE``. + +:prop_tgt:`INTERFACE_HEADER_SETS` + + List of ``INTERFACE`` and ``PUBLIC`` header sets associated with a target. + Headers listed in these header sets can be installed with + :command:`install(TARGETS)` and exported with :command:`install(EXPORT)` and + :command:`export`. + +:prop_tgt:`HEADER_SET` + + Headers in the default header set associated with a target. This property + supports :manual:`generator expressions <cmake-generator-expressions(7)>`. + +:prop_tgt:`HEADER_SET_<NAME>` + + Headers in the named header set ``<NAME>`` associated with a target. This + property supports + :manual:`generator expressions <cmake-generator-expressions(7)>`. + +:prop_tgt:`HEADER_DIRS` + + Base directories of the default header set associated with a target. This + property supports + :manual:`generator expressions <cmake-generator-expressions(7)>`. + +:prop_tgt:`HEADER_DIRS_<NAME>` + + Base directories of the header set ``<NAME>`` associated with a target. This + property supports + :manual:`generator expressions <cmake-generator-expressions(7)>`. + +:prop_tgt:`INCLUDE_DIRECTORIES` + + If the ``TYPE`` is ``HEADERS``, and the scope of the file set is ``PRIVATE`` + or ``PUBLIC``, all of the ``BASE_DIRS`` of the file set are wrapped in + :genex:`$<BUILD_INTERFACE>` and appended to this property. + +:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` + + If the ``TYPE`` is ``HEADERS``, and the scope of the file set is + ``INTERFACE`` or ``PUBLIC``, all of the ``BASE_DIRS`` of the file set are + wrapped in :genex:`$<BUILD_INTERFACE>` and appended to this property. diff --git a/Help/cpack_gen/ifw.rst b/Help/cpack_gen/ifw.rst index 6b8bc26..8bfcd98 100644 --- a/Help/cpack_gen/ifw.rst +++ b/Help/cpack_gen/ifw.rst @@ -292,6 +292,46 @@ Package This feature is available for QtIFW 4.0.0 and newer. +.. variable:: CPACK_IFW_ARCHIVE_FORMAT + + .. versionadded:: 3.23 + + Set the format used when packaging new component data archives. If you omit + this option, the ``7z`` format will be used as a default. Supported formats: + + * 7z + * zip + * tar.gz + * tar.bz2 + * tar.xz + + .. note:: + + If the Qt Installer Framework tools were built without libarchive support, + only ``7z`` format is supported. + + This feature is available for QtIFW 4.2.0 and newer. + +.. variable:: CPACK_IFW_ARCHIVE_COMPRESSION + + .. versionadded:: 3.23 + + Archive compression level. Defaults to 5 (*Normal compression*). + + * 0 (*No compression*) + * 1 (*Fastest compressing*) + * 3 (*Fast compressing*) + * 5 (*Normal compressing*) + * 7 (*Maximum compressing*) + * 9 (*Ultra compressing*) + + .. note:: + + Some formats do not support all the possible values. For example ``zip`` + compression only supports values from 1 to 7. + + This feature is available for QtIFW 4.2.0 and newer. + Components """""""""" diff --git a/Help/cpack_gen/rpm.rst b/Help/cpack_gen/rpm.rst index 823594a..0d287fc 100644 --- a/Help/cpack_gen/rpm.rst +++ b/Help/cpack_gen/rpm.rst @@ -1027,7 +1027,7 @@ Source RPM packaging has its own set of variables: * Mandatory : YES * Default : "/" -.. VARIABLE:: CPACK_RPM_BUILDREQUIRES +.. variable:: CPACK_RPM_BUILDREQUIRES List of source rpm build dependencies. @@ -1040,7 +1040,9 @@ Source RPM packaging has its own set of variables: set(CPACK_RPM_BUILDREQUIRES "python >= 2.5.0, cmake >= 2.8") -.. VARIABLE:: CPACK_RPM_REQUIRES_EXCLUDE_FROM +.. variable:: CPACK_RPM_REQUIRES_EXCLUDE_FROM + + .. versionadded:: 3.22 * Mandatory : NO * Default : - diff --git a/Help/dev/documentation.rst b/Help/dev/documentation.rst index 29fc880..4a2a5d9 100644 --- a/Help/dev/documentation.rst +++ b/Help/dev/documentation.rst @@ -92,6 +92,11 @@ literal block after ``::`` the referenced documents inline as part of the referencing document. +``versionadded``, ``versionchanged`` directives + Specify that something was added or changed by a named CMake version. + The command-line help processor prints the block content as if the lines + were normal paragraph text with interpretation. + Inline markup constructs not listed above are printed literally in the command-line help output. We prefer to use inline markup constructs that look correct in source form, so avoid use of \\-escapes in favor of inline diff --git a/Help/generator/Visual Studio 15 2017.rst b/Help/generator/Visual Studio 15 2017.rst index a4f5f98..912afad 100644 --- a/Help/generator/Visual Studio 15 2017.rst +++ b/Help/generator/Visual Studio 15 2017.rst @@ -15,20 +15,10 @@ Powershell, Python, etc.) are not supported. Instance Selection ^^^^^^^^^^^^^^^^^^ -.. versionadded:: 3.9 - VS 2017 supports multiple installations on the same machine. - The :variable:`CMAKE_GENERATOR_INSTANCE` variable may be set as a - cache entry containing the absolute path to a Visual Studio instance. - If the value is not specified explicitly by the user or a toolchain file, - CMake queries the Visual Studio Installer to locate VS instances, chooses - one, and sets the variable as a cache entry to hold the value persistently. - .. versionadded:: 3.11 - When CMake first chooses an instance, if the ``VS150COMNTOOLS`` environment - variable is set and points to the ``Common7/Tools`` directory within - one of the instances, that instance will be used. Otherwise, if more - than one instance is installed we do not define which one is chosen - by default. + +VS 2017 supports multiple installations on the same machine. The +:variable:`CMAKE_GENERATOR_INSTANCE` variable may be used to select one. Platform Selection ^^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 16 2019.rst b/Help/generator/Visual Studio 16 2019.rst index 72399e0..6cefe6d 100644 --- a/Help/generator/Visual Studio 16 2019.rst +++ b/Help/generator/Visual Studio 16 2019.rst @@ -15,18 +15,8 @@ Powershell, Python, etc.) are not supported. Instance Selection ^^^^^^^^^^^^^^^^^^ -VS 2019 supports multiple installations on the same machine. -The :variable:`CMAKE_GENERATOR_INSTANCE` variable may be set as a -cache entry containing the absolute path to a Visual Studio instance. -If the value is not specified explicitly by the user or a toolchain file, -CMake queries the Visual Studio Installer to locate VS instances, chooses -one, and sets the variable as a cache entry to hold the value persistently. - -When CMake first chooses an instance, if the ``VS160COMNTOOLS`` environment -variable is set and points to the ``Common7/Tools`` directory within -one of the instances, that instance will be used. Otherwise, if more -than one instance is installed we do not define which one is chosen -by default. +VS 2019 supports multiple installations on the same machine. The +:variable:`CMAKE_GENERATOR_INSTANCE` variable may be used to select one. Platform Selection ^^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 17 2022.rst b/Help/generator/Visual Studio 17 2022.rst index eeff05e..edf9d60 100644 --- a/Help/generator/Visual Studio 17 2022.rst +++ b/Help/generator/Visual Studio 17 2022.rst @@ -5,11 +5,6 @@ Visual Studio 17 2022 Generates Visual Studio 17 (VS 2022) project files. -.. warning:: - - This is experimental and based on "Visual Studio 2022 Release Candidate". - As of this version of CMake, VS 2022 has not been released. - Project Types ^^^^^^^^^^^^^ @@ -20,18 +15,8 @@ Powershell, Python, etc.) are not supported. Instance Selection ^^^^^^^^^^^^^^^^^^ -VS 2022 supports multiple installations on the same machine. -The :variable:`CMAKE_GENERATOR_INSTANCE` variable may be set as a -cache entry containing the absolute path to a Visual Studio instance. -If the value is not specified explicitly by the user or a toolchain file, -CMake queries the Visual Studio Installer to locate VS instances, chooses -one, and sets the variable as a cache entry to hold the value persistently. - -When CMake first chooses an instance, if the ``VS170COMNTOOLS`` environment -variable is set and points to the ``Common7/Tools`` directory within -one of the instances, that instance will be used. Otherwise, if more -than one instance is installed we do not define which one is chosen -by default. +VS 2022 supports multiple installations on the same machine. The +:variable:`CMAKE_GENERATOR_INSTANCE` variable may be used to select one. Platform Selection ^^^^^^^^^^^^^^^^^^ @@ -51,8 +36,8 @@ name (architecture). For example: Toolset Selection ^^^^^^^^^^^^^^^^^ -The ``v143`` toolset that comes with VS 17 2022 Release Candidate is selected by -default. The :variable:`CMAKE_GENERATOR_TOOLSET` option may be set, perhaps +The ``v143`` toolset that comes with VS 17 2022 is selected by default. +The :variable:`CMAKE_GENERATOR_TOOLSET` option may be set, perhaps via the :manual:`cmake(1)` ``-T`` option, to specify another toolset. .. |VS_TOOLSET_HOST_ARCH_DEFAULT| replace:: diff --git a/Help/manual/cmake-file-api.7.rst b/Help/manual/cmake-file-api.7.rst index 5e22ea9..4b8ac65 100644 --- a/Help/manual/cmake-file-api.7.rst +++ b/Help/manual/cmake-file-api.7.rst @@ -425,7 +425,7 @@ Version 1 does not exist to avoid confusion with that from { "kind": "codemodel", - "version": { "major": 2, "minor": 2 }, + "version": { "major": 2, "minor": 4 }, "paths": { "source": "/path/to/top-level-source-dir", "build": "/path/to/top-level-build-dir" @@ -758,6 +758,15 @@ with members: ``destination`` member is populated. This type has additional members ``runtimeDependencySetName`` and ``runtimeDependencySetType``. + ``fileSet`` + An :command:`install(TARGETS)` call with ``FILE_SET``. + The ``destination`` and ``paths`` members are populated. + The ``isOptional`` member may exist. + This type has additional members ``fileSetName``, ``fileSetType``, + ``fileSetDirectories``, and ``fileSetTarget``. + + This type was added in codemodel version 2.4. + ``isExcludeFromAll`` Optional member that is present with boolean value ``true`` when :command:`install` is called with the ``EXCLUDE_FROM_ALL`` option. @@ -835,6 +844,41 @@ with members: Indicates that this installer installs dependencies that are macOS frameworks. + ``fileSetName`` + Optional member that is present when ``type`` is ``fileSet``. The value is + a string with the name of the file set. + + This field was added in codemodel version 2.4. + + ``fileSetType`` + Optional member that is present when ``type`` is ``fileSet``. The value is + a string with the type of the file set. + + This field was added in codemodel version 2.4. + + ``fileSetDirectories`` + Optional member that is present when ``type`` is ``fileSet``. The value + is a list of strings with the file set's base directories (determined by + genex-evaluation of :prop_tgt:`HEADER_DIRS` or + :prop_tgt:`HEADER_DIRS_<NAME>`). + + This field was added in codemodel version 2.4. + + ``fileSetTarget`` + Optional member that is present when ``type`` is ``fileSet``. The value + is a JSON object with members: + + ``id`` + A string uniquely identifying the target. This matches + the ``id`` member of the target in the main "codemodel" + object's ``targets`` array. + + ``index`` + An unsigned integer 0-based index into the main "codemodel" + object's ``targets`` array for the target. + + This field was added in codemodel version 2.4. + ``scriptFile`` Optional member that is present when ``type`` is ``script``. The value is a string specifying the path to the script file on disk, diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 3df4f9f..0939a82 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -51,6 +51,15 @@ The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used to determine whether to report an error on use of deprecated macros or functions. + +Policies Introduced by CMake 3.23 +================================= + +.. toctree:: + :maxdepth: 1 + + CMP0129: Compiler id for MCST LCC compilers is now LCC, not GNU. </policy/CMP0129> + Policies Introduced by CMake 3.22 ================================= diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 435b2c6..3d74a11 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -214,6 +214,11 @@ Properties on Targets /prop_tgt/GHS_NO_SOURCE_GROUP_FILE /prop_tgt/GNUtoMS /prop_tgt/HAS_CXX + /prop_tgt/HEADER_DIRS + /prop_tgt/HEADER_DIRS_NAME + /prop_tgt/HEADER_SET + /prop_tgt/HEADER_SET_NAME + /prop_tgt/HEADER_SETS /prop_tgt/HIP_ARCHITECTURES /prop_tgt/HIP_EXTENSIONS /prop_tgt/HIP_STANDARD @@ -255,6 +260,7 @@ Properties on Targets /prop_tgt/INTERFACE_COMPILE_DEFINITIONS /prop_tgt/INTERFACE_COMPILE_FEATURES /prop_tgt/INTERFACE_COMPILE_OPTIONS + /prop_tgt/INTERFACE_HEADER_SETS /prop_tgt/INTERFACE_INCLUDE_DIRECTORIES /prop_tgt/INTERFACE_LINK_DEPENDS /prop_tgt/INTERFACE_LINK_DIRECTORIES diff --git a/Help/policy/CMP0129.rst b/Help/policy/CMP0129.rst new file mode 100644 index 0000000..31a26e5 --- /dev/null +++ b/Help/policy/CMP0129.rst @@ -0,0 +1,34 @@ +CMP0129 +------- + +.. versionadded:: 3.23 + +Compiler id for MCST LCC compilers is now ``LCC``, not ``GNU``. + +CMake 3.23 and above recognize MCST LCC compiler as a different from ``GNU``, +with its own command line and set of capabilities. +CMake now prefers to present this to projects by setting the +:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``LCC`` instead +of ``GNU``. However, existing projects may assume the compiler id for +LCC is ``GNU`` as it was in CMake versions prior to 3.23. +Therefore this policy determines for MCST LCC compiler which +compiler id to report in the :variable:`CMAKE_<LANG>_COMPILER_ID` +variable after language ``<LANG>`` is enabled by the :command:`project` +or :command:`enable_language` command. The policy must be set prior +to the invocation of either command. + +The ``OLD`` behavior for this policy is to use compiler id ``GNU`` (and set +:variable:`CMAKE_<LANG>_COMPILER_VERSION` to the supported GNU compiler version.) +``NEW`` behavior for this policy is to use compiler id ``LCC``, and set +:variable:`CMAKE_<LANG>_SIMULATE_ID` to ``GNU``, and +:variable:`CMAKE_<LANG>_SIMULATE_VERSION` to the supported GNU compiler version. + +This policy was introduced in CMake version 3.23. Use the +:command:`cmake_policy` command to set this policy to ``OLD`` or ``NEW`` explicitly. +Unlike most policies, CMake version |release| does *not* warn +by default when this policy is not set and simply uses ``OLD`` behavior. +See documentation of the +:variable:`CMAKE_POLICY_WARNING_CMP0129 <CMAKE_POLICY_WARNING_CMP<NNNN>>` +variable to control the warning. + +.. include:: DEPRECATED.txt diff --git a/Help/prop_test/ENVIRONMENT_MODIFICATION.rst b/Help/prop_test/ENVIRONMENT_MODIFICATION.rst index 0031210..0b3cd83 100644 --- a/Help/prop_test/ENVIRONMENT_MODIFICATION.rst +++ b/Help/prop_test/ENVIRONMENT_MODIFICATION.rst @@ -8,8 +8,9 @@ that the operations performed by this property are performed after the :prop_test:`ENVIRONMENT` property is already applied. If set to a list of environment variables and values of the form -``MYVAR=OP:VALUE``. Entries are considered in the order specified in the -property's value. The ``OP`` may be one of: +``MYVAR=OP:VALUE``, where ``MYVAR`` is the case-sensitive name of an +environment variable to be modified. Entries are considered in the +order specified in the property's value. The ``OP`` may be one of: - ``reset``: Reset to the unmodified value, ignoring all modifications to ``MYVAR`` prior to this entry. Note that this will reset the variable to diff --git a/Help/prop_tgt/HEADER_DIRS.rst b/Help/prop_tgt/HEADER_DIRS.rst new file mode 100644 index 0000000..3495545 --- /dev/null +++ b/Help/prop_tgt/HEADER_DIRS.rst @@ -0,0 +1,6 @@ +HEADER_DIRS +----------- + +Semicolon-separated list of base directories of the default header set created +by :command:`target_sources(FILE_SET)`. This property supports +:manual:`generator expressions <cmake-generator-expressions(7)>`. diff --git a/Help/prop_tgt/HEADER_DIRS_NAME.rst b/Help/prop_tgt/HEADER_DIRS_NAME.rst new file mode 100644 index 0000000..c2bbd0a --- /dev/null +++ b/Help/prop_tgt/HEADER_DIRS_NAME.rst @@ -0,0 +1,6 @@ +HEADER_DIRS_<NAME> +------------------ + +Semicolon-separated list of base directories of the header set with name +``<NAME>`` created by :command:`target_sources(FILE_SET)`. This property +supports :manual:`generator expressions <cmake-generator-expressions(7)>`. diff --git a/Help/prop_tgt/HEADER_SET.rst b/Help/prop_tgt/HEADER_SET.rst new file mode 100644 index 0000000..2b8b0d4 --- /dev/null +++ b/Help/prop_tgt/HEADER_SET.rst @@ -0,0 +1,8 @@ +HEADER_SET +---------- + +Semicolon-separated list of headers in the default header set created by +:command:`target_sources(FILE_SET)`. This property supports +:manual:`generator expressions <cmake-generator-expressions(7)>`. If any of the +headers are relative paths, they are computed relative to the target's source +directory. diff --git a/Help/prop_tgt/HEADER_SETS.rst b/Help/prop_tgt/HEADER_SETS.rst new file mode 100644 index 0000000..ed7c528 --- /dev/null +++ b/Help/prop_tgt/HEADER_SETS.rst @@ -0,0 +1,6 @@ +HEADER_SETS +----------- + +List of ``PRIVATE`` and ``PUBLIC`` header sets added by +:command:`target_sources(FILE_SET)`. Headers listed in these header sets are +treated as source files for the purposes of IDE integration. diff --git a/Help/prop_tgt/HEADER_SET_NAME.rst b/Help/prop_tgt/HEADER_SET_NAME.rst new file mode 100644 index 0000000..25a5573 --- /dev/null +++ b/Help/prop_tgt/HEADER_SET_NAME.rst @@ -0,0 +1,8 @@ +HEADER_SET_<NAME> +----------------- + +Semicolon-separated list of headers in the named header set ``<NAME>`` created +by :command:`target_sources(FILE_SET)`. This property supports +:manual:`generator expressions <cmake-generator-expressions(7)>`. If any of the +headers are relative paths, they are computed relative to the target's source +directory. diff --git a/Help/prop_tgt/INTERFACE_HEADER_SETS.rst b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst new file mode 100644 index 0000000..93ea9c5 --- /dev/null +++ b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst @@ -0,0 +1,7 @@ +INTERFACE_HEADER_SETS +--------------------- + +List of ``INTERFACE`` and ``PUBLIC`` header sets added by +:command:`target_sources(FILE_SET)`. Headers listed in these header sets can be +installed with :command:`install(TARGETS)` and exported with +:command:`install(EXPORT)` and :command:`export`. diff --git a/Help/release/3.21.rst b/Help/release/3.21.rst index 4b0d68c..e1c6172 100644 --- a/Help/release/3.21.rst +++ b/Help/release/3.21.rst @@ -26,9 +26,7 @@ Presets Generators ---------- -* The :generator:`Visual Studio 17 2022` generator was added. This is - experimental and based on "Visual Studio 2022 Release Candidate" because - this version of VS has not been released. +* The :generator:`Visual Studio 17 2022` generator was added. * The :ref:`Makefile Generators` and the :generator:`Ninja` generator learned to add linker launcher tools along with the linker for ``C``, @@ -329,3 +327,10 @@ Changes made since CMake 3.21.0 include the following. * ``hipcc`` may once again be used as a ``CXX`` compiler, and is treated as whatever compiler it selects underneath, as CMake 3.20 and below did. + +3.21.4 +------ + +* The :generator:`Visual Studio 17 2022` generator is now based on the + "Visual Studio 2022" release candidates. Previously it was based on + preview versions. diff --git a/Help/release/3.22.rst b/Help/release/3.22.rst index b65c0ea..fcb655d 100644 --- a/Help/release/3.22.rst +++ b/Help/release/3.22.rst @@ -142,7 +142,3 @@ Other Changes This became available as of VS 16.10 (toolchain version 14.29.30037). * The :cpack_gen:`CPack NSIS Generator` now requires NSIS 3.03 or later. - -* The :generator:`Visual Studio 17 2022` generator was updated. This is - experimental and based on "Visual Studio 2022 Release Candidate" because - this version of VS has not been released. diff --git a/Help/release/dev/FindVulkan-version.rst b/Help/release/dev/FindVulkan-version.rst new file mode 100644 index 0000000..4e9f121 --- /dev/null +++ b/Help/release/dev/FindVulkan-version.rst @@ -0,0 +1,5 @@ +FindVulkan-version +------------------ + +* The :module:`FindVulkan` module gained a ``Vulkan_VERSION`` result + variable reporting the version number. diff --git a/Help/release/dev/cpackifw-archive-format.rst b/Help/release/dev/cpackifw-archive-format.rst new file mode 100644 index 0000000..8884d74 --- /dev/null +++ b/Help/release/dev/cpackifw-archive-format.rst @@ -0,0 +1,9 @@ + +cpackifw-archive-format +----------------------- + +* The :cpack_gen:`CPack IFW Generator` gained the new + :variable:`CPACK_IFW_ARCHIVE_FORMAT` and + :variable:`CPACK_IFW_ARCHIVE_COMPRESSION` variables for setting the format + used when packaging new component data archives, and choosing the compression + level used. These features are available for QtIFW 4.2 and newer. diff --git a/Help/release/dev/lcc-compiler.rst b/Help/release/dev/lcc-compiler.rst index 59deef8..719611d 100644 --- a/Help/release/dev/lcc-compiler.rst +++ b/Help/release/dev/lcc-compiler.rst @@ -2,3 +2,4 @@ lcc-compiler ------------ * The MCST LCC compiler is now supported with compiler id ``LCC``. + See policy :policy:`CMP0129`. diff --git a/Help/release/dev/target-sources-file-set.rst b/Help/release/dev/target-sources-file-set.rst new file mode 100644 index 0000000..bd28efa --- /dev/null +++ b/Help/release/dev/target-sources-file-set.rst @@ -0,0 +1,18 @@ +target-headers +-------------- + +* The :command:`target_sources` command gained a new ``FILE_SET`` mode, which + can be used to add headers as header-only source files of a target. +* New :prop_tgt:`HEADER_SETS` and :prop_tgt:`INTERFACE_HEADER_SETS` properties + were added, which list the header file sets associated with a target. +* New :prop_tgt:`HEADER_SET` and :prop_tgt:`HEADER_SET_<NAME>` properties were + added, which list the files in the associated header file set. +* New :prop_tgt:`HEADER_DIRS` and :prop_tgt:`HEADER_DIRS_<NAME>` properties + were added, which specify the base directories of the associated header file + set. +* The :command:`install(TARGETS)` command gained a new ``FILE_SET`` argument, + which can be used to install header file sets associated with a target. +* The :manual:`File API <cmake-file-api(7)>` ``codemodel-v2`` minor version has + been bumped to ``4``. +* The :manual:`File API <cmake-file-api(7)>` ``codemodel-v2`` ``directory`` + object gained a new installer type of ``fileSet``. diff --git a/Help/release/dev/vs-instance.rst b/Help/release/dev/vs-instance.rst new file mode 100644 index 0000000..0b9ff4b --- /dev/null +++ b/Help/release/dev/vs-instance.rst @@ -0,0 +1,6 @@ +vs-instance +----------- + +* The :ref:`Visual Studio Generators` for VS 2017 and above learned to + use portable instances of Visual Studio not known to the VS installer. + See the :variable:`CMAKE_GENERATOR_INSTANCE` variable. diff --git a/Help/variable/CMAKE_GENERATOR_INSTANCE.rst b/Help/variable/CMAKE_GENERATOR_INSTANCE.rst index 5858d7a..6a35f17 100644 --- a/Help/variable/CMAKE_GENERATOR_INSTANCE.rst +++ b/Help/variable/CMAKE_GENERATOR_INSTANCE.rst @@ -18,10 +18,43 @@ variable may initialize ``CMAKE_GENERATOR_INSTANCE`` as a cache entry. Once a given build tree has been initialized with a particular value for this variable, changing the value has undefined behavior. -Instance specification is supported only on specific generators: +Instance specification is supported only on specific generators. -* For the :generator:`Visual Studio 15 2017` generator (and above) - this specifies the absolute path to the VS installation directory - of the selected VS instance. +Visual Studio Instance Selection +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -See native build system documentation for allowed instance values. +:ref:`Visual Studio Generators` support instance specification for +Visual Studio 2017 and above. The ``CMAKE_GENERATOR_INSTANCE`` variable +may be set as a cache entry selecting an instance of Visual Studio +via one of the following forms: + +* ``location`` +* ``location[,key=value]*`` +* ``key=value[,key=value]*`` + +The ``location`` specifies the absolute path to the top-level directory +of the VS installation. + +The ``key=value`` pairs form a comma-separated list of options to +specify details of the instance selection. +Supported pairs are: + +``version=<major>.<minor>.<MMMDD>.<BBB>`` + .. versionadded:: 3.23 + + Specify the 4-component VS Build Version. + +.. versionadded:: 3.23 + + A portable VS instance may be specified that is not known to the + Visual Studio Installer tool. The ``location`` and ``version=`` + values must both be provided. + +If the value of ``CMAKE_GENERATOR_INSTANCE`` is not specified explicitly +by the user or a toolchain file, CMake queries the Visual Studio Installer +to locate VS instances, chooses one, and sets the variable as a cache entry +to hold the value persistently. If an environment variable of the form +``VS##0COMNTOOLS``, where ``##`` the Visual Studio major version number, +is set and points to the ``Common7/Tools`` directory within one of the +VS instances, that instance will be used. Otherwise, if more than one +VS instance is installed we do not define which one is chosen by default. diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst index 0231668..8c84f91 100644 --- a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst +++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst @@ -34,6 +34,8 @@ only for the policies that do not warn by default: policy :policy:`CMP0126`. * ``CMAKE_POLICY_WARNING_CMP0128`` controls the warning for policy :policy:`CMP0128`. +* ``CMAKE_POLICY_WARNING_CMP0129`` controls the warning for + policy :policy:`CMP0129`. This variable should not be set by a project in CMake code. Project developers running CMake may set this variable in their cache to diff --git a/Help/variable/CTEST_CUSTOM_TESTS_IGNORE.rst b/Help/variable/CTEST_CUSTOM_TESTS_IGNORE.rst index 57222ca..7b1a4b8 100644 --- a/Help/variable/CTEST_CUSTOM_TESTS_IGNORE.rst +++ b/Help/variable/CTEST_CUSTOM_TESTS_IGNORE.rst @@ -1,7 +1,7 @@ CTEST_CUSTOM_TESTS_IGNORE ------------------------- -A list of regular expressions to use to exclude tests during the +A list of test names to be excluded from the set of tests run by the :command:`ctest_test` command. .. include:: CTEST_CUSTOM_XXX.txt diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 6437be0..ca90032 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -150,6 +150,27 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endif() + # For LCC Fortran we need to explicitly query the version. + if(lang STREQUAL "Fortran" + AND CMAKE_${lang}_COMPILER_ID STREQUAL "LCC") + execute_process( + COMMAND "${CMAKE_${lang}_COMPILER}" + --version + OUTPUT_VARIABLE output ERROR_VARIABLE output + RESULT_VARIABLE result + TIMEOUT 10 + ) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Running the ${lang} compiler: \"${CMAKE_${lang}_COMPILER}\" --version\n" + "${output}\n" + ) + + if(output MATCHES [[\(GCC\) ([0-9]+\.[0-9]+(\.[0-9]+)?) compatible]]) + set(CMAKE_${lang}_SIMULATE_ID "GNU") + set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_MATCH_1}") + endif() + endif() + if (COMPILER_QNXNTO AND (CMAKE_${lang}_COMPILER_ID STREQUAL "GNU" OR CMAKE_${lang}_COMPILER_ID STREQUAL "LCC")) execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 05d244a..6033ef6 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -174,7 +174,10 @@ else() endif() list(PREPEND _CMAKE_AR_NAMES "llvm-ar") list(PREPEND _CMAKE_RANLIB_NAMES "llvm-ranlib") - list(PREPEND _CMAKE_STRIP_NAMES "llvm-strip") + if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}" VERSION_GREATER_EQUAL 11) + # llvm-strip versions prior to 11 require additional flags we do not yet add. + list(PREPEND _CMAKE_STRIP_NAMES "llvm-strip") + endif() list(PREPEND _CMAKE_NM_NAMES "llvm-nm") if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}" VERSION_GREATER_EQUAL 9) # llvm-objdump versions prior to 9 did not support everything we need. diff --git a/Modules/CMakeTestHIPCompiler.cmake b/Modules/CMakeTestHIPCompiler.cmake index 5acd806..ecbfa7f 100644 --- a/Modules/CMakeTestHIPCompiler.cmake +++ b/Modules/CMakeTestHIPCompiler.cmake @@ -10,7 +10,7 @@ if(CMAKE_HIP_COMPILER_FORCED) endif() set(__CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS}") -string(APPEND CMAKE_HIP_FLAGS "--cuda-host-only") +string(APPEND CMAKE_HIP_FLAGS " --cuda-host-only") include(CMakeTestCompilerCommon) diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake index 2e68770..85108db 100644 --- a/Modules/CPackIFW.cmake +++ b/Modules/CPackIFW.cmake @@ -439,6 +439,7 @@ set(_CPACK_IFW_PREFIXES "QtIFW-") set(_CPACK_IFW_VERSIONS + "4.2" "4.1" "4.0" "3.2" diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake index 48ee3c4..a7139af 100644 --- a/Modules/CheckSymbolExists.cmake +++ b/Modules/CheckSymbolExists.cmake @@ -67,14 +67,29 @@ cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE) if(CMAKE_C_COMPILER_LOADED) + __CHECK_SYMBOL_EXISTS_FILTER_FLAGS(C) __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) + __CHECK_SYMBOL_EXISTS_RESTORE_FLAGS(C) elseif(CMAKE_CXX_COMPILER_LOADED) + __CHECK_SYMBOL_EXISTS_FILTER_FLAGS(CXX) __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) + __CHECK_SYMBOL_EXISTS_RESTORE_FLAGS(CXX) else() message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled") endif() endmacro() +macro(__CHECK_SYMBOL_EXISTS_FILTER_FLAGS LANG) + set(__CMAKE_${LANG}_FLAGS_SAVED "${CMAKE_${LANG}_FLAGS}") + string(REGEX REPLACE "(^| )-Werror([= ][^ ]*)?( |$)" " " CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS}") + string(REGEX REPLACE "(^| )-pedantic-errors( |$)" " " CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS}") +endmacro() + +macro(__CHECK_SYMBOL_EXISTS_RESTORE_FLAGS LANG) + set(CMAKE_${LANG}_FLAGS "${__CMAKE_${LANG}_FLAGS_SAVED}") + unset(__CMAKE_${LANG}_FLAGS_SAVED) +endmacro() + macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE) if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}") set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") diff --git a/Modules/Compiler/LCC-C-DetermineCompiler.cmake b/Modules/Compiler/LCC-C-DetermineCompiler.cmake index 6c7a08f..2ce92fe 100644 --- a/Modules/Compiler/LCC-C-DetermineCompiler.cmake +++ b/Modules/Compiler/LCC-C-DetermineCompiler.cmake @@ -8,4 +8,12 @@ set(_compiler_id_version_compute " # endif # if defined(__LCC_MINOR__) # define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__LCC_MINOR__) +# endif +# if defined(__GNUC__) && defined(__GNUC_MINOR__) +# define @PREFIX@SIMULATE_ID \"GNU\" +# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(__GNUC__) +# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(__GNUC_MINOR__) +# if defined(__GNUC_PATCHLEVEL__) +# define @PREFIX@SIMULATE_VERSION_PATCH @MACRO_DEC@(__GNUC_PATCHLEVEL__) +# endif # endif") diff --git a/Modules/Compiler/LCC-CXX-DetermineCompiler.cmake b/Modules/Compiler/LCC-CXX-DetermineCompiler.cmake index 6c7a08f..2ce92fe 100644 --- a/Modules/Compiler/LCC-CXX-DetermineCompiler.cmake +++ b/Modules/Compiler/LCC-CXX-DetermineCompiler.cmake @@ -8,4 +8,12 @@ set(_compiler_id_version_compute " # endif # if defined(__LCC_MINOR__) # define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__LCC_MINOR__) +# endif +# if defined(__GNUC__) && defined(__GNUC_MINOR__) +# define @PREFIX@SIMULATE_ID \"GNU\" +# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(__GNUC__) +# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(__GNUC_MINOR__) +# if defined(__GNUC_PATCHLEVEL__) +# define @PREFIX@SIMULATE_VERSION_PATCH @MACRO_DEC@(__GNUC_PATCHLEVEL__) +# endif # endif") diff --git a/Modules/Compiler/MSVC-C.cmake b/Modules/Compiler/MSVC-C.cmake index 4ba1eea..a53df46 100644 --- a/Modules/Compiler/MSVC-C.cmake +++ b/Modules/Compiler/MSVC-C.cmake @@ -11,6 +11,22 @@ if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.27) set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std:c11") set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std:c11") + if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.28) + set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON) + set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON) + set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON) + set(CMAKE_C17_STANDARD_COMPILE_OPTION "-std:c17") + set(CMAKE_C17_EXTENSION_COMPILE_OPTION "-std:c17") + else() + # Special case for 19.27 (VS 16.7): C11 has partial support. + macro(cmake_record_c_compile_features) + _has_compiler_features_c(90) + _has_compiler_features_c(99) + list(APPEND CMAKE_C11_COMPILE_FEATURES c_std_11) + set(_result 0) # expected by cmake_determine_compile_features + endmacro() + endif() + __compiler_check_default_language_standard(C 19.27 99) else() # MSVC has no specific options to set C language standards, but set them as @@ -25,41 +41,35 @@ else() # There is no meaningful default for this set(CMAKE_C_STANDARD_DEFAULT "") + + # There are no C compiler modes so we hard-code the known compiler supported + # features. Override the default macro for this special case. Pretend that + # all language standards are available so that at least compilation + # can be attempted. + macro(cmake_record_c_compile_features) + list(APPEND CMAKE_C_COMPILE_FEATURES + c_std_90 + c_std_99 + c_std_11 + c_std_17 + c_std_23 + c_function_prototypes + ) + list(APPEND CMAKE_C90_COMPILE_FEATURES c_std_90 c_function_prototypes) + list(APPEND CMAKE_C99_COMPILE_FEATURES c_std_99) + list(APPEND CMAKE_C11_COMPILE_FEATURES c_std_11) + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0) + list(APPEND CMAKE_C_COMPILE_FEATURES c_variadic_macros) + list(APPEND CMAKE_C99_COMPILE_FEATURES c_variadic_macros) + endif() + set(_result 0) # expected by cmake_determine_compile_features + endmacro() endif() set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -TC) set(CMAKE_C_CLANG_TIDY_DRIVER_MODE "cl") set(CMAKE_C_INCLUDE_WHAT_YOU_USE_DRIVER_MODE "cl") -# There are no C compiler modes so we hard-code the known compiler supported -# features. Override the default macro for this special case. Pretend that -# all language standards are available so that at least compilation -# can be attempted. -macro(cmake_record_c_compile_features) - list(APPEND CMAKE_C_COMPILE_FEATURES - c_std_90 - c_std_99 - c_std_11 - c_function_prototypes - ) - list(APPEND CMAKE_C90_COMPILE_FEATURES c_std_90 c_function_prototypes) - list(APPEND CMAKE_C99_COMPILE_FEATURES c_std_99) - list(APPEND CMAKE_C11_COMPILE_FEATURES c_std_11) - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0) - list(APPEND CMAKE_C_COMPILE_FEATURES c_variadic_macros) - list(APPEND CMAKE_C99_COMPILE_FEATURES c_variadic_macros) - endif() - if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.27) - list(APPEND CMAKE_C_COMPILE_FEATURES c_restrict) - list(APPEND CMAKE_C99_COMPILE_FEATURES c_restrict) - endif() - if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.28) - list(APPEND CMAKE_C_COMPILE_FEATURES c_static_assert) - list(APPEND CMAKE_C11_COMPILE_FEATURES c_static_assert) - endif() - set(_result 0) # expected by cmake_determine_compile_features -endmacro() - # /JMC "Just My Code" is only supported by MSVC 19.05 onward. if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05) set(CMAKE_C_COMPILE_OPTIONS_JMC "-JMC") diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index 62412ae..c974d33 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -267,7 +267,7 @@ cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) # if IN_LIST include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/FindPkgConfig.cmake) +find_package(PkgConfig QUIET) # Generic compiler names set(_MPI_C_GENERIC_COMPILER_NAMES mpicc mpcc mpicc_r mpcc_r) @@ -1583,7 +1583,7 @@ foreach(LANG IN ITEMS C CXX Fortran) else() set(_MPI_PKG "") endif() - if(_MPI_PKG) + if(_MPI_PKG AND PKG_CONFIG_FOUND) pkg_check_modules("MPI_${LANG}_PKG" "${_MPI_PKG}") if("${MPI_${LANG}_PKG_FOUND}") set(MPI_${LANG}_COMPILE_OPTIONS ${MPI_${LANG}_PKG_CFLAGS} CACHE STRING "MPI ${LANG} compilation options" FORCE) diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 4f48e13..078e367 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -39,18 +39,29 @@ This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found: Result Variables ^^^^^^^^^^^^^^^^ -This module defines the following variables:: - - Vulkan_FOUND - "True" if Vulkan was found - Vulkan_INCLUDE_DIRS - include directories for Vulkan - Vulkan_LIBRARIES - link against this library to use Vulkan - -The module will also define three cache variables:: - - Vulkan_INCLUDE_DIR - the Vulkan include directory - Vulkan_LIBRARY - the path to the Vulkan library - Vulkan_GLSLC_EXECUTABLE - the path to the GLSL SPIR-V compiler - Vulkan_GLSLANG_VALIDATOR_EXECUTABLE - the path to the glslangValidator tool +This module defines the following variables: + +``Vulkan_FOUND`` + set to true if Vulkan was found +``Vulkan_INCLUDE_DIRS`` + include directories for Vulkan +``Vulkan_LIBRARIES`` + link against this library to use Vulkan +``Vulkan_VERSION`` + .. versionadded:: 3.23 + + value from ``vulkan/vulkan_core.h`` + +The module will also defines these cache variables: + +``Vulkan_INCLUDE_DIR`` + the Vulkan include directory +``Vulkan_LIBRARY`` + the path to the Vulkan library +``Vulkan_GLSLC_EXECUTABLE`` + the path to the GLSL SPIR-V compiler +``Vulkan_GLSLANG_VALIDATOR_EXECUTABLE`` + the path to the glslangValidator tool Hints ^^^^^ @@ -125,10 +136,28 @@ endif() set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR}) +# detect version e.g 1.2.189 +set(Vulkan_VERSION "") +if(Vulkan_INCLUDE_DIR) + set(VULKAN_CORE_H ${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h) + if(EXISTS ${VULKAN_CORE_H}) + file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION ") + string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion "${VulkanHeaderVersionLine}") + file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION_COMPLETE ") + # "#define VK_HEADER_VERSION_COMPLETE VK_MAKE_API_VERSION(0, 1, 2, VK_HEADER_VERSION)" + string(REGEX REPLACE ".*\\([0_9]+[, ]+([0-9]+)[, ]+([0-9]+)[, ].*\\)" + "\\1.\\2.${VulkanHeaderVersion}" Vulkan_VERSION "${VulkanHeaderVersionLine}") + endif() +endif() + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(Vulkan - DEFAULT_MSG - Vulkan_LIBRARY Vulkan_INCLUDE_DIR) + REQUIRED_VARS + Vulkan_LIBRARY + Vulkan_INCLUDE_DIR + VERSION_VAR + Vulkan_VERSION +) mark_as_advanced(Vulkan_INCLUDE_DIR Vulkan_LIBRARY Vulkan_GLSLC_EXECUTABLE Vulkan_GLSLANG_VALIDATOR_EXECUTABLE) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index c8498a9..c125378 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -261,6 +261,8 @@ set(SRCS cmFileLockResult.h cmFilePathChecksum.cxx cmFilePathChecksum.h + cmFileSet.cxx + cmFileSet.h cmFileTime.cxx cmFileTime.h cmFileTimeCache.cxx @@ -316,6 +318,8 @@ set(SRCS cmInstallExportGenerator.cxx cmInstalledFile.h cmInstalledFile.cxx + cmInstallFileSetGenerator.h + cmInstallFileSetGenerator.cxx cmInstallFilesGenerator.h cmInstallFilesGenerator.cxx cmInstallImportedRuntimeArtifactsGenerator.h diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index c39bea6..ac6e3c1 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 22) -set(CMake_VERSION_PATCH 20211021) +set(CMake_VERSION_PATCH 20211102) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/CPack/IFW/cmCPackIFWCommon.cxx b/Source/CPack/IFW/cmCPackIFWCommon.cxx index f6b8a8a..5d995c3 100644 --- a/Source/CPack/IFW/cmCPackIFWCommon.cxx +++ b/Source/CPack/IFW/cmCPackIFWCommon.cxx @@ -29,19 +29,18 @@ cmValue cmCPackIFWCommon::GetOption(const std::string& op) const bool cmCPackIFWCommon::IsOn(const std::string& op) const { - return this->Generator ? this->Generator->cmCPackGenerator::IsOn(op) : false; + return this->Generator && this->Generator->cmCPackGenerator::IsOn(op); } bool cmCPackIFWCommon::IsSetToOff(const std::string& op) const { - return this->Generator ? this->Generator->cmCPackGenerator::IsSetToOff(op) - : false; + return this->Generator && this->Generator->cmCPackGenerator::IsSetToOff(op); } bool cmCPackIFWCommon::IsSetToEmpty(const std::string& op) const { - return this->Generator ? this->Generator->cmCPackGenerator::IsSetToEmpty(op) - : false; + return this->Generator && + this->Generator->cmCPackGenerator::IsSetToEmpty(op); } bool cmCPackIFWCommon::IsVersionLess(const char* version) const diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index 9b33eec..f35d7e9 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -58,6 +58,17 @@ std::vector<std::string> cmCPackIFWGenerator::BuildRepogenCommand() ifwCmd.emplace_back(this->RepoGen); + if (!this->IsVersionLess("4.2")) { + if (!this->ArchiveFormat.empty()) { + ifwCmd.emplace_back("--archive-format"); + ifwCmd.emplace_back(this->ArchiveFormat); + } + if (!this->ArchiveCompression.empty()) { + ifwCmd.emplace_back("--compression"); + ifwCmd.emplace_back(this->ArchiveCompression); + } + } + if (this->IsVersionLess("2.0.0")) { ifwCmd.emplace_back("-c"); ifwCmd.emplace_back(this->toplevel + "/config/config.xml"); @@ -157,6 +168,17 @@ std::vector<std::string> cmCPackIFWGenerator::BuildBinaryCreatorCommmand() ifwCmd.emplace_back(this->BinCreator); + if (!this->IsVersionLess("4.2")) { + if (!this->ArchiveFormat.empty()) { + ifwCmd.emplace_back("--archive-format"); + ifwCmd.emplace_back(this->ArchiveFormat); + } + if (!this->ArchiveCompression.empty()) { + ifwCmd.emplace_back("--compression"); + ifwCmd.emplace_back(this->ArchiveCompression); + } + } + ifwCmd.emplace_back("-c"); ifwCmd.emplace_back(this->toplevel + "/config/config.xml"); @@ -354,6 +376,14 @@ int cmCPackIFWGenerator::InitializeInternal() cmExpandList(dirs, this->RepoDirsVector); } + // Archive format and compression level + if (cmValue af = this->GetOption("CPACK_IFW_ARCHIVE_FORMAT")) { + this->ArchiveFormat = *af; + } + if (cmValue ac = this->GetOption("CPACK_IFW_ARCHIVE_COMPRESSION")) { + this->ArchiveCompression = *ac; + } + // Installer this->Installer.Generator = this; this->Installer.ConfigureFromOptions(); diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h index 902ebaf..b853e18 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.h +++ b/Source/CPack/IFW/cmCPackIFWGenerator.h @@ -151,6 +151,8 @@ private: std::string FrameworkVersion; std::string ExecutableSuffix; std::string OutputExtension; + std::string ArchiveFormat; + std::string ArchiveCompression; bool OnlineOnly; bool ResolveDuplicateNames; diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index 1340fb5..6ad3755 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -107,7 +107,7 @@ int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os) cmCPackLogger(cmCPackLog::LOG_DEBUG, "Number of lines: " << counter << std::endl); char buffer[1024]; - sprintf(buffer, "%d", counter); + snprintf(buffer, sizeof(buffer), "%d", counter); cmSystemTools::ReplaceString(res, headerLengthTag, buffer); // Write in file diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index a353435..0fe4ff4 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -20,9 +20,9 @@ #include "cmSystemTools.h" #include "cmXMLParser.h" -extern "C" int cmBZRXMLParserUnknownEncodingHandler(void* /*unused*/, - const XML_Char* name, - XML_Encoding* info) +static int cmBZRXMLParserUnknownEncodingHandler(void* /*unused*/, + const XML_Char* name, + XML_Encoding* info) { static const int latin1[] = { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 57b1dda..1b2f769 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -49,9 +49,8 @@ public: } ~cmCTestRunProcess() { - if (!(this->PipeState == -1) && - !(this->PipeState == cmsysProcess_Pipe_None) && - !(this->PipeState == cmsysProcess_Pipe_Timeout)) { + if (this->PipeState != -1 && this->PipeState != cmsysProcess_Pipe_None && + this->PipeState != cmsysProcess_Pipe_Timeout) { this->WaitForExit(); } cmsysProcess_Delete(this->Process); @@ -148,7 +147,8 @@ bool cmCTestCoverageHandler::StartCoverageLogFile( cmGeneratedFileStream& covLogFile, int logFileCount) { char covLogFilename[1024]; - sprintf(covLogFilename, "CoverageLog-%d", logFileCount); + snprintf(covLogFilename, sizeof(covLogFilename), "CoverageLog-%d", + logFileCount); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Open file: " << covLogFilename << std::endl, this->Quiet); @@ -165,7 +165,8 @@ void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount) { char covLogFilename[1024]; - sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount); + snprintf(covLogFilename, sizeof(covLogFilename), "CoverageLog-%d.xml", + logFileCount); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Close file: " << covLogFilename << std::endl, this->Quiet); @@ -692,7 +693,7 @@ void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile* mf) # define fnc_prefix(s, t) cmHasPrefix(s, t) #endif -bool IsFileInDir(const std::string& infile, const std::string& indir) +static bool IsFileInDir(const std::string& infile, const std::string& indir) { std::string file = cmSystemTools::CollapseFullPath(infile); std::string dir = cmSystemTools::CollapseFullPath(indir); diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index d85edcc..da94754 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -582,16 +582,17 @@ private: time_t seconds = static_cast<time_t>(person.Time); struct tm* t = gmtime(&seconds); char dt[1024]; - sprintf(dt, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, - t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + snprintf(dt, sizeof(dt), "%04d-%02d-%02d %02d:%02d:%02d", + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, + t->tm_min, t->tm_sec); std::string out = dt; // Add the time-zone field "+zone" or "-zone". char tz[32]; if (person.TimeZone >= 0) { - sprintf(tz, " +%04ld", person.TimeZone); + snprintf(tz, sizeof(tz), " +%04ld", person.TimeZone); } else { - sprintf(tz, " -%04ld", -person.TimeZone); + snprintf(tz, sizeof(tz), " -%04ld", -person.TimeZone); } out += tz; return out; diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 20f0ed3..6cd3b09 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -229,7 +229,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED; char buf[1024]; - sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime().count()); + snprintf(buf, sizeof(buf), "%6.2f sec", + this->TestProcess->GetTotalTime().count()); outputStream << buf << "\n"; bool passedOrSkipped = passed || skipped; @@ -294,9 +295,10 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) ttime -= minutes; auto seconds = std::chrono::duration_cast<std::chrono::seconds>(ttime); char buffer[100]; - sprintf(buffer, "%02d:%02d:%02d", static_cast<unsigned>(hours.count()), - static_cast<unsigned>(minutes.count()), - static_cast<unsigned>(seconds.count())); + snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", + static_cast<unsigned>(hours.count()), + static_cast<unsigned>(minutes.count()), + static_cast<unsigned>(seconds.count())); *this->TestHandler->LogFile << "----------------------------------------------------------" << std::endl; @@ -782,6 +784,9 @@ bool cmCTestRunTest::ForkProcess( std::ostringstream envMeasurement; if (environment && !environment->empty()) { + // Environment modification works on the assumption that the environment is + // actually modified here. If another strategy is used, there will need to + // be updates below in `apply_diff`. cmSystemTools::AppendEnv(*environment); for (auto const& var : *environment) { envMeasurement << var << std::endl; @@ -800,13 +805,22 @@ bool cmCTestRunTest::ForkProcess( auto apply_diff = [&env_application](const std::string& name, std::function<void(std::string&)> const& apply) { - auto entry = env_application.find(name); + cm::optional<std::string> old_value = env_application[name]; std::string output; - if (entry != env_application.end() && entry->second) { - output = *entry->second; + if (old_value) { + output = *old_value; + } else { + // This only works because the environment is actually modified above + // (`AppendEnv`). If CTest ever just creates an environment block + // directly, that block will need to be queried for the subprocess' + // value instead. + const char* curval = cmSystemTools::GetEnv(name); + if (curval) { + output = curval; + } } apply(output); - entry->second = output; + env_application[name] = output; }; bool err_occurred = false; diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index f685f66..16c0a0e 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -48,8 +48,6 @@ # include <unistd.h> #endif -#define CTEST_INITIAL_CMAKE_OUTPUT_FILE_NAME "CTestInitialCMakeOutput.log" - cmCTestScriptHandler::cmCTestScriptHandler() = default; void cmCTestScriptHandler::Initialize() @@ -411,7 +409,7 @@ int cmCTestScriptHandler::ExtractVariables() char updateVar[40]; int i; for (i = 1; i < 10; ++i) { - sprintf(updateVar, "CTEST_EXTRA_UPDATES_%i", i); + snprintf(updateVar, sizeof(updateVar), "CTEST_EXTRA_UPDATES_%i", i); cmValue updateVal = this->Makefile->GetDefinition(updateVar); if (updateVal) { if (this->UpdateCmd.empty()) { diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 34088d2..02db0c6 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -623,7 +623,7 @@ void cmCTestTestHandler::LogTestSummary(const std::vector<std::string>& passed, this->PrintLabelOrSubprojectSummary(false); } char realBuf[1024]; - sprintf(realBuf, "%6.2f sec", durationInSecs.count()); + snprintf(realBuf, sizeof(realBuf), "%6.2f sec", durationInSecs.count()); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (real) = " << realBuf << "\n", this->Quiet); @@ -784,7 +784,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject) label.resize(maxlen + 3, ' '); char buf[1024]; - sprintf(buf, "%6.2f sec*proc", labelTimes[i]); + snprintf(buf, sizeof(buf), "%6.2f sec*proc", labelTimes[i]); std::ostringstream labelCountStr; labelCountStr << "(" << labelCounts[i] << " test"; diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index 423b506..9ba6456 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -123,8 +123,9 @@ std::string cmCTestVC::GetNightlyTime() this->CTest->GetCTestConfiguration("NightlyStartTime"), this->CTest->GetTomorrowTag()); char current_time[1024]; - sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, - t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + snprintf(current_time, sizeof(current_time), "%04d-%02d-%02d %02d:%02d:%02d", + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, + t->tm_sec); return std::string(current_time); } diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index 16bca01..e14a4e1 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -511,7 +511,7 @@ std::string cmProcess::GetExitExceptionString() const default: char buf[1024]; const char* fmt = "Exit code 0x%" KWIML_INT_PRIx64 "\n"; - _snprintf(buf, 1024, fmt, this->ExitValue); + snprintf(buf, sizeof(buf), fmt, this->ExitValue); exception_str.assign(buf); } #else diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index 1ba45e5..ae4c0f6 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -55,7 +55,7 @@ cmCursesForm* cmCursesForm::CurrentForm = nullptr; extern "C" { -void onsig(int /*unused*/) +static void onsig(int /*unused*/) { if (cmCursesForm::CurrentForm) { endwin(); diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx index 591c546..7f1815f 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -78,7 +78,8 @@ void cmCursesLongMessageForm::UpdateStatusBar() char version[cmCursesMainForm::MAX_WIDTH]; char vertmp[128]; - sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion()); + snprintf(vertmp, sizeof(vertmp), "CMake Version %s", + cmVersion::GetCMakeVersion()); size_t sideSpace = (width - strlen(vertmp)); for (size_t i = 0; i < sideSpace; i++) { version[i] = ' '; @@ -105,7 +106,7 @@ void cmCursesLongMessageForm::PrintKeys() return; } char firstLine[512]; - sprintf(firstLine, "Press [e] to exit screen"); + snprintf(firstLine, sizeof(firstLine), "Press [e] to exit screen"); char fmt_s[] = "%s"; curses_move(y - 2, 0); @@ -176,7 +177,8 @@ void cmCursesLongMessageForm::HandleInput() this->PrintKeys(); int key = getch(); - sprintf(debugMessage, "Message widget handling input, key: %d", key); + snprintf(debugMessage, sizeof(debugMessage), + "Message widget handling input, key: %d", key); cmCursesForm::LogMessage(debugMessage); // quit diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index b28c5b7..0012a25 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -322,22 +322,22 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) memset(thirdLine, ' ', 68); } else { if (this->OkToGenerate) { - sprintf(firstLine, - " [l] Show log output [c] Configure" - " [g] Generate "); + snprintf(firstLine, sizeof(firstLine), + " [l] Show log output [c] Configure" + " [g] Generate "); } else { - sprintf(firstLine, - " [l] Show log output [c] Configure" - " "); + snprintf(firstLine, sizeof(firstLine), + " [l] Show log output [c] Configure" + " "); } { const char* toggleKeyInstruction = " [t] Toggle advanced mode (currently %s)"; - sprintf(thirdLine, toggleKeyInstruction, - this->AdvancedMode ? "on" : "off"); + snprintf(thirdLine, sizeof(thirdLine), toggleKeyInstruction, + this->AdvancedMode ? "on" : "off"); } - sprintf(secondLine, - " [h] Help [q] Quit without generating"); + snprintf(secondLine, sizeof(secondLine), + " [h] Help [q] Quit without generating"); } curses_move(y - 4, 0); @@ -356,7 +356,8 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) if (cw) { char pageLine[512] = ""; - sprintf(pageLine, "Page %d of %d", cw->GetPage(), this->NumberOfPages); + snprintf(pageLine, sizeof(pageLine), "Page %d of %d", cw->GetPage(), + this->NumberOfPages); curses_move(0, 65 - static_cast<unsigned int>(strlen(pageLine)) - 1); printw(fmt_s, pageLine); } @@ -739,7 +740,8 @@ void cmCursesMainForm::HandleInput() if ((!currentWidget || !widgetHandled) && !this->SearchMode) { // If the current widget does not want to handle input, // we handle it. - sprintf(debugMessage, "Main form handling input, key: %d", key); + snprintf(debugMessage, sizeof(debugMessage), + "Main form handling input, key: %d", key); cmCursesForm::LogMessage(debugMessage); // quit if (key == 'q') { diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx index 4830d63..c0d06ce 100644 --- a/Source/CursesDialog/cmCursesStringWidget.cxx +++ b/Source/CursesDialog/cmCursesStringWidget.cxx @@ -85,7 +85,8 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, // <Enter> is used to change edit mode (like <Esc> in vi). while (!this->Done) { - sprintf(debugMessage, "String widget handling input, key: %d", key); + snprintf(debugMessage, sizeof(debugMessage), + "String widget handling input, key: %d", key); cmCursesForm::LogMessage(debugMessage); fm->PrintKeys(); diff --git a/Source/CursesDialog/form/fty_enum.c b/Source/CursesDialog/form/fty_enum.c index 59058a9..f1059b1 100644 --- a/Source/CursesDialog/form/fty_enum.c +++ b/Source/CursesDialog/form/fty_enum.c @@ -116,7 +116,7 @@ static int Compare(const unsigned char *s, const unsigned char *buf, if (*buf=='\0') { - return (((*s)!='\0') ? NOMATCH : EXACT); + return (((*s)=='\0') ? EXACT : NOMATCH); } else { @@ -144,7 +144,7 @@ static int Compare(const unsigned char *s, const unsigned char *buf, /* If it happens that the reference buffer is at its end, the partial match is actually an exact match. */ - return ((s[-1]!='\0') ? PARTIAL : EXACT); + return ((s[-1]=='\0') ? EXACT : PARTIAL); } /*--------------------------------------------------------------------------- diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx index 0dc954a..017fdc0 100644 --- a/Source/bindexplib.cxx +++ b/Source/bindexplib.cxx @@ -320,9 +320,9 @@ private: }; #endif -bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename, - std::set<std::string>& symbols, - std::set<std::string>& dataSymbols) +static bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename, + std::set<std::string>& symbols, + std::set<std::string>& dataSymbols) { std::string output; // break up command line into a vector @@ -375,9 +375,9 @@ bool DumpFileWithLlvmNm(std::string const& nmPath, const char* filename, return true; } -bool DumpFile(std::string const& nmPath, const char* filename, - std::set<std::string>& symbols, - std::set<std::string>& dataSymbols) +static bool DumpFile(std::string const& nmPath, const char* filename, + std::set<std::string>& symbols, + std::set<std::string>& dataSymbols) { #ifndef _WIN32 return DumpFileWithLlvmNm(nmPath, filename, symbols, dataSymbols); diff --git a/Source/cmBase32.cxx b/Source/cmBase32.cxx index a9c15c2..e8e46aa 100644 --- a/Source/cmBase32.cxx +++ b/Source/cmBase32.cxx @@ -12,7 +12,7 @@ inline unsigned char Base32EncodeChar(int schar) return Base32EncodeTable[schar]; } -void Base32Encode5(const unsigned char src[5], char dst[8]) +static void Base32Encode5(const unsigned char src[5], char dst[8]) { // [0]:5 bits dst[0] = Base32EncodeChar((src[0] >> 3) & 0x1F); diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h index c48a1f8..769fb4e 100644 --- a/Source/cmCMakePresetsFile.h +++ b/Source/cmCMakePresetsFile.h @@ -101,14 +101,18 @@ public: class ConfigurePreset : public Preset { public: -#if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L) + ConfigurePreset() = default; + ConfigurePreset(ConfigurePreset&& /*other*/) = default; + ConfigurePreset(const ConfigurePreset& /*other*/) = default; + ConfigurePreset& operator=(const ConfigurePreset& /*other*/) = default; + ~ConfigurePreset() override = default; +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) + ConfigurePreset& operator=(ConfigurePreset&& /*other*/) = default; +#else // The move assignment operators for several STL classes did not become // noexcept until C++17, which causes some tools to warn about this move - // assignment operator throwing an exception when it shouldn't. Disable the - // move assignment operator until C++17 is enabled. - // Explicitly defining a copy assignment operator prevents the compiler - // from automatically generating a move assignment operator. - ConfigurePreset& operator=(const ConfigurePreset& /*other*/) = default; + // assignment operator throwing an exception when it shouldn't. + ConfigurePreset& operator=(ConfigurePreset&& /*other*/) = delete; #endif std::string Generator; @@ -142,14 +146,18 @@ public: class BuildPreset : public Preset { public: -#if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L) + BuildPreset() = default; + BuildPreset(BuildPreset&& /*other*/) = default; + BuildPreset(const BuildPreset& /*other*/) = default; + BuildPreset& operator=(const BuildPreset& /*other*/) = default; + ~BuildPreset() override = default; +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) + BuildPreset& operator=(BuildPreset&& /*other*/) = default; +#else // The move assignment operators for several STL classes did not become // noexcept until C++17, which causes some tools to warn about this move - // assignment operator throwing an exception when it shouldn't. Disable the - // move assignment operator until C++17 is enabled. - // Explicitly defining a copy assignment operator prevents the compiler - // from automatically generating a move assignment operator. - BuildPreset& operator=(const BuildPreset& /*other*/) = default; + // assignment operator throwing an exception when it shouldn't. + BuildPreset& operator=(BuildPreset&& /*other*/) = delete; #endif std::string ConfigurePreset; @@ -168,14 +176,18 @@ public: class TestPreset : public Preset { public: -#if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L) + TestPreset() = default; + TestPreset(TestPreset&& /*other*/) = default; + TestPreset(const TestPreset& /*other*/) = default; + TestPreset& operator=(const TestPreset& /*other*/) = default; + ~TestPreset() override = default; +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) + TestPreset& operator=(TestPreset&& /*other*/) = default; +#else // The move assignment operators for several STL classes did not become // noexcept until C++17, which causes some tools to warn about this move - // assignment operator throwing an exception when it shouldn't. Disable the - // move assignment operator until C++17 is enabled. - // Explicitly defining a copy assignment operator prevents the compiler - // from automatically generating a move assignment operator. - TestPreset& operator=(const TestPreset& /*other*/) = default; + // assignment operator throwing an exception when it shouldn't. + TestPreset& operator=(TestPreset&& /*other*/) = delete; #endif struct OutputOptions diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index e460031..c49347d 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -22,17 +22,17 @@ extern "C" { -void CCONV* cmGetClientData(void* info) +static void CCONV* cmGetClientData(void* info) { return ((cmLoadedCommandInfo*)info)->ClientData; } -void CCONV cmSetClientData(void* info, void* cd) +static void CCONV cmSetClientData(void* info, void* cd) { ((cmLoadedCommandInfo*)info)->ClientData = cd; } -void CCONV cmSetError(void* info, const char* err) +static void CCONV cmSetError(void* info, const char* err) { if (((cmLoadedCommandInfo*)info)->Error) { free(((cmLoadedCommandInfo*)info)->Error); @@ -40,30 +40,31 @@ void CCONV cmSetError(void* info, const char* err) ((cmLoadedCommandInfo*)info)->Error = strdup(err); } -unsigned int CCONV cmGetCacheMajorVersion(void* arg) +static unsigned int CCONV cmGetCacheMajorVersion(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); cmState* state = mf->GetState(); return state->GetCacheMajorVersion(); } -unsigned int CCONV cmGetCacheMinorVersion(void* arg) +static unsigned int CCONV cmGetCacheMinorVersion(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); cmState* state = mf->GetState(); return state->GetCacheMinorVersion(); } -unsigned int CCONV cmGetMajorVersion(void*) +static unsigned int CCONV cmGetMajorVersion(void*) { return cmVersion::GetMajorVersion(); } -unsigned int CCONV cmGetMinorVersion(void*) +static unsigned int CCONV cmGetMinorVersion(void*) { return cmVersion::GetMinorVersion(); } -void CCONV cmAddDefinition(void* arg, const char* name, const char* value) +static void CCONV cmAddDefinition(void* arg, const char* name, + const char* value) { if (value) { cmMakefile* mf = static_cast<cmMakefile*>(arg); @@ -72,8 +73,9 @@ void CCONV cmAddDefinition(void* arg, const char* name, const char* value) } /* Add a definition to this makefile and the global cmake cache. */ -void CCONV cmAddCacheDefinition(void* arg, const char* name, const char* value, - const char* doc, int type) +static void CCONV cmAddCacheDefinition(void* arg, const char* name, + const char* value, const char* doc, + int type) { cmMakefile* mf = static_cast<cmMakefile*>(arg); @@ -99,7 +101,7 @@ void CCONV cmAddCacheDefinition(void* arg, const char* name, const char* value, } } -const char* CCONV cmGetProjectName(void* arg) +static const char* CCONV cmGetProjectName(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); static std::string name; @@ -107,63 +109,63 @@ const char* CCONV cmGetProjectName(void* arg) return name.c_str(); } -const char* CCONV cmGetHomeDirectory(void* arg) +static const char* CCONV cmGetHomeDirectory(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetHomeDirectory().c_str(); } -const char* CCONV cmGetHomeOutputDirectory(void* arg) +static const char* CCONV cmGetHomeOutputDirectory(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetHomeOutputDirectory().c_str(); } -const char* CCONV cmGetStartDirectory(void* arg) +static const char* CCONV cmGetStartDirectory(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetCurrentSourceDirectory().c_str(); } -const char* CCONV cmGetStartOutputDirectory(void* arg) +static const char* CCONV cmGetStartOutputDirectory(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetCurrentBinaryDirectory().c_str(); } -const char* CCONV cmGetCurrentDirectory(void* arg) +static const char* CCONV cmGetCurrentDirectory(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetCurrentSourceDirectory().c_str(); } -const char* CCONV cmGetCurrentOutputDirectory(void* arg) +static const char* CCONV cmGetCurrentOutputDirectory(void* arg) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetCurrentBinaryDirectory().c_str(); } -const char* CCONV cmGetDefinition(void* arg, const char* def) +static const char* CCONV cmGetDefinition(void* arg, const char* def) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return mf->GetDefinition(def).GetCStr(); } -int CCONV cmIsOn(void* arg, const char* name) +static int CCONV cmIsOn(void* arg, const char* name) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return static_cast<int>(mf->IsOn(name)); } /** Check if a command exists. */ -int CCONV cmCommandExists(void* arg, const char* name) +static int CCONV cmCommandExists(void* arg, const char* name) { cmMakefile* mf = static_cast<cmMakefile*>(arg); return static_cast<int>(mf->GetState()->GetCommand(name) ? 1 : 0); } -void CCONV cmAddDefineFlag(void* arg, const char* definition) +static void CCONV cmAddDefineFlag(void* arg, const char* definition) { cmMakefile* mf = static_cast<cmMakefile*>(arg); mf->AddDefineFlag(definition); } -void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt, - const char* d) +static void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt, + const char* d) { cmMakefile* mf = static_cast<cmMakefile*>(arg); cmTarget* t = mf->FindLocalNonAliasTarget(tgt); @@ -176,8 +178,8 @@ void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt, t->InsertLinkDirectory(BT<std::string>(d, mf->GetBacktrace())); } -void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs, - const char** srcs, int win32) +static void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs, + const char** srcs, int win32) { cmMakefile* mf = static_cast<cmMakefile*>(arg); std::vector<std::string> srcs2; @@ -191,10 +193,11 @@ void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs, } } -void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, - const char* command, const char* arguments, - int all, int numDepends, const char** depends, - int, const char**) +static void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, + const char* command, + const char* arguments, int all, + int numDepends, const char** depends, + int, const char**) { // Get the makefile instance. Perform an extra variable expansion // now because the API caller expects it. @@ -226,11 +229,11 @@ void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, mf->GetPolicyStatus(cmPolicies::CMP0116)); } -void CCONV cmAddCustomCommand(void* arg, const char* source, - const char* command, int numArgs, - const char** args, int numDepends, - const char** depends, int numOutputs, - const char** outputs, const char* target) +static void CCONV cmAddCustomCommand(void* arg, const char* source, + const char* command, int numArgs, + const char** args, int numDepends, + const char** depends, int numOutputs, + const char** outputs, const char* target) { // Get the makefile instance. Perform an extra variable expansion // now because the API caller expects it. @@ -268,11 +271,12 @@ void CCONV cmAddCustomCommand(void* arg, const char* source, mf->GetPolicyStatus(cmPolicies::CMP0116)); } -void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, - const char* command, int numArgs, - const char** args, - const char* main_dependency, - int numDepends, const char** depends) +static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, + const char* command, int numArgs, + const char** args, + const char* main_dependency, + int numDepends, + const char** depends) { // Get the makefile instance. Perform an extra variable expansion // now because the API caller expects it. @@ -304,9 +308,10 @@ void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, mf->GetPolicyStatus(cmPolicies::CMP0116)); } -void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, - const char* command, int numArgs, - const char** args, int commandType) +static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, + const char* command, int numArgs, + const char** args, + int commandType) { // Get the makefile instance. cmMakefile* mf = static_cast<cmMakefile*>(arg); @@ -376,8 +381,8 @@ static void addLinkLibrary(cmMakefile* mf, std::string const& target, t->AddLinkLibrary(*mf, lib, llt); } -void CCONV cmAddLinkLibraryForTarget(void* arg, const char* tgt, - const char* value, int libtype) +static void CCONV cmAddLinkLibraryForTarget(void* arg, const char* tgt, + const char* value, int libtype) { cmMakefile* mf = static_cast<cmMakefile*>(arg); @@ -394,8 +399,8 @@ void CCONV cmAddLinkLibraryForTarget(void* arg, const char* tgt, } } -void CCONV cmAddLibrary(void* arg, const char* libname, int shared, - int numSrcs, const char** srcs) +static void CCONV cmAddLibrary(void* arg, const char* libname, int shared, + int numSrcs, const char** srcs) { cmMakefile* mf = static_cast<cmMakefile*>(arg); std::vector<std::string> srcs2; @@ -409,8 +414,8 @@ void CCONV cmAddLibrary(void* arg, const char* libname, int shared, srcs2); } -char CCONV* cmExpandVariablesInString(void* arg, const char* source, - int escapeQuotes, int atOnly) +static char CCONV* cmExpandVariablesInString(void* arg, const char* source, + int escapeQuotes, int atOnly) { cmMakefile* mf = static_cast<cmMakefile*>(arg); std::string barf = source; @@ -419,8 +424,8 @@ char CCONV* cmExpandVariablesInString(void* arg, const char* source, return strdup(result.c_str()); } -int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs, - const char** args) +static int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs, + const char** args) { cmMakefile* mf = static_cast<cmMakefile*>(arg); @@ -436,10 +441,10 @@ int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs, return mf->ExecuteCommand(lff, status); } -void CCONV cmExpandSourceListArguments(void* arg, int numArgs, - const char** args, int* resArgc, - char*** resArgv, - unsigned int startArgumentIndex) +static void CCONV cmExpandSourceListArguments(void* arg, int numArgs, + const char** args, int* resArgc, + char*** resArgv, + unsigned int startArgumentIndex) { (void)arg; (void)startArgumentIndex; @@ -460,7 +465,7 @@ void CCONV cmExpandSourceListArguments(void* arg, int numArgs, *resArgv = resargv; } -void CCONV cmFreeArguments(int argc, char** argv) +static void CCONV cmFreeArguments(int argc, char** argv) { int i; for (i = 0; i < argc; ++i) { @@ -469,7 +474,7 @@ void CCONV cmFreeArguments(int argc, char** argv) free(argv); } -int CCONV cmGetTotalArgumentSize(int argc, char** argv) +static int CCONV cmGetTotalArgumentSize(int argc, char** argv) { int i; int result = 0; @@ -497,19 +502,19 @@ struct cmCPluginAPISourceFile // the CPluginAPI proxy source file. using cmCPluginAPISourceFileMap = std::map<cmSourceFile*, std::unique_ptr<cmCPluginAPISourceFile>>; -cmCPluginAPISourceFileMap cmCPluginAPISourceFiles; +static cmCPluginAPISourceFileMap cmCPluginAPISourceFiles; -void* CCONV cmCreateSourceFile(void) +static void* CCONV cmCreateSourceFile() { return new cmCPluginAPISourceFile; } -void* CCONV cmCreateNewSourceFile(void*) +static void* CCONV cmCreateNewSourceFile(void*) { return new cmCPluginAPISourceFile; } -void CCONV cmDestroySourceFile(void* arg) +static void CCONV cmDestroySourceFile(void* arg) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); // Only delete if it was created by cmCreateSourceFile or @@ -519,7 +524,7 @@ void CCONV cmDestroySourceFile(void* arg) } } -void CCONV* cmGetSource(void* arg, const char* name) +static void CCONV* cmGetSource(void* arg, const char* name) { cmMakefile* mf = static_cast<cmMakefile*>(arg); if (cmSourceFile* rsf = mf->GetSource(name)) { @@ -543,7 +548,7 @@ void CCONV* cmGetSource(void* arg, const char* name) return nullptr; } -void* CCONV cmAddSource(void* arg, void* arg2) +static void* CCONV cmAddSource(void* arg, void* arg2) { cmMakefile* mf = static_cast<cmMakefile*>(arg); cmCPluginAPISourceFile* osf = static_cast<cmCPluginAPISourceFile*>(arg2); @@ -576,19 +581,19 @@ void* CCONV cmAddSource(void* arg, void* arg2) return value; } -const char* CCONV cmSourceFileGetSourceName(void* arg) +static const char* CCONV cmSourceFileGetSourceName(void* arg) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); return sf->SourceName.c_str(); } -const char* CCONV cmSourceFileGetFullPath(void* arg) +static const char* CCONV cmSourceFileGetFullPath(void* arg) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); return sf->FullPath.c_str(); } -const char* CCONV cmSourceFileGetProperty(void* arg, const char* prop) +static const char* CCONV cmSourceFileGetProperty(void* arg, const char* prop) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); if (cmSourceFile* rsf = sf->RealSourceFile) { @@ -600,7 +605,7 @@ const char* CCONV cmSourceFileGetProperty(void* arg, const char* prop) return sf->Properties.GetPropertyValue(prop).GetCStr(); } -int CCONV cmSourceFileGetPropertyAsBool(void* arg, const char* prop) +static int CCONV cmSourceFileGetPropertyAsBool(void* arg, const char* prop) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); if (cmSourceFile* rsf = sf->RealSourceFile) { @@ -609,8 +614,8 @@ int CCONV cmSourceFileGetPropertyAsBool(void* arg, const char* prop) return cmIsOn(cmSourceFileGetProperty(arg, prop)) ? 1 : 0; } -void CCONV cmSourceFileSetProperty(void* arg, const char* prop, - const char* value) +static void CCONV cmSourceFileSetProperty(void* arg, const char* prop, + const char* value) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); if (cmSourceFile* rsf = sf->RealSourceFile) { @@ -623,7 +628,7 @@ void CCONV cmSourceFileSetProperty(void* arg, const char* prop, } } -void CCONV cmSourceFileAddDepend(void* arg, const char* depend) +static void CCONV cmSourceFileAddDepend(void* arg, const char* depend) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); if (cmSourceFile* rsf = sf->RealSourceFile) { @@ -633,11 +638,11 @@ void CCONV cmSourceFileAddDepend(void* arg, const char* depend) } } -void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir, - int numSourceExtensions, - const char** sourceExtensions, - int numHeaderExtensions, - const char** headerExtensions) +static void CCONV cmSourceFileSetName(void* arg, const char* name, + const char* dir, int numSourceExtensions, + const char** sourceExtensions, + int numHeaderExtensions, + const char** headerExtensions) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); if (sf->RealSourceFile) { @@ -718,8 +723,9 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir, cmSystemTools::Error(e.str()); } -void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir, - const char* ext, int headerFileOnly) +static void CCONV cmSourceFileSetName2(void* arg, const char* name, + const char* dir, const char* ext, + int headerFileOnly) { cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg); if (sf->RealSourceFile) { @@ -743,48 +749,48 @@ void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir, sf->SourceExtension = ext; } -char* CCONV cmGetFilenameWithoutExtension(const char* name) +static char* CCONV cmGetFilenameWithoutExtension(const char* name) { std::string sres = cmSystemTools::GetFilenameWithoutExtension(name); return strdup(sres.c_str()); } -char* CCONV cmGetFilenamePath(const char* name) +static char* CCONV cmGetFilenamePath(const char* name) { std::string sres = cmSystemTools::GetFilenamePath(name); return strdup(sres.c_str()); } -char* CCONV cmCapitalized(const char* name) +static char* CCONV cmCapitalized(const char* name) { std::string sres = cmSystemTools::Capitalized(name); return strdup(sres.c_str()); } -void CCONV cmCopyFileIfDifferent(const char* name1, const char* name2) +static void CCONV cmCopyFileIfDifferent(const char* name1, const char* name2) { cmSystemTools::CopyFileIfDifferent(name1, name2); } -void CCONV cmRemoveFile(const char* name) +static void CCONV cmRemoveFile(const char* name) { cmSystemTools::RemoveFile(name); } -void CCONV cmDisplayStatus(void* arg, const char* message) +static void CCONV cmDisplayStatus(void* arg, const char* message) { cmMakefile* mf = static_cast<cmMakefile*>(arg); mf->DisplayStatus(message, -1); } -void CCONV cmFree(void* data) +static void CCONV cmFree(void* data) { free(data); } -void CCONV DefineSourceFileProperty(void* arg, const char* name, - const char* briefDocs, - const char* longDocs, int chained) +static void CCONV DefineSourceFileProperty(void* arg, const char* name, + const char* briefDocs, + const char* longDocs, int chained) { cmMakefile* mf = static_cast<cmMakefile*>(arg); mf->GetState()->DefineProperty(name, cmProperty::SOURCE_FILE, @@ -794,7 +800,7 @@ void CCONV DefineSourceFileProperty(void* arg, const char* name, } // close the extern "C" scope -cmCAPI cmStaticCAPI = { +static cmCAPI cmStaticCAPI = { cmGetClientData, cmGetTotalArgumentSize, cmFreeArguments, diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index dfd2b6c..647dd87 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -227,8 +227,8 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) char buf[1024]; // add todays year day and month to the time in str because // curl_getdate no longer assumes the day is today - sprintf(buf, "%d%02d%02d %s", lctime->tm_year + 1900, lctime->tm_mon + 1, - lctime->tm_mday, str.c_str()); + snprintf(buf, sizeof(buf), "%d%02d%02d %s", lctime->tm_year + 1900, + lctime->tm_mon + 1, lctime->tm_mday, str.c_str()); cmCTestLog(this, OUTPUT, "Determine Nightly Start Time" << std::endl << " Specified time: " << str @@ -543,9 +543,9 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) this->Impl->TomorrowTag); } char datestring[100]; - sprintf(datestring, "%04d%02d%02d-%02d%02d", lctime->tm_year + 1900, - lctime->tm_mon + 1, lctime->tm_mday, lctime->tm_hour, - lctime->tm_min); + snprintf(datestring, sizeof(datestring), "%04d%02d%02d-%02d%02d", + lctime->tm_year + 1900, lctime->tm_mon + 1, lctime->tm_mday, + lctime->tm_hour, lctime->tm_min); tag = datestring; cmsys::ofstream ofs(tagfile.c_str()); if (ofs) { @@ -2967,8 +2967,9 @@ void cmCTest::SetStopTime(std::string const& time_str) tzone_offset *= 100; char buf[1024]; - sprintf(buf, "%d%02d%02d %s %+05i", lctime->tm_year + 1900, - lctime->tm_mon + 1, lctime->tm_mday, time_str.c_str(), tzone_offset); + snprintf(buf, sizeof(buf), "%d%02d%02d %s %+05i", lctime->tm_year + 1900, + lctime->tm_mon + 1, lctime->tm_mday, time_str.c_str(), + tzone_offset); time_t stop_time = curl_getdate(buf, ¤t_time); if (stop_time == -1) { diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 831a81f..2ff91fe 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -722,7 +722,7 @@ void cmComputeLinkInformation::AddItem(BT<std::string> const& item, this->AddFrameworkItem(item.Value); } else if (cmSystemTools::FileIsDirectory(item.Value)) { // This is a directory. - this->DropDirectoryItem(item.Value); + this->DropDirectoryItem(item); } else { // Use the full path given to the library file. this->Depends.push_back(item.Value); @@ -1349,16 +1349,17 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item) } } -void cmComputeLinkInformation::DropDirectoryItem(std::string const& item) +void cmComputeLinkInformation::DropDirectoryItem(BT<std::string> const& item) { // A full path to a directory was found as a link item. Warn the // user. - std::ostringstream e; - e << "WARNING: Target \"" << this->Target->GetName() - << "\" requests linking to directory \"" << item << "\". " - << "Targets may link only to libraries. " - << "CMake is dropping the item."; - cmSystemTools::Message(e.str()); + this->CMakeInstance->IssueMessage( + MessageType::WARNING, + cmStrCat( + "Target \"", this->Target->GetName(), + "\" requests linking to directory \"", item.Value, + "\". Targets may link only to libraries. CMake is dropping the item."), + item.Backtrace); } void cmComputeLinkInformation::ComputeFrameworkInfo() diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 90a699e..0315540 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -187,7 +187,7 @@ private: bool CheckImplicitDirItem(std::string const& item); void AddUserItem(BT<std::string> const& item, bool pathNotKnown); void AddFrameworkItem(std::string const& item); - void DropDirectoryItem(std::string const& item); + void DropDirectoryItem(BT<std::string> const& item); bool CheckSharedLibNoSOName(std::string const& item); void AddSharedLibNoSOName(std::string const& item); void HandleBadFullItem(std::string const& item, std::string const& file); diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 971c86e..84fa897 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -699,7 +699,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, /* Use a random file name to avoid rapid creation and deletion of the same executable name (some filesystems fail on that). */ - sprintf(targetNameBuf, "cmTC_%05x", cmSystemTools::RandomSeed() & 0xFFFFF); + snprintf(targetNameBuf, sizeof(targetNameBuf), "cmTC_%05x", + cmSystemTools::RandomSeed() & 0xFFFFF); targetName = targetNameBuf; if (!targets.empty()) { diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 04d09d4..105ccf1 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -342,7 +342,7 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const return this->CommandLines[c][0]; } -std::string escapeForShellOldStyle(const std::string& str) +static std::string escapeForShellOldStyle(const std::string& str) { std::string result; #if defined(_WIN32) && !defined(__CYGWIN__) diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 1678ce8..66f1733 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -26,17 +26,14 @@ template <size_t s> struct cmELFByteSwapSize { }; -void cmELFByteSwap(char* /*unused*/, cmELFByteSwapSize<1> /*unused*/) -{ -} -void cmELFByteSwap(char* data, cmELFByteSwapSize<2> /*unused*/) +static void cmELFByteSwap(char* data, cmELFByteSwapSize<2> /*unused*/) { char one_byte; one_byte = data[0]; data[0] = data[1]; data[1] = one_byte; } -void cmELFByteSwap(char* data, cmELFByteSwapSize<4> /*unused*/) +static void cmELFByteSwap(char* data, cmELFByteSwapSize<4> /*unused*/) { char one_byte; one_byte = data[0]; @@ -46,7 +43,7 @@ void cmELFByteSwap(char* data, cmELFByteSwapSize<4> /*unused*/) data[1] = data[2]; data[2] = one_byte; } -void cmELFByteSwap(char* data, cmELFByteSwapSize<8> /*unused*/) +static void cmELFByteSwap(char* data, cmELFByteSwapSize<8> /*unused*/) { char one_byte; one_byte = data[0]; diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index 51fb219..e069b77 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -114,7 +114,7 @@ bool cmExecProgramCommand(std::vector<std::string> const& args, if (!return_variable.empty()) { char buffer[100]; - sprintf(buffer, "%d", retVal); + snprintf(buffer, sizeof(buffer), "%d", retVal); status.GetMakefile().AddDefinition(return_variable, buffer); } diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index ffcc415..3b990cc 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -318,7 +318,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args, case cmsysProcess_State_Exited: { int v = cmsysProcess_GetExitValue(cp); char buf[16]; - sprintf(buf, "%d", v); + snprintf(buf, sizeof(buf), "%d", v); status.GetMakefile().AddDefinition(arguments.ResultVariable, buf); } break; case cmsysProcess_State_Exception: @@ -346,7 +346,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args, int exitCode = cmsysProcess_GetExitValueByIndex(cp, static_cast<int>(i)); char buf[16]; - sprintf(buf, "%d", exitCode); + snprintf(buf, sizeof(buf), "%d", exitCode); res.emplace_back(buf); } break; case kwsysProcess_StateByIndex_Exception: diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index aa968dc..a47f1e5 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -11,12 +11,15 @@ #include <cmext/algorithm> #include "cmExportSet.h" +#include "cmFileSet.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" @@ -135,6 +138,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) this->PopulateCompatibleInterfaceProperties(gte, properties); this->GenerateInterfaceProperties(gte, os, properties); + + this->GenerateTargetFileSets(gte, os); } // Generate import file content for each configuration. @@ -356,3 +361,17 @@ std::string cmExportBuildFileGenerator::InstallNameDir( return install_name_dir; } + +std::string cmExportBuildFileGenerator::GetFileSetDirectories( + cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/) +{ + return cmOutputConverter::EscapeForCMake( + cmJoin(fileSet->GetDirectoryEntries(), ";")); +} + +std::string cmExportBuildFileGenerator::GetFileSetFiles( + cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/) +{ + return cmOutputConverter::EscapeForCMake( + cmJoin(fileSet->GetFileEntries(), ";")); +} diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 244f526..a7985c7 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -15,9 +15,11 @@ #include "cmStateTypes.h" class cmExportSet; +class cmFileSet; class cmGeneratorTarget; class cmGlobalGenerator; class cmLocalGenerator; +class cmTargetExport; /** \class cmExportBuildFileGenerator * \brief Generate a file exporting targets from a build tree. @@ -76,6 +78,11 @@ protected: std::string InstallNameDir(cmGeneratorTarget const* target, const std::string& config) override; + std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet, + cmTargetExport* te) override; + std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet, + cmTargetExport* te) override; + std::pair<std::vector<std::string>, std::string> FindBuildExportInfo( cmGlobalGenerator* gg, const std::string& name); diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 0eda92c..896240c 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -12,6 +12,7 @@ #include "cmsys/FStream.hxx" #include "cmComputeLinkInformation.h" +#include "cmFileSet.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -494,8 +495,9 @@ void cmExportFileGenerator::PopulateInterfaceProperty( properties, missingTargets); } -void getPropertyContents(cmGeneratorTarget const* tgt, const std::string& prop, - std::set<std::string>& ifaceProperties) +static void getPropertyContents(cmGeneratorTarget const* tgt, + const std::string& prop, + std::set<std::string>& ifaceProperties) { cmValue p = tgt->GetProperty(prop); if (!p) { @@ -505,9 +507,9 @@ void getPropertyContents(cmGeneratorTarget const* tgt, const std::string& prop, ifaceProperties.insert(content.begin(), content.end()); } -void getCompatibleInterfaceProperties(cmGeneratorTarget const* target, - std::set<std::string>& ifaceProperties, - const std::string& config) +static void getCompatibleInterfaceProperties( + cmGeneratorTarget const* target, std::set<std::string>& ifaceProperties, + const std::string& config) { if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) { // object libraries have no link information, so nothing to compute @@ -1255,3 +1257,39 @@ bool cmExportFileGenerator::PopulateExportProperties( } return true; } + +void cmExportFileGenerator::GenerateTargetFileSets(cmGeneratorTarget* gte, + std::ostream& os, + cmTargetExport* te) +{ + auto interfaceFileSets = gte->Target->GetAllInterfaceFileSets(); + if (!interfaceFileSets.empty()) { + std::string targetName = cmStrCat(this->Namespace, gte->GetExportName()); + os << "if(NOT CMAKE_VERSION VERSION_LESS \"" << DEVEL_CMAKE_VERSION(3, 23) + << "\")\n" + " target_sources(" + << targetName << "\n"; + + for (auto const& name : interfaceFileSets) { + auto* fileSet = gte->Target->GetFileSet(name); + if (!fileSet) { + gte->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("File set \"", name, + "\" is listed in interface file sets of ", gte->GetName(), + " but has not been created")); + return; + } + + os << " INTERFACE" + << "\n FILE_SET " << cmOutputConverter::EscapeForCMake(name) + << "\n TYPE " + << cmOutputConverter::EscapeForCMake(fileSet->GetType()) + << "\n BASE_DIRS " + << this->GetFileSetDirectories(gte, fileSet, te) << "\n FILES " + << this->GetFileSetFiles(gte, fileSet, te) << "\n"; + } + + os << " )\nendif()\n\n"; + } +} diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 24e048b..5875247 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -15,7 +15,9 @@ #include "cmVersion.h" #include "cmVersionConfig.h" +class cmFileSet; class cmGeneratorTarget; +class cmTargetExport; #define STRINGIFY_HELPER(X) #X #define STRINGIFY(X) STRINGIFY_HELPER(X) @@ -184,6 +186,16 @@ protected: ImportPropertyMap& properties, std::string& errorMessage); + void GenerateTargetFileSets(cmGeneratorTarget* gte, std::ostream& os, + cmTargetExport* te = nullptr); + + virtual std::string GetFileSetDirectories(cmGeneratorTarget* gte, + cmFileSet* fileSet, + cmTargetExport* te) = 0; + virtual std::string GetFileSetFiles(cmGeneratorTarget* gte, + cmFileSet* fileSet, + cmTargetExport* te) = 0; + // The namespace in which the exports are placed in the generated file. std::string Namespace; diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index e9ac875..2dd8b8f 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -2,19 +2,23 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmExportInstallFileGenerator.h" +#include <algorithm> #include <memory> #include <sstream> #include <utility> #include "cmExportSet.h" +#include "cmFileSet.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmInstallExportGenerator.h" +#include "cmInstallFileSetGenerator.h" #include "cmInstallTargetGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" @@ -147,6 +151,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) this->PopulateCompatibleInterfaceProperties(gt, properties); this->GenerateInterfaceProperties(gt, os, properties); + + this->GenerateTargetFileSets(gt, os, te); } if (require3_1_0) { @@ -534,3 +540,102 @@ std::string cmExportInstallFileGenerator::InstallNameDir( return install_name_dir; } + +namespace { +bool EntryIsContextSensitive( + const std::unique_ptr<cmCompiledGeneratorExpression>& cge) +{ + return cge->GetHadContextSensitiveCondition(); +} +} + +std::string cmExportInstallFileGenerator::GetFileSetDirectories( + cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* te) +{ + std::vector<std::string> resultVector; + + auto configs = + gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + + cmGeneratorExpression ge; + auto cge = ge.Parse(te->FileSetGenerators.at(fileSet)->GetDestination()); + + for (auto const& config : configs) { + auto dest = cmStrCat("${_IMPORT_PREFIX}/", + cmOutputConverter::EscapeForCMake( + cge->Evaluate(gte->LocalGenerator, config, gte), + cmOutputConverter::WrapQuotes::NoWrap)); + + if (cge->GetHadContextSensitiveCondition() && configs.size() != 1) { + resultVector.push_back( + cmStrCat("\"$<$<CONFIG:", config, ">:", dest, ">\"")); + } else { + resultVector.push_back(cmStrCat('"', dest, '"')); + break; + } + } + + return cmJoin(resultVector, " "); +} + +std::string cmExportInstallFileGenerator::GetFileSetFiles( + cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* te) +{ + std::vector<std::string> resultVector; + + auto configs = + gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + + auto fileEntries = fileSet->CompileFileEntries(); + auto directoryEntries = fileSet->CompileDirectoryEntries(); + + cmGeneratorExpression destGe; + auto destCge = + destGe.Parse(te->FileSetGenerators.at(fileSet)->GetDestination()); + + for (auto const& config : configs) { + auto directories = fileSet->EvaluateDirectoryEntries( + directoryEntries, gte->LocalGenerator, config, gte); + + std::map<std::string, std::vector<std::string>> files; + for (auto const& entry : fileEntries) { + fileSet->EvaluateFileEntry(directories, files, entry, + gte->LocalGenerator, config, gte); + } + auto dest = cmStrCat("${_IMPORT_PREFIX}/", + cmOutputConverter::EscapeForCMake( + destCge->Evaluate(gte->LocalGenerator, config, gte), + cmOutputConverter::WrapQuotes::NoWrap), + '/'); + + bool const contextSensitive = destCge->GetHadContextSensitiveCondition() || + std::any_of(directoryEntries.begin(), directoryEntries.end(), + EntryIsContextSensitive) || + std::any_of(fileEntries.begin(), fileEntries.end(), + EntryIsContextSensitive); + + for (auto const& it : files) { + auto prefix = it.first.empty() ? "" : cmStrCat(it.first, '/'); + for (auto const& filename : it.second) { + auto relFile = + cmStrCat(prefix, cmSystemTools::GetFilenameName(filename)); + auto escapedFile = + cmStrCat(dest, + cmOutputConverter::EscapeForCMake( + relFile, cmOutputConverter::WrapQuotes::NoWrap)); + if (contextSensitive && configs.size() != 1) { + resultVector.push_back( + cmStrCat("\"$<$<CONFIG:", config, ">:", escapedFile, ">\"")); + } else { + resultVector.push_back(cmStrCat('"', escapedFile, '"')); + } + } + } + + if (!(contextSensitive && configs.size() != 1)) { + break; + } + } + + return cmJoin(resultVector, " "); +} diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 5cec2e0..9374c6b 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -14,6 +14,7 @@ #include "cmExportFileGenerator.h" #include "cmStateTypes.h" +class cmFileSet; class cmGeneratorTarget; class cmGlobalGenerator; class cmInstallExportGenerator; @@ -97,6 +98,11 @@ protected: std::string InstallNameDir(cmGeneratorTarget const* target, const std::string& config) override; + std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet, + cmTargetExport* te) override; + std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet, + cmTargetExport* te) override; + cmInstallExportGenerator* IEGen; // The import file generated for each configuration. diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index cbe3c4d..4fe92c6 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -7,17 +7,22 @@ #include <cm/memory> +#include "cmFileSet.h" #include "cmGeneratorExpression.h" #include "cmGeneratorExpressionDAGChecker.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmOutputConverter.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" #include "cmValue.h" +class cmTargetExport; + cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator( cmGlobalGenerator* gg, const std::vector<std::string>& targets, cmMakefile* mf, std::set<std::string> const& langs) @@ -137,3 +142,17 @@ std::string cmExportTryCompileFileGenerator::InstallNameDir( return install_name_dir; } + +std::string cmExportTryCompileFileGenerator::GetFileSetDirectories( + cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/) +{ + return cmOutputConverter::EscapeForCMake( + cmJoin(fileSet->GetDirectoryEntries(), ";")); +} + +std::string cmExportTryCompileFileGenerator::GetFileSetFiles( + cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/) +{ + return cmOutputConverter::EscapeForCMake( + cmJoin(fileSet->GetFileEntries(), ";")); +} diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index 127b8df..8a1fd7e 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -11,9 +11,11 @@ #include "cmExportFileGenerator.h" +class cmFileSet; class cmGeneratorTarget; class cmGlobalGenerator; class cmMakefile; +class cmTargetExport; class cmExportTryCompileFileGenerator : public cmExportFileGenerator { @@ -48,6 +50,13 @@ protected: std::string InstallNameDir(cmGeneratorTarget const* target, const std::string& config) override; + std::string GetFileSetDirectories(cmGeneratorTarget* target, + cmFileSet* fileSet, + cmTargetExport* te) override; + + std::string GetFileSetFiles(cmGeneratorTarget* target, cmFileSet* fileSet, + cmTargetExport* te) override; + private: std::string FindTargets(const std::string& prop, const cmGeneratorTarget* tgt, diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index d529f52..c1df992 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -686,7 +686,8 @@ std::string cmFileAPI::NoSupportedVersion( // The "codemodel" object kind. -static unsigned int const CodeModelV2Minor = 3; +// Update Help/manual/cmake-file-api.7.rst when updating this constant. +static unsigned int const CodeModelV2Minor = 4; void cmFileAPI::BuildClientRequestCodeModel( ClientRequest& r, std::vector<RequestVersion> const& versions) diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 147181e..40e1d2e 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -23,11 +23,13 @@ #include "cmCryptoHash.h" #include "cmExportSet.h" #include "cmFileAPI.h" +#include "cmFileSet.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmInstallDirectoryGenerator.h" #include "cmInstallExportGenerator.h" +#include "cmInstallFileSetGenerator.h" #include "cmInstallFilesGenerator.h" #include "cmInstallGenerator.h" #include "cmInstallGetRuntimeDependenciesGenerator.h" @@ -1043,6 +1045,53 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen) installer["runtimeDependencySetType"] = "library"; break; } + } else if (auto* installFileSet = + dynamic_cast<cmInstallFileSetGenerator*>(gen)) { + installer["type"] = "fileSet"; + installer["destination"] = installFileSet->GetDestination(this->Config); + + auto* fileSet = installFileSet->GetFileSet(); + auto* target = installFileSet->GetTarget(); + + auto dirCges = fileSet->CompileDirectoryEntries(); + auto dirs = fileSet->EvaluateDirectoryEntries( + dirCges, target->GetLocalGenerator(), this->Config, target); + + auto entryCges = fileSet->CompileFileEntries(); + std::map<std::string, std::vector<std::string>> entries; + for (auto const& entryCge : entryCges) { + fileSet->EvaluateFileEntry(dirs, entries, entryCge, + target->GetLocalGenerator(), this->Config, + target); + } + + Json::Value files = Json::arrayValue; + for (auto const& it : entries) { + auto dir = it.first; + if (!dir.empty()) { + dir += '/'; + } + for (auto const& file : it.second) { + files.append(this->DumpInstallerPath( + this->TopSource, file, + cmStrCat(dir, cmSystemTools::GetFilenameName(file)))); + } + } + installer["paths"] = std::move(files); + installer["fileSetName"] = fileSet->GetName(); + installer["fileSetType"] = fileSet->GetType(); + installer["fileSetDirectories"] = Json::arrayValue; + for (auto const& dir : dirs) { + installer["fileSetDirectories"].append( + RelativeIfUnder(this->TopSource, dir)); + } + installer["fileSetTarget"] = Json::objectValue; + installer["fileSetTarget"]["id"] = TargetId(target, this->TopBuild); + installer["fileSetTarget"]["index"] = this->TargetIndexMap[target]; + + if (installFileSet->GetOptional()) { + installer["isOptional"] = true; + } } // Add fields common to all install generators. diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index fd0595d..338f3c9 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -217,7 +217,7 @@ bool HandleReadCommand(std::vector<std::string> const& args, char c; while ((sizeLimit != 0) && (file.get(c))) { char hex[4]; - sprintf(hex, "%.2x", c & 0xff); + snprintf(hex, sizeof(hex), "%.2x", c & 0xff); output += hex; if (sizeLimit > 0) { sizeLimit--; @@ -1627,8 +1627,9 @@ size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr, case CURLINFO_SSL_DATA_IN: case CURLINFO_SSL_DATA_OUT: { char buf[128]; - int n = sprintf(buf, "[%" KWIML_INT_PRIu64 " bytes data]\n", - static_cast<KWIML_INT_uint64_t>(size)); + int n = + snprintf(buf, sizeof(buf), "[%" KWIML_INT_PRIu64 " bytes data]\n", + static_cast<KWIML_INT_uint64_t>(size)); if (n > 0) { cm::append(vec, buf, buf + n); } diff --git a/Source/cmFileLockResult.cxx b/Source/cmFileLockResult.cxx index 9d5a6c6..70b8cdb 100644 --- a/Source/cmFileLockResult.cxx +++ b/Source/cmFileLockResult.cxx @@ -5,7 +5,6 @@ #include <cerrno> #include <cstring> -#define WINMSG_BUF_LEN (1024) cmFileLockResult cmFileLockResult::MakeOk() { return { OK, 0 }; @@ -54,6 +53,7 @@ std::string cmFileLockResult::GetOutputMessage() const case SYSTEM: #if defined(_WIN32) { +# define WINMSG_BUF_LEN (1024) char winmsg[WINMSG_BUF_LEN]; DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; if (FormatMessageA(flags, NULL, this->ErrorValue, diff --git a/Source/cmFileSet.cxx b/Source/cmFileSet.cxx new file mode 100644 index 0000000..08d56ba --- /dev/null +++ b/Source/cmFileSet.cxx @@ -0,0 +1,151 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmFileSet.h" + +#include <sstream> +#include <string> +#include <utility> +#include <vector> + +#include "cmGeneratorExpression.h" +#include "cmListFileCache.h" +#include "cmLocalGenerator.h" +#include "cmMessageType.h" +#include "cmStringAlgorithms.h" +#include "cmSystemTools.h" +#include "cmake.h" + +cmFileSet::cmFileSet(std::string name, std::string type) + : Name(std::move(name)) + , Type(std::move(type)) +{ +} + +void cmFileSet::ClearDirectoryEntries() +{ + this->DirectoryEntries.clear(); +} + +void cmFileSet::AddDirectoryEntry(BT<std::string> directories) +{ + this->DirectoryEntries.push_back(std::move(directories)); +} + +void cmFileSet::ClearFileEntries() +{ + this->FileEntries.clear(); +} + +void cmFileSet::AddFileEntry(BT<std::string> files) +{ + this->FileEntries.push_back(std::move(files)); +} + +std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> +cmFileSet::CompileFileEntries() const +{ + std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> result; + + for (auto const& entry : this->FileEntries) { + for (auto const& ex : cmExpandedList(entry.Value)) { + cmGeneratorExpression ge(entry.Backtrace); + auto cge = ge.Parse(ex); + result.push_back(std::move(cge)); + } + } + + return result; +} + +std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> +cmFileSet::CompileDirectoryEntries() const +{ + std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> result; + + for (auto const& entry : this->DirectoryEntries) { + for (auto const& ex : cmExpandedList(entry.Value)) { + cmGeneratorExpression ge(entry.Backtrace); + auto cge = ge.Parse(ex); + result.push_back(std::move(cge)); + } + } + + return result; +} + +std::vector<std::string> cmFileSet::EvaluateDirectoryEntries( + const std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>& cges, + cmLocalGenerator* lg, const std::string& config, + const cmGeneratorTarget* target, + cmGeneratorExpressionDAGChecker* dagChecker) const +{ + std::vector<std::string> result; + for (auto const& cge : cges) { + auto entry = cge->Evaluate(lg, config, target, dagChecker); + auto dirs = cmExpandedList(entry); + for (std::string dir : dirs) { + if (!cmSystemTools::FileIsFullPath(dir)) { + dir = cmStrCat(lg->GetCurrentSourceDirectory(), '/', dir); + } + auto collapsedDir = cmSystemTools::CollapseFullPath(dir); + for (auto const& priorDir : result) { + auto collapsedPriorDir = cmSystemTools::CollapseFullPath(priorDir); + if (!cmSystemTools::SameFile(collapsedDir, collapsedPriorDir) && + (cmSystemTools::IsSubDirectory(collapsedDir, collapsedPriorDir) || + cmSystemTools::IsSubDirectory(collapsedPriorDir, collapsedDir))) { + lg->GetCMakeInstance()->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat( + "Base directories in file set cannot be subdirectories of each " + "other:\n ", + priorDir, "\n ", dir), + cge->GetBacktrace()); + return {}; + } + } + result.push_back(dir); + } + } + return result; +} + +void cmFileSet::EvaluateFileEntry( + const std::vector<std::string>& dirs, + std::map<std::string, std::vector<std::string>>& filesPerDir, + const std::unique_ptr<cmCompiledGeneratorExpression>& cge, + cmLocalGenerator* lg, const std::string& config, + const cmGeneratorTarget* target, + cmGeneratorExpressionDAGChecker* dagChecker) const +{ + auto files = cge->Evaluate(lg, config, target, dagChecker); + for (std::string file : cmExpandedList(files)) { + if (!cmSystemTools::FileIsFullPath(file)) { + file = cmStrCat(lg->GetCurrentSourceDirectory(), '/', file); + } + auto collapsedFile = cmSystemTools::CollapseFullPath(file); + bool found = false; + std::string relDir; + for (auto const& dir : dirs) { + auto collapsedDir = cmSystemTools::CollapseFullPath(dir); + if (cmSystemTools::IsSubDirectory(collapsedFile, collapsedDir)) { + found = true; + relDir = cmSystemTools::GetParentDirectory( + cmSystemTools::RelativePath(collapsedDir, collapsedFile)); + break; + } + } + if (!found) { + std::ostringstream e; + e << "File:\n " << file + << "\nmust be in one of the file set's base directories:"; + for (auto const& dir : dirs) { + e << "\n " << dir; + } + lg->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(), + cge->GetBacktrace()); + return; + } + + filesPerDir[relDir].push_back(file); + } +} diff --git a/Source/cmFileSet.h b/Source/cmFileSet.h new file mode 100644 index 0000000..5ee4a98 --- /dev/null +++ b/Source/cmFileSet.h @@ -0,0 +1,64 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include <map> +#include <memory> +#include <string> +#include <vector> + +#include "cmListFileCache.h" + +class cmCompiledGeneratorExpression; +struct cmGeneratorExpressionDAGChecker; +class cmGeneratorTarget; +class cmLocalGenerator; + +class cmFileSet +{ +public: + cmFileSet(std::string name, std::string type); + + const std::string& GetName() const { return this->Name; } + const std::string& GetType() const { return this->Type; } + + void ClearDirectoryEntries(); + void AddDirectoryEntry(BT<std::string> directories); + const std::vector<BT<std::string>>& GetDirectoryEntries() const + { + return this->DirectoryEntries; + } + + void ClearFileEntries(); + void AddFileEntry(BT<std::string> files); + const std::vector<BT<std::string>>& GetFileEntries() const + { + return this->FileEntries; + } + + std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> + CompileFileEntries() const; + + std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> + CompileDirectoryEntries() const; + + std::vector<std::string> EvaluateDirectoryEntries( + const std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>& cges, + cmLocalGenerator* lg, const std::string& config, + const cmGeneratorTarget* target, + cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const; + + void EvaluateFileEntry( + const std::vector<std::string>& dirs, + std::map<std::string, std::vector<std::string>>& filesPerDir, + const std::unique_ptr<cmCompiledGeneratorExpression>& cge, + cmLocalGenerator* lg, const std::string& config, + const cmGeneratorTarget* target, + cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const; + +private: + std::string Name; + std::string Type; + std::vector<BT<std::string>> DirectoryEntries; + std::vector<BT<std::string>> FileEntries; +}; diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index e896a87..70d59c2 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -353,7 +353,7 @@ void cmFindCommon::AddPathSuffix(std::string const& arg) this->SearchPathSuffixes.push_back(std::move(suffix)); } -void AddTrailingSlash(std::string& s) +static void AddTrailingSlash(std::string& s) { if (!s.empty() && s.back() != '/') { s += '/'; diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 335ebbe..694eb0f 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -671,7 +671,7 @@ void cmFindPackageCommand::SetVersionVariables( addDefinition(prefix, version); char buf[64]; - sprintf(buf, "%u", major); + snprintf(buf, sizeof(buf), "%u", major); addDefinition(prefix + "_MAJOR", buf); sprintf(buf, "%u", minor); addDefinition(prefix + "_MINOR", buf); diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 1c87625..9a4b063 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -104,6 +104,26 @@ struct cmFindProgramHelper } bool FileIsExecutable(std::string const& file) const { +#ifdef _WIN32 + if (!this->FileIsExecutableCMP0109(file)) { + return false; + } + // Pretend the Windows "python" app installer alias does not exist. + if (cmSystemTools::LowerCase(file).find("/windowsapps/python") != + std::string::npos) { + std::string dest; + if (cmSystemTools::ReadSymlink(file, dest) && + cmHasLiteralSuffix(dest, "\\AppInstallerPythonRedirector.exe")) { + return false; + } + } + return true; +#else + return this->FileIsExecutableCMP0109(file); +#endif + } + bool FileIsExecutableCMP0109(std::string const& file) const + { switch (this->PolicyCMP0109) { case cmPolicies::OLD: return cmSystemTools::FileExists(file, true); diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 06778b1..c86001a 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -136,7 +136,8 @@ void cmGeneratedFileStreamBase::Open(std::string const& name) this->TempName += this->TempExt; } else { char buf[64]; - sprintf(buf, "tmp%05x", cmSystemTools::RandomSeed() & 0xFFFFF); + snprintf(buf, sizeof(buf), "tmp%05x", + cmSystemTools::RandomSeed() & 0xFFFFF); this->TempName += buf; } diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index c357ee1..396e9c9 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -814,7 +814,8 @@ struct PlatformIdNode : public cmGeneratorExpressionNode } return "0"; } -} platformIdNode; +}; +static struct PlatformIdNode platformIdNode; template <cmSystemTools::CompareOp Op> struct VersionNode : public cmGeneratorExpressionNode @@ -1261,7 +1262,7 @@ static const struct DeviceLinkNode : public cmGeneratorExpressionNode } } deviceLinkNode; -std::string getLinkedTargetsContent( +static std::string getLinkedTargetsContent( cmGeneratorTarget const* target, std::string const& prop, cmGeneratorExpressionContext* context, cmGeneratorExpressionDAGChecker* dagChecker) @@ -1830,8 +1831,8 @@ static const char* targetPolicyWhitelist[] = { #undef TARGET_POLICY_STRING }; -cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt, - const char* policy) +static cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt, + const char* policy) { #define RETURN_POLICY(POLICY) \ if (strcmp(policy, #POLICY) == 0) { \ @@ -1846,7 +1847,7 @@ cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt, return cmPolicies::WARN; } -cmPolicies::PolicyID policyForString(const char* policy_id) +static cmPolicies::PolicyID policyForString(const char* policy_id) { #define RETURN_POLICY_ID(POLICY_ID) \ if (strcmp(policy_id, #POLICY_ID) == 0) { \ diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 8cc524a..2fedbd1 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -25,6 +25,7 @@ #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" +#include "cmFileSet.h" #include "cmFileTimes.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" @@ -41,6 +42,7 @@ #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmSourceFileLocationKind.h" +#include "cmSourceGroup.h" #include "cmStandardLevelResolver.h" #include "cmState.h" #include "cmStringAlgorithms.h" @@ -173,9 +175,73 @@ private: BT<std::string> PropertyValue; }; -std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> -CreateTargetPropertyEntry(const BT<std::string>& propertyValue, - bool evaluateForBuildsystem = false) +class TargetPropertyEntryFileSet + : public cmGeneratorTarget::TargetPropertyEntry +{ +public: + TargetPropertyEntryFileSet( + std::vector<std::string> dirs, bool contextSensitiveDirs, + std::unique_ptr<cmCompiledGeneratorExpression> entryCge, + const cmFileSet* fileSet, cmLinkImplItem const& item = NoLinkImplItem) + : cmGeneratorTarget::TargetPropertyEntry(item) + , BaseDirs(std::move(dirs)) + , ContextSensitiveDirs(contextSensitiveDirs) + , EntryCge(std::move(entryCge)) + , FileSet(fileSet) + { + } + + const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config, + cmGeneratorTarget const* headTarget, + cmGeneratorExpressionDAGChecker* dagChecker, + std::string const& /*lang*/) const override + { + std::map<std::string, std::vector<std::string>> filesPerDir; + this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir, + this->EntryCge, lg, config, headTarget, + dagChecker); + + std::vector<std::string> files; + for (auto const& it : filesPerDir) { + files.insert(files.end(), it.second.begin(), it.second.end()); + } + + static std::string filesStr; + filesStr = cmJoin(files, ";"); + return filesStr; + } + + cmListFileBacktrace GetBacktrace() const override + { + return this->EntryCge->GetBacktrace(); + } + + std::string const& GetInput() const override + { + return this->EntryCge->GetInput(); + } + + bool GetHadContextSensitiveCondition() const override + { + return this->ContextSensitiveDirs || + this->EntryCge->GetHadContextSensitiveCondition(); + } + +private: + const std::vector<std::string> BaseDirs; + const bool ContextSensitiveDirs; + const std::unique_ptr<cmCompiledGeneratorExpression> EntryCge; + const cmFileSet* FileSet; +}; + +std::unique_ptr< + cmGeneratorTarget:: + TargetPropertyEntry> static CreateTargetPropertyEntry(const BT<std:: + string>& + propertyValue, + bool + evaluateForBuildsystem = + false) { if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) { cmGeneratorExpression ge(propertyValue.Backtrace); @@ -190,7 +256,7 @@ CreateTargetPropertyEntry(const BT<std::string>& propertyValue, cm::make_unique<TargetPropertyEntryString>(propertyValue)); } -void CreatePropertyGeneratorExpressions( +static void CreatePropertyGeneratorExpressions( cmBTStringRange entries, std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items, bool evaluateForBuildsystem = false) @@ -1589,6 +1655,80 @@ void AddObjectEntries(cmGeneratorTarget const* headTarget, } } +void addFileSetEntry(cmGeneratorTarget const* headTarget, + std::string const& config, + cmGeneratorExpressionDAGChecker* dagChecker, + cmFileSet const* fileSet, + EvaluatedTargetPropertyEntries& entries) +{ + auto dirCges = fileSet->CompileDirectoryEntries(); + auto dirs = fileSet->EvaluateDirectoryEntries( + dirCges, headTarget->GetLocalGenerator(), config, headTarget, dagChecker); + bool contextSensitiveDirs = false; + for (auto const& dirCge : dirCges) { + if (dirCge->GetHadContextSensitiveCondition()) { + contextSensitiveDirs = true; + break; + } + } + cmake* cm = headTarget->GetLocalGenerator()->GetCMakeInstance(); + for (auto& entryCge : fileSet->CompileFileEntries()) { + TargetPropertyEntryFileSet tpe(dirs, contextSensitiveDirs, + std::move(entryCge), fileSet); + entries.Entries.emplace_back( + EvaluateTargetPropertyEntry(headTarget, config, "", dagChecker, tpe)); + for (auto const& file : entries.Entries.back().Values) { + auto* sf = headTarget->Makefile->GetOrCreateSource(file); + if (fileSet->GetType() == "HEADERS"_s) { + sf->SetProperty("HEADER_FILE_ONLY", "TRUE"); + } + +#ifndef CMAKE_BOOTSTRAP + std::string e; + std::string w; + auto path = sf->ResolveFullPath(&e, &w); + if (!w.empty()) { + cm->IssueMessage(MessageType::AUTHOR_WARNING, w, + headTarget->GetBacktrace()); + } + if (path.empty()) { + if (!e.empty()) { + cm->IssueMessage(MessageType::FATAL_ERROR, e, + headTarget->GetBacktrace()); + } + return; + } + bool found = false; + for (auto const& sg : headTarget->Makefile->GetSourceGroups()) { + if (sg.MatchesFiles(path)) { + found = true; + break; + } + } + if (!found) { + if (fileSet->GetType() == "HEADERS"_s) { + headTarget->Makefile->GetOrCreateSourceGroup("Header Files") + ->AddGroupFile(path); + } + } +#endif + } + } +} + +void AddFileSetEntries(cmGeneratorTarget const* headTarget, + std::string const& config, + cmGeneratorExpressionDAGChecker* dagChecker, + EvaluatedTargetPropertyEntries& entries) +{ + for (auto const& entry : headTarget->Target->GetHeaderSetsEntries()) { + for (auto const& name : cmExpandedList(entry.Value)) { + auto const* headerSet = headTarget->Target->GetFileSet(name); + addFileSetEntry(headTarget, config, dagChecker, headerSet, entries); + } + } +} + bool processSources(cmGeneratorTarget const* tgt, EvaluatedTargetPropertyEntries& entries, std::vector<BT<std::string>>& srcs, @@ -1726,10 +1866,18 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths( uniqueSrcs, debugSources); } + // Collect this target's file sets. + std::vector<std::string>::size_type numFilesBefore3 = files.size(); + EvaluatedTargetPropertyEntries fileSetEntries; + AddFileSetEntries(this, config, &dagChecker, fileSetEntries); + bool contextDependentFileSets = + processSources(this, fileSetEntries, files, uniqueSrcs, debugSources); + // Determine if sources are context-dependent or not. if (!contextDependentDirectSources && !(contextDependentInterfaceSources && numFilesBefore < files.size()) && - !(contextDependentObjects && numFilesBefore2 < files.size())) { + !(contextDependentObjects && numFilesBefore2 < files.size()) && + !(contextDependentFileSets && numFilesBefore3 < files.size())) { this->SourcesAreContextDependent = Tribool::False; } else { this->SourcesAreContextDependent = Tribool::True; @@ -2926,11 +3074,11 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result, result); } -void processILibs(const std::string& config, - cmGeneratorTarget const* headTarget, cmLinkItem const& item, - cmGlobalGenerator* gg, - std::vector<cmGeneratorTarget const*>& tgts, - std::set<cmGeneratorTarget const*>& emitted) +static void processILibs(const std::string& config, + cmGeneratorTarget const* headTarget, + cmLinkItem const& item, cmGlobalGenerator* gg, + std::vector<cmGeneratorTarget const*>& tgts, + std::set<cmGeneratorTarget const*>& emitted) { if (item.Target && emitted.insert(item.Target).second) { tgts.push_back(item.Target); @@ -5708,7 +5856,7 @@ std::string valueAsString<std::nullptr_t>(std::nullptr_t /*unused*/) return "(unset)"; } -std::string compatibilityType(CompatibleType t) +static std::string compatibilityType(CompatibleType t) { switch (t) { case BoolType: @@ -5724,7 +5872,7 @@ std::string compatibilityType(CompatibleType t) return ""; } -std::string compatibilityAgree(CompatibleType t, bool dominant) +static std::string compatibilityAgree(CompatibleType t, bool dominant) { switch (t) { case BoolType: @@ -5814,23 +5962,23 @@ std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, return { lhs == rhs, lhs }; } -std::pair<bool, const char*> consistentStringProperty(const char* lhs, - const char* rhs) +static std::pair<bool, const char*> consistentStringProperty(const char* lhs, + const char* rhs) { const bool b = strcmp(lhs, rhs) == 0; return { b, b ? lhs : nullptr }; } -std::pair<bool, std::string> consistentStringProperty(const std::string& lhs, - const std::string& rhs) +static std::pair<bool, std::string> consistentStringProperty( + const std::string& lhs, const std::string& rhs) { const bool b = lhs == rhs; return { b, b ? lhs : valueAsString(nullptr) }; } -std::pair<bool, const char*> consistentNumberProperty(const char* lhs, - const char* rhs, - CompatibleType t) +static std::pair<bool, const char*> consistentNumberProperty(const char* lhs, + const char* rhs, + CompatibleType t) { char* pEnd; @@ -5881,9 +6029,9 @@ std::pair<bool, const char*> consistentProperty(const char* lhs, return { false, nullptr }; } -std::pair<bool, std::string> consistentProperty(const std::string& lhs, - const std::string& rhs, - CompatibleType t) +static std::pair<bool, std::string> consistentProperty(const std::string& lhs, + const std::string& rhs, + CompatibleType t) { const std::string null_ptr = valueAsString(nullptr); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ac283ab..38034d4 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -337,6 +337,12 @@ bool cmGlobalGenerator::CheckTargetsForType() const bool failed = false; for (const auto& generator : this->LocalGenerators) { for (const auto& target : generator->GetGeneratorTargets()) { + std::string systemName = + target->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"); + if (systemName.find("Windows") == std::string::npos) { + continue; + } + if (target->GetType() == cmStateEnums::EXECUTABLE) { std::vector<std::string> const& configs = target->Makefile->GetGeneratorConfigs( @@ -1027,6 +1033,54 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( break; } } + + if (compilerId == "LCC") { + switch (mf->GetPolicyStatus(cmPolicies::CMP0129)) { + case cmPolicies::WARN: + if (!this->CMakeInstance->GetIsInTryCompile() && + mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0129")) { + std::ostringstream w; + /* clang-format off */ + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0129) << "\n" + "Converting " << lang << + R"( compiler id "LCC" to "GNU" for compatibility.)" + ; + /* clang-format on */ + mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + // OLD behavior is to convert LCC to GNU. + mf->AddDefinition(compilerIdVar, "GNU"); + if (lang == "C") { + mf->AddDefinition("CMAKE_COMPILER_IS_GNUCC", "1"); + } else if (lang == "CXX") { + mf->AddDefinition("CMAKE_COMPILER_IS_GNUCXX", "1"); + } else if (lang == "Fortran") { + mf->AddDefinition("CMAKE_COMPILER_IS_GNUG77", "1"); + } + { + // Fix compiler versions. + std::string version = "CMAKE_" + lang + "_COMPILER_VERSION"; + std::string emulated = "CMAKE_" + lang + "_SIMULATE_VERSION"; + std::string emulatedId = "CMAKE_" + lang + "_SIMULATE_ID"; + std::string const& actual = mf->GetRequiredDefinition(emulated); + mf->AddDefinition(version, actual); + mf->RemoveDefinition(emulatedId); + mf->RemoveDefinition(emulated); + } + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0129)); + CM_FALLTHROUGH; + case cmPolicies::NEW: + // NEW behavior is to keep LCC. + break; + } + } } std::string cmGlobalGenerator::GetLanguageOutputExtension( @@ -1263,7 +1317,7 @@ void cmGlobalGenerator::Configure() // update the cache entry for the number of local generators, this is used // for progress char num[100]; - sprintf(num, "%d", static_cast<int>(this->Makefiles.size())); + snprintf(num, sizeof(num), "%d", static_cast<int>(this->Makefiles.size())); this->GetCMakeInstance()->AddCacheEntry("CMAKE_NUMBER_OF_MAKEFILES", num, "number of local generators", cmStateEnums::INTERNAL); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 3f6f55e..d5b5eb0 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -156,7 +156,7 @@ std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name) encoded += i; } else { char buf[16]; - sprintf(buf, ".%02x", static_cast<unsigned int>(i)); + snprintf(buf, sizeof(buf), ".%02x", static_cast<unsigned int>(i)); encoded += buf; } } diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index ec2e74f..f2ce83e 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -6,6 +6,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/Glob.hxx" +#include "cmsys/RegularExpression.hxx" #include "cmAlgorithms.h" #include "cmDocumentationEntry.h" @@ -109,6 +110,30 @@ static const char* VSVersionToToolset( return ""; } +static std::string VSVersionToMajorString( + cmGlobalVisualStudioGenerator::VSVersion v) +{ + switch (v) { + case cmGlobalVisualStudioGenerator::VS9: + return "9"; + case cmGlobalVisualStudioGenerator::VS10: + return "10"; + case cmGlobalVisualStudioGenerator::VS11: + return "11"; + case cmGlobalVisualStudioGenerator::VS12: + return "12"; + case cmGlobalVisualStudioGenerator::VS14: + return "14"; + case cmGlobalVisualStudioGenerator::VS15: + return "15"; + case cmGlobalVisualStudioGenerator::VS16: + return "16"; + case cmGlobalVisualStudioGenerator::VS17: + return "17"; + } + return ""; +} + static const char* VSVersionToAndroidToolset( cmGlobalVisualStudioGenerator::VSVersion v) { @@ -436,18 +461,30 @@ bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName( bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( std::string const& i, cmMakefile* mf) { - if (this->GeneratorInstance && i == *(this->GeneratorInstance)) { + if (this->LastGeneratorInstanceString && + i == *(this->LastGeneratorInstanceString)) { return true; } - if (!i.empty()) { - if (!this->vsSetupAPIHelper.SetVSInstance(i)) { + + if (!this->ParseGeneratorInstance(i, mf)) { + return false; + } + + if (!this->GeneratorInstanceVersion.empty()) { + std::string const majorStr = VSVersionToMajorString(this->Version); + cmsys::RegularExpression versionRegex( + cmStrCat("^", majorStr, "\\.[0-9]+\\.[0-9]+\\.[0-9]+$")); + if (!versionRegex.find(this->GeneratorInstanceVersion)) { std::ostringstream e; /* clang-format off */ e << "Generator\n" " " << this->GetName() << "\n" - "could not find specified instance of Visual Studio:\n" - " " << i; + "given instance specification\n" + " " << i << "\n" + "but the version field is not 4 integer components" + " starting in " << majorStr << "." + ; /* clang-format on */ mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; @@ -455,7 +492,29 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( } std::string vsInstance; - if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) { + if (!i.empty()) { + vsInstance = i; + if (!this->vsSetupAPIHelper.SetVSInstance( + this->GeneratorInstance, this->GeneratorInstanceVersion)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "could not find specified instance of Visual Studio:\n" + " " << i; + /* clang-format on */ + if (!this->GeneratorInstance.empty() && + this->GeneratorInstanceVersion.empty() && + cmSystemTools::FileIsDirectory(this->GeneratorInstance)) { + e << "\n" + "The directory exists, but the instance is not known to the " + "Visual Studio Installer, and no 'version=' field was given."; + } + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; + } + } else if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) { std::ostringstream e; /* clang-format off */ e << @@ -478,9 +537,93 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( // The selected instance may have a different MSBuild than previously found. this->MSBuildCommandInitialized = false; + this->LastGeneratorInstanceString = i; + + return true; +} + +bool cmGlobalVisualStudioVersionedGenerator::ParseGeneratorInstance( + std::string const& is, cmMakefile* mf) +{ + this->GeneratorInstance.clear(); + this->GeneratorInstanceVersion.clear(); + + std::vector<std::string> const fields = cmTokenize(is, ","); + std::vector<std::string>::const_iterator fi = fields.begin(); + if (fi == fields.end()) { + return true; + } + + // The first field may be the VS instance. + if (fi->find('=') == fi->npos) { + this->GeneratorInstance = *fi; + ++fi; + } + + std::set<std::string> handled; + + // The rest of the fields must be key=value pairs. + for (; fi != fields.end(); ++fi) { + std::string::size_type pos = fi->find('='); + if (pos == fi->npos) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "given instance specification\n" + " " << is << "\n" + "that contains a field after the first ',' with no '='." + ; + /* clang-format on */ + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; + } + std::string const key = fi->substr(0, pos); + std::string const value = fi->substr(pos + 1); + if (!handled.insert(key).second) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "given instance specification\n" + " " << is << "\n" + "that contains duplicate field key '" << key << "'." + ; + /* clang-format on */ + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; + } + if (!this->ProcessGeneratorInstanceField(key, value)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "given instance specification\n" + " " << is << "\n" + "that contains invalid field '" << *fi << "'." + ; + /* clang-format on */ + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; + } + } + return true; } +bool cmGlobalVisualStudioVersionedGenerator::ProcessGeneratorInstanceField( + std::string const& key, std::string const& value) +{ + if (key == "version") { + this->GeneratorInstanceVersion = value; + return true; + } + return false; +} + bool cmGlobalVisualStudioVersionedGenerator::GetVSInstance( std::string& dir) const { diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index b7760ac..54c38d9 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -65,6 +65,9 @@ protected: std::string GetWindows10SDKMaxVersionDefault(cmMakefile*) const override; + virtual bool ProcessGeneratorInstanceField(std::string const& key, + std::string const& value); + std::string FindMSBuildCommand() override; std::string FindDevEnvCommand() override; @@ -76,5 +79,10 @@ private: class Factory17; friend class Factory17; mutable cmVSSetupAPIHelper vsSetupAPIHelper; - cm::optional<std::string> GeneratorInstance; + + bool ParseGeneratorInstance(std::string const& is, cmMakefile* mf); + + std::string GeneratorInstance; + std::string GeneratorInstanceVersion; + cm::optional<std::string> LastGeneratorInstanceString; }; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index f34ef62..c8df0a7 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -833,8 +833,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateFlatClone(cmXCodeObject* orig) return obj; } -std::string GetGroupMapKeyFromPath(cmGeneratorTarget* target, - const std::string& fullpath) +static std::string GetGroupMapKeyFromPath(cmGeneratorTarget* target, + const std::string& fullpath) { std::string key(target->GetName()); key += "-"; diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index eaf88f6..52a411b 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -6,11 +6,13 @@ #include <cassert> #include <cstddef> #include <iterator> +#include <map> #include <set> #include <sstream> #include <utility> #include <cm/memory> +#include <cm/string_view> #include <cmext/string_view> #include "cmsys/Glob.hxx" @@ -18,11 +20,13 @@ #include "cmArgumentParser.h" #include "cmExecutionStatus.h" #include "cmExportSet.h" +#include "cmFileSet.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallCommandArguments.h" #include "cmInstallDirectoryGenerator.h" #include "cmInstallExportGenerator.h" +#include "cmInstallFileSetGenerator.h" #include "cmInstallFilesGenerator.h" #include "cmInstallGenerator.h" #include "cmInstallGetRuntimeDependenciesGenerator.h" @@ -89,6 +93,9 @@ public: bool MakeFilesFullPath(const char* modeName, const std::vector<std::string>& relFiles, std::vector<std::string>& absFiles); + bool MakeFilesFullPath(const char* modeName, const std::string& basePath, + const std::vector<std::string>& relFiles, + std::vector<std::string>& absFiles); bool CheckCMP0006(bool& failure) const; std::string GetDestination(const cmInstallCommandArguments* args, @@ -177,6 +184,19 @@ std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( args.GetDestination()); } +std::unique_ptr<cmInstallFileSetGenerator> CreateInstallFileSetGenerator( + Helper& helper, cmTarget& target, cmFileSet* fileSet, + const std::string& destination, const cmInstallCommandArguments& args) +{ + cmInstallGenerator::MessageLevel message = + cmInstallGenerator::SelectMessageLevel(helper.Makefile); + return cm::make_unique<cmInstallFileSetGenerator>( + target.GetName(), fileSet, destination, args.GetPermissions(), + args.GetConfigurations(), args.GetComponent(), message, + args.GetExcludeFromAll(), args.GetOptional(), + helper.Makefile->GetBacktrace()); +} + void AddInstallRuntimeDependenciesGenerator( Helper& helper, cmInstallRuntimeDependencySet* runtimeDependencySet, const cmInstallCommandArguments& runtimeArgs, @@ -390,6 +410,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args, std::vector<std::string> PrivateHeader; std::vector<std::string> PublicHeader; std::vector<std::string> Resource; + std::vector<std::vector<std::string>> FileSets; }; static auto const argHelper = @@ -403,7 +424,8 @@ bool HandleTargetsMode(std::vector<std::string> const& args, .Bind("INCLUDES"_s, &ArgVectors::Includes) .Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader) .Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader) - .Bind("RESOURCE"_s, &ArgVectors::Resource); + .Bind("RESOURCE"_s, &ArgVectors::Resource) + .Bind("FILE_SET"_s, &ArgVectors::FileSets); std::vector<std::string> genericArgVector; ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); @@ -442,6 +464,8 @@ bool HandleTargetsMode(std::vector<std::string> const& args, cmInstallCommandArguments publicHeaderArgs(helper.DefaultComponentName); cmInstallCommandArguments resourceArgs(helper.DefaultComponentName); cmInstallCommandIncludesArgument includesArgs; + std::vector<cmInstallCommandFileSetArguments> fileSetArgs( + argVectors.FileSets.size(), { helper.DefaultComponentName }); // now parse the args for specific parts of the target (e.g. LIBRARY, // RUNTIME, ARCHIVE etc. @@ -455,6 +479,15 @@ bool HandleTargetsMode(std::vector<std::string> const& args, publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs); resourceArgs.Parse(argVectors.Resource, &unknownArgs); includesArgs.Parse(&argVectors.Includes, &unknownArgs); + for (std::size_t i = 0; i < argVectors.FileSets.size(); i++) { + // We have to create a separate object for the parsing because + // cmArgumentParser<void>::Bind() binds to a specific address, but the + // objects in the vector can move around. So we parse in an object with a + // fixed address and then copy the data into the vector. + cmInstallCommandFileSetArguments fileSetArg(helper.DefaultComponentName); + fileSetArg.Parse(argVectors.FileSets[i], &unknownArgs); + fileSetArgs[i] = std::move(fileSetArg); + } if (!unknownArgs.empty()) { // Unknown argument. @@ -473,6 +506,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, privateHeaderArgs.SetGenericArguments(&genericArgs); publicHeaderArgs.SetGenericArguments(&genericArgs); resourceArgs.SetGenericArguments(&genericArgs); + for (auto& fileSetArg : fileSetArgs) { + fileSetArg.SetGenericArguments(&genericArgs); + } success = success && archiveArgs.Finalize(); success = success && libraryArgs.Finalize(); @@ -483,6 +519,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, success = success && privateHeaderArgs.Finalize(); success = success && publicHeaderArgs.Finalize(); success = success && resourceArgs.Finalize(); + for (auto& fileSetArg : fileSetArgs) { + success = success && fileSetArg.Finalize(); + } if (!success) { return false; @@ -493,7 +532,10 @@ bool HandleTargetsMode(std::vector<std::string> const& args, if (archiveArgs.GetNamelinkOnly() || runtimeArgs.GetNamelinkOnly() || objectArgs.GetNamelinkOnly() || frameworkArgs.GetNamelinkOnly() || bundleArgs.GetNamelinkOnly() || privateHeaderArgs.GetNamelinkOnly() || - publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly()) { + publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly() || + std::any_of(fileSetArgs.begin(), fileSetArgs.end(), + [](const cmInstallCommandFileSetArguments& fileSetArg) + -> bool { return fileSetArg.GetNamelinkOnly(); })) { status.SetError( "TARGETS given NAMELINK_ONLY option not in LIBRARY group. " "The NAMELINK_ONLY option may be specified only following LIBRARY."); @@ -502,7 +544,10 @@ bool HandleTargetsMode(std::vector<std::string> const& args, if (archiveArgs.GetNamelinkSkip() || runtimeArgs.GetNamelinkSkip() || objectArgs.GetNamelinkSkip() || frameworkArgs.GetNamelinkSkip() || bundleArgs.GetNamelinkSkip() || privateHeaderArgs.GetNamelinkSkip() || - publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip()) { + publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip() || + std::any_of(fileSetArgs.begin(), fileSetArgs.end(), + [](const cmInstallCommandFileSetArguments& fileSetArg) + -> bool { return fileSetArg.GetNamelinkSkip(); })) { status.SetError( "TARGETS given NAMELINK_SKIP option not in LIBRARY group. " "The NAMELINK_SKIP option may be specified only following LIBRARY."); @@ -515,7 +560,10 @@ bool HandleTargetsMode(std::vector<std::string> const& args, bundleArgs.HasNamelinkComponent() || privateHeaderArgs.HasNamelinkComponent() || publicHeaderArgs.HasNamelinkComponent() || - resourceArgs.HasNamelinkComponent()) { + resourceArgs.HasNamelinkComponent() || + std::any_of(fileSetArgs.begin(), fileSetArgs.end(), + [](const cmInstallCommandFileSetArguments& fileSetArg) + -> bool { return fileSetArg.HasNamelinkComponent(); })) { status.SetError( "TARGETS given NAMELINK_COMPONENT option not in LIBRARY group. " "The NAMELINK_COMPONENT option may be specified only following " @@ -531,12 +579,21 @@ bool HandleTargetsMode(std::vector<std::string> const& args, !libraryArgs.GetType().empty() || !runtimeArgs.GetType().empty() || !objectArgs.GetType().empty() || !frameworkArgs.GetType().empty() || !bundleArgs.GetType().empty() || !privateHeaderArgs.GetType().empty() || - !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty()) { + !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty() || + std::any_of(fileSetArgs.begin(), fileSetArgs.end(), + [](const cmInstallCommandFileSetArguments& fileSetArg) + -> bool { return !fileSetArg.GetType().empty(); })) { status.SetError( "TARGETS given TYPE option. The TYPE option may only be specified in " " install(FILES) and install(DIRECTORIES)."); return false; } + if (std::any_of(fileSetArgs.begin(), fileSetArgs.end(), + [](const cmInstallCommandFileSetArguments& fileSetArg) + -> bool { return fileSetArg.GetFileSet().empty(); })) { + status.SetError("TARGETS given FILE_SET option without file set name."); + return false; + } cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr; if (withRuntimeDependencies) { @@ -647,6 +704,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args, bool installsPrivateHeader = false; bool installsPublicHeader = false; bool installsResource = false; + std::vector<bool> installsFileSet(fileSetArgs.size(), false); // Generate install script code to install the given targets. for (cmTarget* ti : targets) { @@ -662,6 +720,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args, std::unique_ptr<cmInstallFilesGenerator> privateHeaderGenerator; std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator; std::unique_ptr<cmInstallFilesGenerator> resourceGenerator; + std::vector<std::unique_ptr<cmInstallFileSetGenerator>> fileSetGenerators; // Avoid selecting default destinations for PUBLIC_HEADER and // PRIVATE_HEADER if any artifacts are specified. @@ -670,9 +729,24 @@ bool HandleTargetsMode(std::vector<std::string> const& args, // Track whether this is a namelink-only rule. bool namelinkOnly = false; - auto addTargetExport = [&]() { + auto addTargetExport = [&]() -> bool { // Add this install rule to an export if one was specified. if (!exports.empty()) { + auto interfaceFileSets = target.GetAllInterfaceFileSets(); + if (std::any_of( + interfaceFileSets.begin(), interfaceFileSets.end(), + [=](const std::string& name) -> bool { + return !std::any_of( + fileSetArgs.begin(), fileSetArgs.end(), + [=](const cmInstallCommandFileSetArguments& fileSetArg) + -> bool { return fileSetArg.GetFileSet() == name; }); + })) { + status.SetError(cmStrCat( + "TARGETS target ", target.GetName(), + " is exported but not all of its file sets are installed")); + return false; + } + auto te = cm::make_unique<cmTargetExport>(); te->TargetName = target.GetName(); te->ArchiveGenerator = archiveGenerator.get(); @@ -682,6 +756,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, te->LibraryGenerator = libraryGenerator.get(); te->RuntimeGenerator = runtimeGenerator.get(); te->ObjectsGenerator = objectGenerator.get(); + for (auto const& gen : fileSetGenerators) { + te->FileSetGenerators[gen->GetFileSet()] = gen.get(); + } target.AddInstallIncludeDirectories( cmMakeRange(includesArgs.GetIncludeDirs())); te->NamelinkOnly = namelinkOnly; @@ -689,6 +766,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args, ->GetExportSets()[exports] .AddTargetExport(std::move(te)); } + return true; }; switch (target.GetType()) { @@ -700,7 +778,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, // When in namelink only mode skip all libraries on Windows. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { namelinkOnly = true; - addTargetExport(); + if (!addTargetExport()) { + return false; + } continue; } @@ -736,7 +816,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, // When in namelink only mode skip frameworks. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { namelinkOnly = true; - addTargetExport(); + if (!addTargetExport()) { + return false; + } continue; } @@ -785,7 +867,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, // When in namelink only mode skip frameworks. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { namelinkOnly = true; - addTargetExport(); + if (!addTargetExport()) { + return false; + } continue; } @@ -942,9 +1026,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, helper.GetIncludeDestination(&privateHeaderArgs)); } else { std::ostringstream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " + e << "Target " << target.GetName() << " has " << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION."; - cmSystemTools::Message(e.str(), "Warning"); + helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } } @@ -964,9 +1048,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, helper.GetIncludeDestination(&publicHeaderArgs)); } else { std::ostringstream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " + e << "Target " << target.GetName() << " has " << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION."; - cmSystemTools::Message(e.str(), "Warning"); + helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } } @@ -983,16 +1067,47 @@ bool HandleTargetsMode(std::vector<std::string> const& args, resourceGenerator = CreateInstallFilesGenerator( helper.Makefile, absFiles, resourceArgs, false); } else if (!target.IsAppBundleOnApple()) { - cmSystemTools::Message( - cmStrCat("INSTALL TARGETS - target ", target.GetName(), - " has RESOURCE files but no RESOURCE DESTINATION."), - "Warning"); + helper.Makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat("Target ", target.GetName(), + " has RESOURCE files but no RESOURCE DESTINATION.")); + } + } + } + + if (!namelinkOnly) { + for (std::size_t i = 0; i < fileSetArgs.size(); i++) { + auto* fileSet = target.GetFileSet(fileSetArgs[i].GetFileSet()); + auto interfaceFileSetEntries = cmExpandedList(target.GetSafeProperty( + cmTarget::GetInterfaceFileSetsPropertyName(fileSet->GetType()))); + if (fileSet && + std::find( + interfaceFileSetEntries.begin(), interfaceFileSetEntries.end(), + fileSetArgs[i].GetFileSet()) != interfaceFileSetEntries.end()) { + std::string destination; + if (fileSet->GetType() == "HEADERS"_s) { + destination = helper.GetIncludeDestination(&fileSetArgs[i]); + } else { + destination = fileSetArgs[i].GetDestination(); + if (destination.empty()) { + status.SetError( + cmStrCat("TARGETS given no FILE_SET DESTINATION for target \"", + target.GetName(), "\" file set \"", + fileSet->GetName(), "\".")); + return false; + } + } + fileSetGenerators.push_back(CreateInstallFileSetGenerator( + helper, target, fileSet, destination, fileSetArgs[i])); + installsFileSet[i] = true; } } } // Add this install rule to an export if one was specified. - addTargetExport(); + if (!addTargetExport()) { + return false; + } // Keep track of whether we're installing anything in each category installsArchive = installsArchive || archiveGenerator; @@ -1016,6 +1131,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args, helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator)); helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator)); helper.Makefile->AddInstallGenerator(std::move(resourceGenerator)); + for (auto& gen : fileSetGenerators) { + helper.Makefile->AddInstallGenerator(std::move(gen)); + } } if (withRuntimeDependencies && !runtimeDependencySet->Empty()) { @@ -1067,6 +1185,12 @@ bool HandleTargetsMode(std::vector<std::string> const& args, helper.Makefile->GetGlobalGenerator()->AddInstallComponent( resourceArgs.GetComponent()); } + for (std::size_t i = 0; i < fileSetArgs.size(); i++) { + if (installsFileSet[i]) { + helper.Makefile->GetGlobalGenerator()->AddInstallComponent( + fileSetArgs[i].GetComponent()); + } + } return true; } @@ -2063,12 +2187,20 @@ bool Helper::MakeFilesFullPath(const char* modeName, const std::vector<std::string>& relFiles, std::vector<std::string>& absFiles) { + return this->MakeFilesFullPath( + modeName, this->Makefile->GetCurrentSourceDirectory(), relFiles, absFiles); +} + +bool Helper::MakeFilesFullPath(const char* modeName, + const std::string& basePath, + const std::vector<std::string>& relFiles, + std::vector<std::string>& absFiles) +{ for (std::string const& relFile : relFiles) { std::string file = relFile; std::string::size_type gpos = cmGeneratorExpression::Find(file); if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) { - file = - cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', relFile); + file = cmStrCat(basePath, '/', relFile); } // Make sure the file is not a directory. diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index cc3df2a..7309316 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -152,6 +152,11 @@ const std::string& cmInstallCommandArguments::GetType() const return this->Type; } +const std::string& cmInstallCommandArguments::GetDefaultComponent() const +{ + return this->DefaultComponentName; +} + const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations() const { @@ -220,3 +225,17 @@ void cmInstallCommandIncludesArgument::Parse( this->IncludeDirs.push_back(std::move(dir)); } } + +cmInstallCommandFileSetArguments::cmInstallCommandFileSetArguments( + std::string defaultComponent) + : cmInstallCommandArguments(std::move(defaultComponent)) +{ + this->Bind("FILE_SET"_s, this->FileSet); +} + +void cmInstallCommandFileSetArguments::Parse( + std::vector<std::string> args, std::vector<std::string>* unconsumedArgs) +{ + args.insert(args.begin(), "FILE_SET"); + this->cmInstallCommandArguments::Parse(args, unconsumedArgs); +} diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h index f318a1a..79bd945 100644 --- a/Source/cmInstallCommandArguments.h +++ b/Source/cmInstallCommandArguments.h @@ -34,6 +34,8 @@ public: bool HasNamelinkComponent() const; const std::string& GetType() const; + const std::string& GetDefaultComponent() const; + static bool CheckPermissions(const std::string& onePerm, std::string& perm); private: @@ -71,3 +73,17 @@ public: private: std::vector<std::string> IncludeDirs; }; + +class cmInstallCommandFileSetArguments : public cmInstallCommandArguments +{ +public: + cmInstallCommandFileSetArguments(std::string defaultComponent); + + void Parse(std::vector<std::string> args, + std::vector<std::string>* unconsumedArgs); + + const std::string& GetFileSet() const { return this->FileSet; } + +private: + std::string FileSet; +}; diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index d932fd9..820f24a 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -85,7 +85,9 @@ void cmInstallExportGenerator::ComputeTempDir() } if (useMD5) { // Replace the destination path with a hash to keep it short. +#ifndef CMAKE_BOOTSTRAP this->TempDir += cmSystemTools::ComputeStringMD5(this->Destination); +#endif } else { std::string dest = this->Destination; // Avoid unix full paths. diff --git a/Source/cmInstallFileSetGenerator.cxx b/Source/cmInstallFileSetGenerator.cxx new file mode 100644 index 0000000..7121ea3 --- /dev/null +++ b/Source/cmInstallFileSetGenerator.cxx @@ -0,0 +1,88 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmInstallFileSetGenerator.h" + +#include <map> +#include <string> +#include <utility> +#include <vector> + +#include "cmFileSet.h" +#include "cmGeneratorExpression.h" +#include "cmGlobalGenerator.h" +#include "cmInstallType.h" +#include "cmLocalGenerator.h" +#include "cmStringAlgorithms.h" + +cmInstallFileSetGenerator::cmInstallFileSetGenerator( + std::string targetName, cmFileSet* fileSet, std::string const& dest, + std::string file_permissions, std::vector<std::string> const& configurations, + std::string const& component, MessageLevel message, bool exclude_from_all, + bool optional, cmListFileBacktrace backtrace) + : cmInstallGenerator(dest, configurations, component, message, + exclude_from_all, false, std::move(backtrace)) + , TargetName(std::move(targetName)) + , FileSet(fileSet) + , FilePermissions(std::move(file_permissions)) + , Optional(optional) +{ + this->ActionsPerConfig = true; +} + +cmInstallFileSetGenerator::~cmInstallFileSetGenerator() = default; + +bool cmInstallFileSetGenerator::Compute(cmLocalGenerator* lg) +{ + this->LocalGenerator = lg; + + // Lookup this target in the current directory. + this->Target = lg->FindLocalNonAliasGeneratorTarget(this->TargetName); + if (!this->Target) { + // If no local target has been found, find it in the global scope. + this->Target = + lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName); + } + + return true; +} + +std::string cmInstallFileSetGenerator::GetDestination( + std::string const& config) const +{ + return cmGeneratorExpression::Evaluate(this->Destination, + this->LocalGenerator, config); +} + +void cmInstallFileSetGenerator::GenerateScriptForConfig( + std::ostream& os, const std::string& config, Indent indent) +{ + for (auto const& dirEntry : this->CalculateFilesPerDir(config)) { + std::string destSub; + if (!dirEntry.first.empty()) { + destSub = cmStrCat('/', dirEntry.first); + } + this->AddInstallRule(os, cmStrCat(this->GetDestination(config), destSub), + cmInstallType_FILES, dirEntry.second, + this->GetOptional(), this->FilePermissions.c_str(), + nullptr, nullptr, nullptr, indent); + } +} + +std::map<std::string, std::vector<std::string>> +cmInstallFileSetGenerator::CalculateFilesPerDir( + const std::string& config) const +{ + std::map<std::string, std::vector<std::string>> result; + + auto dirCges = this->FileSet->CompileDirectoryEntries(); + auto dirs = this->FileSet->EvaluateDirectoryEntries( + dirCges, this->LocalGenerator, config, this->Target); + + auto fileCges = this->FileSet->CompileFileEntries(); + for (auto const& fileCge : fileCges) { + this->FileSet->EvaluateFileEntry( + dirs, result, fileCge, this->LocalGenerator, config, this->Target); + } + + return result; +} diff --git a/Source/cmInstallFileSetGenerator.h b/Source/cmInstallFileSetGenerator.h new file mode 100644 index 0000000..8d067d9 --- /dev/null +++ b/Source/cmInstallFileSetGenerator.h @@ -0,0 +1,52 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include <iosfwd> +#include <map> +#include <string> +#include <vector> + +#include "cmInstallGenerator.h" +#include "cmListFileCache.h" +#include "cmScriptGenerator.h" + +class cmGeneratorTarget; +class cmFileSet; +class cmLocalGenerator; + +class cmInstallFileSetGenerator : public cmInstallGenerator +{ +public: + cmInstallFileSetGenerator(std::string targetName, cmFileSet* fileSet, + std::string const& dest, + std::string file_permissions, + std::vector<std::string> const& configurations, + std::string const& component, MessageLevel message, + bool exclude_from_all, bool optional, + cmListFileBacktrace backtrace); + ~cmInstallFileSetGenerator() override; + + bool Compute(cmLocalGenerator* lg) override; + + std::string GetDestination(std::string const& config) const; + std::string GetDestination() const { return this->Destination; } + bool GetOptional() const { return this->Optional; } + cmFileSet* GetFileSet() const { return this->FileSet; } + cmGeneratorTarget* GetTarget() const { return this->Target; } + +protected: + void GenerateScriptForConfig(std::ostream& os, const std::string& config, + Indent indent) override; + +private: + std::string TargetName; + cmLocalGenerator* LocalGenerator; + cmFileSet* const FileSet; + std::string const FilePermissions; + bool const Optional; + cmGeneratorTarget* Target; + + std::map<std::string, std::vector<std::string>> CalculateFilesPerDir( + const std::string& config) const; +}; diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 7d42fc8..b358327 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -155,7 +155,7 @@ bool HandleLengthCommand(std::vector<std::string> const& args, GetList(varArgsExpanded, listName, status.GetMakefile()); size_t length = varArgsExpanded.size(); char buffer[1024]; - sprintf(buffer, "%d", static_cast<int>(length)); + snprintf(buffer, sizeof(buffer), "%d", static_cast<int>(length)); status.GetMakefile().AddDefinition(variableName, buffer); return true; diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 2456db9..2080b40 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -44,6 +44,7 @@ namespace { const char* LastName = nullptr; +extern "C" void TrapsForSignals(int sig); extern "C" void TrapsForSignals(int sig) { fprintf(stderr, "CMake loaded command %s crashed with signal: %d.\n", diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 9b6b9abe..3a4c386 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2831,7 +2831,10 @@ void cmLocalGenerator::IncludeFileInUnitySources( unity_file << "/* " << pathToHash << " */\n" << "#undef " << *uniqueIdName << "\n" << "#define " << *uniqueIdName << " unity_" - << cmSystemTools::ComputeStringMD5(pathToHash) << "\n"; +#ifndef CMAKE_BOOTSTRAP + << cmSystemTools::ComputeStringMD5(pathToHash) << "\n" +#endif + ; } if (beforeInclude) { @@ -3505,7 +3508,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName( bool done; int cc = 0; char rpstr[100]; - sprintf(rpstr, "_p_"); + snprintf(rpstr, sizeof(rpstr), "_p_"); cmSystemTools::ReplaceString(ssin, "+", rpstr); std::string sssin = sin; do { @@ -3521,7 +3524,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName( } sssin = ssin; cmSystemTools::ReplaceString(ssin, "_p_", rpstr); - sprintf(rpstr, "_p%d_", cc++); + snprintf(rpstr, sizeof(rpstr), "_p%d_", cc++); } while (!done); } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 7e39b91..2700ded 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1279,7 +1279,7 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable( // it is used then add number to the end of the variable while (this->ShortMakeVariableMap.count(ret) && ni < 1000) { ++ni; - sprintf(buffer, "%04d", ni); + snprintf(buffer, sizeof(buffer), "%04d", ni); ret = unmodified + buffer; } this->ShortMakeVariableMap[ret] = "1"; @@ -1304,11 +1304,11 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable( } char buffer[5]; int ni = 0; - sprintf(buffer, "%04d", ni); + snprintf(buffer, sizeof(buffer), "%04d", ni); ret = str1 + str2 + buffer; while (this->ShortMakeVariableMap.count(ret) && ni < 1000) { ++ni; - sprintf(buffer, "%04d", ni); + snprintf(buffer, sizeof(buffer), "%04d", ni); ret = str1 + str2 + buffer; } if (ni == 1000) { diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx index 53112e0..4fcaedf 100644 --- a/Source/cmMachO.cxx +++ b/Source/cmMachO.cxx @@ -56,7 +56,7 @@ bool peek(cmsys::ifstream& fin, T& v) template <typename T> bool read(cmsys::ifstream& fin, T& v) { - return !!fin.read(reinterpret_cast<char*>(&v), sizeof(T)); + return static_cast<bool>(fin.read(reinterpret_cast<char*>(&v), sizeof(T))); } // read from the file and fill multiple data structures where @@ -68,7 +68,8 @@ bool read(cmsys::ifstream& fin, std::vector<T>& v) if (v.empty()) { return true; } - return !!fin.read(reinterpret_cast<char*>(&v[0]), sizeof(T) * v.size()); + return static_cast<bool>( + fin.read(reinterpret_cast<char*>(&v[0]), sizeof(T) * v.size())); } } @@ -340,7 +341,8 @@ bool cmMachO::GetInstallName(std::string& install_name) if (lc_cmd == LC_ID_DYLIB || lc_cmd == LC_LOAD_WEAK_DYLIB || lc_cmd == LC_LOAD_DYLIB) { if (sizeof(dylib_command) < cmd.LoadCommand.size()) { - uint32_t namelen = cmd.LoadCommand.size() - sizeof(dylib_command); + uint32_t namelen = static_cast<uint32_t>(cmd.LoadCommand.size() - + sizeof(dylib_command)); install_name.assign(&cmd.LoadCommand[sizeof(dylib_command)], namelen); return true; } diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 8c4b2a7..154df63 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -77,7 +77,7 @@ bool cmMacroHelperCommand::operator()( argVs.reserve(expandedArgs.size()); char argvName[60]; for (unsigned int j = 0; j < expandedArgs.size(); ++j) { - sprintf(argvName, "${ARGV%u}", j); + snprintf(argvName, sizeof(argvName), "${ARGV%u}", j); argVs.emplace_back(argvName); } // Invoke all the functions that were collected in the block. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 23b97ed..bf3e217 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -134,8 +134,8 @@ cmDirectoryId cmMakefile::GetDirectoryId() const // If we ever need to expose this to CMake language code we should // add a read-only property in cmMakefile::GetProperty. char buf[32]; - sprintf(buf, "(%p)", - static_cast<void const*>(this)); // cast avoids format warning + snprintf(buf, sizeof(buf), "(%p)", + static_cast<void const*>(this)); // cast avoids format warning return std::string(buf); } diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 9f2ae19..4e5913e 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -2176,7 +2176,7 @@ void cmMakefileTargetGenerator::CreateObjectLists( for (unsigned int i = 0; i < object_strings.size(); ++i) { // Number the response files. char rsp[32]; - sprintf(rsp, "objects%u.rsp", i + 1); + snprintf(rsp, sizeof(rsp), "objects%u.rsp", i + 1); // Create this response file. std::string objects_rsp = diff --git a/Source/cmMathCommand.cxx b/Source/cmMathCommand.cxx index 56221bf..df9ebcf 100644 --- a/Source/cmMathCommand.cxx +++ b/Source/cmMathCommand.cxx @@ -107,7 +107,7 @@ bool HandleExprCommand(std::vector<std::string> const& args, fmt = "%" KWIML_INT_PRId64; break; } - sprintf(buffer, fmt, helper.GetResult()); + snprintf(buffer, sizeof(buffer), fmt, helper.GetResult()); std::string const& w = helper.GetWarning(); if (!w.empty()) { diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index 1cb638a..b898d22 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -102,7 +102,7 @@ static int getMessageColor(MessageType t) } } -void printMessageText(std::ostream& msg, std::string const& text) +static void printMessageText(std::ostream& msg, std::string const& text) { msg << ":\n"; cmDocumentationFormatter formatter; @@ -110,7 +110,7 @@ void printMessageText(std::ostream& msg, std::string const& text) formatter.PrintFormatted(msg, text.c_str()); } -void displayMessage(MessageType t, std::ostringstream& msg) +static void displayMessage(MessageType t, std::ostringstream& msg) { // Add a note about warning suppression. if (t == MessageType::AUTHOR_WARNING) { diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 2b785e1..02b4821 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -219,10 +219,11 @@ std::string cmOutputConverter::EscapeForShell( return Shell_GetArgument(str, flags); } -std::string cmOutputConverter::EscapeForCMake(cm::string_view str) +std::string cmOutputConverter::EscapeForCMake(cm::string_view str, + WrapQuotes wrapQuotes) { // Always double-quote the argument to take care of most escapes. - std::string result = "\""; + std::string result = (wrapQuotes == WrapQuotes::Wrap) ? "\"" : ""; for (const char c : str) { if (c == '"') { // Escape the double quote to avoid ending the argument. @@ -238,7 +239,9 @@ std::string cmOutputConverter::EscapeForCMake(cm::string_view str) result += c; } } - result += "\""; + if (wrapQuotes == WrapQuotes::Wrap) { + result += "\""; + } return result; } diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 865df71..53ec247 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -94,7 +94,13 @@ public: bool forEcho = false, bool useWatcomQuote = false, bool unescapeNinjaConfiguration = false) const; - static std::string EscapeForCMake(cm::string_view str); + enum class WrapQuotes + { + Wrap, + NoWrap, + }; + static std::string EscapeForCMake(cm::string_view str, + WrapQuotes wrapQuotes = WrapQuotes::Wrap); /** Compute an escaped version of the given argument for use in a windows shell. */ diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 23000fa..e31de1c 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -103,7 +103,7 @@ static bool isPolicyNewerThan(cmPolicies::PolicyID id, unsigned int majorV, return false; } -const char* idToShortDescription(cmPolicies::PolicyID id) +static const char* idToShortDescription(cmPolicies::PolicyID id) { switch (id) { #define POLICY_CASE(ID, SHORT_DESCRIPTION) \ diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index ce04117..99e2eb6 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -385,7 +385,10 @@ class cmMakefile; 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0128, \ "Selection of language standard and extension flags improved.", 3, \ - 22, 0, cmPolicies::WARN) + 22, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0129, \ + "Compiler id for MCST LCC compilers is now LCC, not GNU.", 3, 23, 0, \ + cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 20fcdbe..04d99c9 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -235,14 +235,15 @@ bool cmProjectCommand(std::vector<std::string> const& args, std::array<std::string, MAX_VERSION_COMPONENTS> version_components; if (cmp0096 == cmPolicies::OLD || cmp0096 == cmPolicies::WARN) { - char vb[MAX_VERSION_COMPONENTS] - [std::numeric_limits<unsigned>::digits10 + 2]; + constexpr size_t maxIntLength = + std::numeric_limits<unsigned>::digits10 + 2; + char vb[MAX_VERSION_COMPONENTS][maxIntLength]; unsigned v[MAX_VERSION_COMPONENTS] = { 0, 0, 0, 0 }; const int vc = std::sscanf(version.c_str(), "%u.%u.%u.%u", &v[0], &v[1], &v[2], &v[3]); for (auto i = 0u; i < MAX_VERSION_COMPONENTS; ++i) { if (int(i) < vc) { - std::sprintf(vb[i], "%u", v[i]); + std::snprintf(vb[i], maxIntLength, "%u", v[i]); version_string += &"."[std::size_t(i == 0)]; version_string += vb[i]; version_components[i] = vb[i]; diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index 9584e5c..0a394b5 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -22,10 +22,10 @@ /// @brief Merges newOpts into baseOpts /// @arg valueOpts list of options that accept a value -void MergeOptions(std::vector<std::string>& baseOpts, - std::vector<std::string> const& newOpts, - std::initializer_list<cm::string_view> valueOpts, - bool isQt5OrLater) +static void MergeOptions(std::vector<std::string>& baseOpts, + std::vector<std::string> const& newOpts, + std::initializer_list<cm::string_view> valueOpts, + bool isQt5OrLater) { if (newOpts.empty()) { return; diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index fce6e80..1e4dedd 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -35,6 +35,7 @@ cmRST::cmRST(std::ostream& os, std::string docroot) , TocTreeDirective("^.. toctree::[ \t]*(.*)$") , ProductionListDirective("^.. productionlist::[ \t]*(.*)$") , NoteDirective("^.. note::[ \t]*(.*)$") + , VersionDirective("^.. version(added|changed)::[ \t]*(.*)$") , ModuleRST(R"(^#\[(=*)\[\.rst:$)") , CMakeRole("(:cmake)?:(" "command|cpack_gen|generator|genex|" @@ -209,6 +210,10 @@ void cmRST::ProcessLine(std::string const& line) } else if (this->NoteDirective.find(line)) { // Output note directives and their content normally. this->NormalLine(line); + } else if (this->VersionDirective.find(line)) { + // Output versionadded and versionchanged directives and their content + // normally. + this->NormalLine(line); } } // An explicit markup start followed nothing but whitespace and a diff --git a/Source/cmRST.h b/Source/cmRST.h index 17cdfe8..156b20a 100644 --- a/Source/cmRST.h +++ b/Source/cmRST.h @@ -83,6 +83,7 @@ private: cmsys::RegularExpression TocTreeDirective; cmsys::RegularExpression ProductionListDirective; cmsys::RegularExpression NoteDirective; + cmsys::RegularExpression VersionDirective; cmsys::RegularExpression ModuleRST; cmsys::RegularExpression CMakeRole; cmsys::RegularExpression InlineLink; diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index f44fcf7..e5935b8 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -526,7 +526,7 @@ bool HandleLengthCommand(std::vector<std::string> const& args, size_t length = stringValue.size(); char buffer[1024]; - sprintf(buffer, "%d", static_cast<int>(length)); + snprintf(buffer, sizeof(buffer), "%d", static_cast<int>(length)); status.GetMakefile().AddDefinition(variableName, buffer); return true; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 75a5a8d..1b07358 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1158,39 +1158,26 @@ void cmSystemTools::MoveFileIfDifferent(const std::string& source, RemoveFile(source); } +#ifndef CMAKE_BOOTSTRAP std::string cmSystemTools::ComputeFileHash(const std::string& source, cmCryptoHash::Algo algo) { -#if !defined(CMAKE_BOOTSTRAP) cmCryptoHash hash(algo); return hash.HashFile(source); -#else - (void)source; - cmSystemTools::Message("hashsum not supported in bootstrapping mode", - "Error"); - return std::string(); -#endif } std::string cmSystemTools::ComputeStringMD5(const std::string& input) { -#if !defined(CMAKE_BOOTSTRAP) cmCryptoHash md5(cmCryptoHash::AlgoMD5); return md5.HashString(input); -#else - (void)input; - cmSystemTools::Message("md5sum not supported in bootstrapping mode", - "Error"); - return ""; -#endif } +# ifdef _WIN32 std::string cmSystemTools::ComputeCertificateThumbprint( const std::string& source) { std::string thumbprint; -#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) CRYPT_INTEGER_BLOB cryptBlob; HCERTSTORE certStore = NULL; PCCERT_CONTEXT certContext = NULL; @@ -1247,14 +1234,11 @@ std::string cmSystemTools::ComputeCertificateThumbprint( } CloseHandle(certFile); } -#else - (void)source; - cmSystemTools::Message("ComputeCertificateThumbprint is not implemented", - "Error"); -#endif return thumbprint; } +# endif +#endif void cmSystemTools::Glob(const std::string& directory, const std::string& regexp, @@ -1693,7 +1677,8 @@ void list_item_verbose(FILE* out, struct archive_entry* entry) /* Use uname if it's present, else uid. */ p = archive_entry_uname(entry); if ((p == nullptr) || (*p == '\0')) { - sprintf(tmp, "%lu ", static_cast<unsigned long>(archive_entry_uid(entry))); + snprintf(tmp, sizeof(tmp), "%lu ", + static_cast<unsigned long>(archive_entry_uid(entry))); p = tmp; } w = strlen(p); @@ -1707,7 +1692,8 @@ void list_item_verbose(FILE* out, struct archive_entry* entry) fprintf(out, "%s", p); w = strlen(p); } else { - sprintf(tmp, "%lu", static_cast<unsigned long>(archive_entry_gid(entry))); + snprintf(tmp, sizeof(tmp), "%lu", + static_cast<unsigned long>(archive_entry_gid(entry))); w = strlen(tmp); fprintf(out, "%s", tmp); } @@ -1721,15 +1707,15 @@ void list_item_verbose(FILE* out, struct archive_entry* entry) archive_entry_filetype(entry) == AE_IFBLK) { unsigned long rdevmajor = archive_entry_rdevmajor(entry); unsigned long rdevminor = archive_entry_rdevminor(entry); - sprintf(tmp, "%lu,%lu", rdevmajor, rdevminor); + snprintf(tmp, sizeof(tmp), "%lu,%lu", rdevmajor, rdevminor); } else { /* * Note the use of platform-dependent macros to format * the filesize here. We need the format string and the * corresponding type for the cast. */ - sprintf(tmp, BSDTAR_FILESIZE_PRINTF, - static_cast<BSDTAR_FILESIZE_TYPE>(archive_entry_size(entry))); + snprintf(tmp, sizeof(tmp), BSDTAR_FILESIZE_PRINTF, + static_cast<BSDTAR_FILESIZE_TYPE>(archive_entry_size(entry))); } if (w + strlen(tmp) >= gs_width) { gs_width = w + strlen(tmp) + 1; @@ -2496,8 +2482,8 @@ bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath, return false; } -std::string::size_type cmSystemToolsFindRPath(cm::string_view const& have, - cm::string_view const& want) +static std::string::size_type cmSystemToolsFindRPath( + cm::string_view const& have, cm::string_view const& want) { std::string::size_type pos = 0; while (pos < have.size()) { @@ -2694,11 +2680,11 @@ std::function<bool(std::string*, const cmELF&)> MakeEmptyCallback( } } -cm::optional<bool> ChangeRPathELF(std::string const& file, - std::string const& oldRPath, - std::string const& newRPath, - bool removeEnvironmentRPath, - std::string* emsg, bool* changed) +static cm::optional<bool> ChangeRPathELF(std::string const& file, + std::string const& oldRPath, + std::string const& newRPath, + bool removeEnvironmentRPath, + std::string* emsg, bool* changed) { auto adjustCallback = [oldRPath, newRPath, removeEnvironmentRPath]( cm::optional<std::string>& outRPath, @@ -3289,7 +3275,7 @@ std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes) case ' ': case '=': case '%': - sprintf(hexCh, "%%%02X", static_cast<int>(c)); + snprintf(hexCh, sizeof(hexCh), "%%%02X", static_cast<int>(c)); break; case '/': if (escapeSlashes) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 715724c..19dabe8 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -179,6 +179,7 @@ public: static void MoveFileIfDifferent(const std::string& source, const std::string& destination); +#ifndef CMAKE_BOOTSTRAP //! Compute the hash of a file static std::string ComputeFileHash(const std::string& source, cmCryptoHash::Algo algo); @@ -186,8 +187,11 @@ public: /** Compute the md5sum of a string. */ static std::string ComputeStringMD5(const std::string& input); +# ifdef _WIN32 //! Get the SHA thumbprint for a certificate file static std::string ComputeCertificateThumbprint(const std::string& source); +# endif +#endif /** * Run a single executable command diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 97d60cf..4f0dc60 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -14,11 +14,13 @@ #include <cm/memory> #include <cmext/algorithm> +#include <cmext/string_view> #include "cmsys/RegularExpression.hxx" #include "cmAlgorithms.h" #include "cmCustomCommand.h" +#include "cmFileSet.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -200,8 +202,11 @@ public: std::vector<BT<std::string>> LinkOptionsEntries; std::vector<BT<std::string>> LinkDirectoriesEntries; std::vector<BT<std::string>> LinkImplementationPropertyEntries; + std::vector<BT<std::string>> HeaderSetsEntries; + std::vector<BT<std::string>> InterfaceHeaderSetsEntries; std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>> TLLCommands; + std::map<std::string, cmFileSet> FileSets; cmListFileBacktrace Backtrace; bool CheckImportedLibName(std::string const& prop, @@ -1110,6 +1115,16 @@ cmBTStringRange cmTarget::GetLinkImplementationEntries() const return cmMakeRange(this->impl->LinkImplementationPropertyEntries); } +cmBTStringRange cmTarget::GetHeaderSetsEntries() const +{ + return cmMakeRange(this->impl->HeaderSetsEntries); +} + +cmBTStringRange cmTarget::GetInterfaceHeaderSetsEntries() const +{ + return cmMakeRange(this->impl->InterfaceHeaderSetsEntries); +} + namespace { #define MAKE_PROP(PROP) const std::string prop##PROP = #PROP MAKE_PROP(C_STANDARD); @@ -1139,6 +1154,10 @@ MAKE_PROP(BINARY_DIR); MAKE_PROP(SOURCE_DIR); MAKE_PROP(FALSE); MAKE_PROP(TRUE); +MAKE_PROP(HEADER_DIRS); +MAKE_PROP(HEADER_SET); +MAKE_PROP(HEADER_SETS); +MAKE_PROP(INTERFACE_HEADER_SETS); #undef MAKE_PROP } @@ -1158,6 +1177,21 @@ std::string ConvertToString<cmValue>(cmValue value) { return std::string(*value); } + +template <typename ValueType> +bool StringIsEmpty(ValueType value); + +template <> +bool StringIsEmpty<const char*>(const char* value) +{ + return cmValue::IsEmpty(value); +} + +template <> +bool StringIsEmpty<cmValue>(cmValue value) +{ + return value.IsEmpty(); +} } template <typename ValueType> @@ -1321,6 +1355,104 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } else { this->impl->LanguageStandardProperties.erase(prop); } + } else if (prop == propHEADER_DIRS) { + auto* fileSet = this->GetFileSet("HEADERS"); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "The default header set has not yet been created."); + return; + } + fileSet->ClearDirectoryEntries(); + if (!StringIsEmpty(value)) { + fileSet->AddDirectoryEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } + } else if (prop == propHEADER_SET) { + auto* fileSet = this->GetFileSet("HEADERS"); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "The default header set has not yet been created."); + return; + } + fileSet->ClearFileEntries(); + if (!StringIsEmpty(value)) { + fileSet->AddFileEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } + } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { + auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); + if (fileSetName.empty()) { + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + "Header set name cannot be empty."); + return; + } + auto* fileSet = this->GetFileSet(fileSetName); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", fileSetName, + "\" has not yet been created.")); + return; + } + fileSet->ClearDirectoryEntries(); + if (!StringIsEmpty(value)) { + fileSet->AddDirectoryEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } + } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { + auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); + if (fileSetName.empty()) { + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + "Header set name cannot be empty."); + return; + } + auto* fileSet = this->GetFileSet(fileSetName); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", fileSetName, + "\" has not yet been created.")); + return; + } + fileSet->ClearFileEntries(); + if (!StringIsEmpty(value)) { + fileSet->AddFileEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } + } else if (prop == propHEADER_SETS) { + if (value) { + for (auto const& name : cmExpandedList(value)) { + if (!this->GetFileSet(name)) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", name, "\" has not yet been created.")); + return; + } + } + } + this->impl->HeaderSetsEntries.clear(); + if (!StringIsEmpty(value)) { + this->impl->HeaderSetsEntries.emplace_back( + value, this->impl->Makefile->GetBacktrace()); + } + } else if (prop == propINTERFACE_HEADER_SETS) { + if (value) { + for (auto const& name : cmExpandedList(value)) { + if (!this->GetFileSet(name)) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", name, "\" has not yet been created.")); + return; + } + } + } + this->impl->InterfaceHeaderSetsEntries.clear(); + if (!StringIsEmpty(value)) { + this->impl->InterfaceHeaderSetsEntries.emplace_back( + value, this->impl->Makefile->GetBacktrace()); + } } else { this->impl->Properties.SetProperty(prop, value); } @@ -1415,6 +1547,82 @@ void cmTarget::AppendProperty(const std::string& prop, prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be appended."); + } else if (prop == "HEADER_DIRS") { + auto* fileSet = this->GetFileSet("HEADERS"); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "The default header set has not yet been created."); + return; + } + fileSet->AddDirectoryEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { + auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); + if (fileSetName.empty()) { + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + "Header set name cannot be empty."); + return; + } + auto* fileSet = this->GetFileSet(fileSetName); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", fileSetName, + "\" has not yet been created.")); + return; + } + fileSet->AddDirectoryEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } else if (prop == "HEADER_SET") { + auto* fileSet = this->GetFileSet("HEADERS"); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "The default header set has not yet been created."); + return; + } + fileSet->AddFileEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { + auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); + if (fileSetName.empty()) { + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + "Header set name cannot be empty."); + return; + } + auto* fileSet = this->GetFileSet(fileSetName); + if (!fileSet) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", fileSetName, + "\" has not yet been created.")); + return; + } + fileSet->AddFileEntry( + BT<std::string>(value, this->impl->Makefile->GetBacktrace())); + } else if (prop == "HEADER_SETS") { + for (auto const& name : cmExpandedList(value)) { + if (!this->GetFileSet(name)) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", name, "\" has not yet been created.")); + return; + } + } + this->impl->HeaderSetsEntries.emplace_back( + value, this->impl->Makefile->GetBacktrace()); + } else if (prop == "INTERFACE_HEADER_SETS") { + for (auto const& name : cmExpandedList(value)) { + if (!this->GetFileSet(name)) { + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Header set \"", name, "\" has not yet been created.")); + return; + } + } + this->impl->InterfaceHeaderSetsEntries.emplace_back( + value, this->impl->Makefile->GetBacktrace()); } else { this->impl->Properties.AppendProperty(prop, value, asString); } @@ -1633,7 +1841,11 @@ cmValue cmTarget::GetProperty(const std::string& prop) const propNAME, propBINARY_DIR, propSOURCE_DIR, - propSOURCES + propSOURCES, + propHEADER_DIRS, + propHEADER_SET, + propHEADER_SETS, + propINTERFACE_HEADER_SETS, }; if (specialProps.count(prop)) { if (prop == propC_STANDARD || prop == propCXX_STANDARD || @@ -1759,6 +1971,60 @@ cmValue cmTarget::GetProperty(const std::string& prop) const .GetDirectory() .GetCurrentSource()); } + if (prop == propHEADER_DIRS) { + auto const* fileSet = this->GetFileSet("HEADERS"); + if (!fileSet) { + return nullptr; + } + static std::string output; + output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s); + return cmValue(output); + } + if (prop == propHEADER_SET) { + auto const* fileSet = this->GetFileSet("HEADERS"); + if (!fileSet) { + return nullptr; + } + static std::string output; + output = cmJoin(fileSet->GetFileEntries(), ";"_s); + return cmValue(output); + } + if (prop == propHEADER_SETS) { + static std::string output; + output = cmJoin(this->impl->HeaderSetsEntries, ";"_s); + return cmValue(output); + } + if (prop == propINTERFACE_HEADER_SETS) { + static std::string output; + output = cmJoin(this->impl->InterfaceHeaderSetsEntries, ";"_s); + return cmValue(output); + } + } + if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { + std::string fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); + if (fileSetName.empty()) { + return nullptr; + } + auto const* fileSet = this->GetFileSet(fileSetName); + if (!fileSet) { + return nullptr; + } + static std::string output; + output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s); + return cmValue(output); + } + if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { + std::string fileSetName = prop.substr(cmStrLen("HEADER_SET_")); + if (fileSetName.empty()) { + return nullptr; + } + auto const* fileSet = this->GetFileSet(fileSetName); + if (!fileSet) { + return nullptr; + } + static std::string output; + output = cmJoin(fileSet->GetFileEntries(), ";"_s); + return cmValue(output); } cmValue retVal = this->impl->Properties.GetPropertyValue(prop); @@ -2015,6 +2281,59 @@ std::string cmTarget::ImportedGetFullPath( return result; } +const cmFileSet* cmTarget::GetFileSet(const std::string& name) const +{ + auto it = this->impl->FileSets.find(name); + return it == this->impl->FileSets.end() ? nullptr : &it->second; +} + +cmFileSet* cmTarget::GetFileSet(const std::string& name) +{ + auto it = this->impl->FileSets.find(name); + return it == this->impl->FileSets.end() ? nullptr : &it->second; +} + +std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet( + const std::string& name, const std::string& type) +{ + auto result = + this->impl->FileSets.emplace(std::make_pair(name, cmFileSet(name, type))); + return std::make_pair(&result.first->second, result.second); +} + +std::string cmTarget::GetFileSetsPropertyName(const std::string& type) +{ + if (type == "HEADERS") { + return "HEADER_SETS"; + } + return ""; +} + +std::string cmTarget::GetInterfaceFileSetsPropertyName(const std::string& type) +{ + if (type == "HEADERS") { + return "INTERFACE_HEADER_SETS"; + } + return ""; +} + +std::vector<std::string> cmTarget::GetAllInterfaceFileSets() const +{ + std::vector<std::string> result; + auto inserter = std::back_inserter(result); + + auto appendEntries = [=](const std::vector<BT<std::string>>& entries) { + for (auto const& entry : entries) { + auto expanded = cmExpandedList(entry.Value); + std::copy(expanded.begin(), expanded.end(), inserter); + } + }; + + appendEntries(this->impl->InterfaceHeaderSetsEntries); + + return result; +} + bool cmTargetInternals::CheckImportedLibName(std::string const& prop, std::string const& value) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 3cf6942..27b325a 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -20,6 +20,7 @@ #include "cmValue.h" class cmCustomCommand; +class cmFileSet; class cmGlobalGenerator; class cmInstallTargetGenerator; class cmMakefile; @@ -260,6 +261,10 @@ public: cmBTStringRange GetLinkImplementationEntries() const; + cmBTStringRange GetHeaderSetsEntries() const; + + cmBTStringRange GetInterfaceHeaderSetsEntries() const; + std::string ImportedGetFullPath(const std::string& config, cmStateEnums::ArtifactType artifact) const; @@ -268,6 +273,16 @@ public: bool operator()(cmTarget const* t1, cmTarget const* t2) const; }; + const cmFileSet* GetFileSet(const std::string& name) const; + cmFileSet* GetFileSet(const std::string& name); + std::pair<cmFileSet*, bool> GetOrCreateFileSet(const std::string& name, + const std::string& type); + + std::vector<std::string> GetAllInterfaceFileSets() const; + + static std::string GetFileSetsPropertyName(const std::string& type); + static std::string GetInterfaceFileSetsPropertyName(const std::string& type); + private: template <typename ValueType> void StoreProperty(const std::string& prop, ValueType value); diff --git a/Source/cmTargetExport.h b/Source/cmTargetExport.h index 19fc931..885ac74 100644 --- a/Source/cmTargetExport.h +++ b/Source/cmTargetExport.h @@ -6,7 +6,9 @@ #include <string> +class cmFileSet; class cmGeneratorTarget; +class cmInstallFileSetGenerator; class cmInstallFilesGenerator; class cmInstallTargetGenerator; @@ -29,6 +31,7 @@ public: cmInstallTargetGenerator* FrameworkGenerator; cmInstallTargetGenerator* BundleGenerator; cmInstallFilesGenerator* HeaderGenerator; + std::map<cmFileSet*, cmInstallFileSetGenerator*> FileSetGenerators; ///@} bool NamelinkOnly = false; diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 3bd1ea3..391b954 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -155,10 +155,10 @@ bool cmTargetPropCommandBase::ProcessContentArgs( return false; } } - return this->PopulateTargetProperies(scope, content, prepend, system); + return this->PopulateTargetProperties(scope, content, prepend, system); } -bool cmTargetPropCommandBase::PopulateTargetProperies( +bool cmTargetPropCommandBase::PopulateTargetProperties( const std::string& scope, const std::vector<std::string>& content, bool prepend, bool system) { diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index fc24fe8..6bf7c3c 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -40,6 +40,9 @@ protected: virtual void HandleInterfaceContent(cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool system); + virtual bool PopulateTargetProperties( + const std::string& scope, const std::vector<std::string>& content, + bool prepend, bool system); private: virtual void HandleMissingTarget(const std::string& name) = 0; @@ -52,9 +55,6 @@ private: bool ProcessContentArgs(std::vector<std::string> const& args, unsigned int& argIndex, bool prepend, bool system); - bool PopulateTargetProperies(const std::string& scope, - const std::vector<std::string>& content, - bool prepend, bool system); cmExecutionStatus& Status; }; diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 26282ef..818e271 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -2,9 +2,17 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTargetSourcesCommand.h" +#include <algorithm> #include <sstream> +#include <utility> +#include <cm/string_view> +#include <cmext/string_view> + +#include "cmArgumentParser.h" +#include "cmFileSet.h" #include "cmGeneratorExpression.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" @@ -15,6 +23,20 @@ namespace { +struct FileSetArgs +{ + std::string Type; + std::string FileSet; + std::vector<std::string> BaseDirs; + std::vector<std::string> Files; +}; + +auto const FileSetArgsParser = cmArgumentParser<FileSetArgs>() + .Bind("TYPE"_s, &FileSetArgs::Type) + .Bind("FILE_SET"_s, &FileSetArgs::FileSet) + .Bind("BASE_DIRS"_s, &FileSetArgs::BaseDirs) + .Bind("FILES"_s, &FileSetArgs::Files); + class TargetSourcesImpl : public cmTargetPropCommandBase { public: @@ -26,8 +48,10 @@ protected: bool prepend, bool system) override { this->cmTargetPropCommandBase::HandleInterfaceContent( - tgt, this->ConvertToAbsoluteContent(tgt, content, true), prepend, - system); + tgt, + this->ConvertToAbsoluteContent(tgt, content, IsInterface::Yes, + CheckCMP0076::Yes), + prepend, system); } private: @@ -43,29 +67,55 @@ private: const std::vector<std::string>& content, bool /*prepend*/, bool /*system*/) override { - tgt->AppendProperty( - "SOURCES", - this->Join(this->ConvertToAbsoluteContent(tgt, content, false))); + tgt->AppendProperty("SOURCES", + this->Join(this->ConvertToAbsoluteContent( + tgt, content, IsInterface::No, CheckCMP0076::Yes))); return true; // Successfully handled. } + bool PopulateTargetProperties(const std::string& scope, + const std::vector<std::string>& content, + bool prepend, bool system) override + { + if (!content.empty() && content.front() == "FILE_SET"_s) { + return this->HandleFileSetMode(scope, content, prepend, system); + } + return this->cmTargetPropCommandBase::PopulateTargetProperties( + scope, content, prepend, system); + } + std::string Join(const std::vector<std::string>& content) override { return cmJoin(content, ";"); } + enum class IsInterface + { + Yes, + No, + }; + enum class CheckCMP0076 + { + Yes, + No, + }; std::vector<std::string> ConvertToAbsoluteContent( cmTarget* tgt, const std::vector<std::string>& content, - bool isInterfaceContent); + IsInterface isInterfaceContent, CheckCMP0076 checkCmp0076); + + bool HandleFileSetMode(const std::string& scope, + const std::vector<std::string>& content, bool prepend, + bool system); }; std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent( cmTarget* tgt, const std::vector<std::string>& content, - bool isInterfaceContent) + IsInterface isInterfaceContent, CheckCMP0076 checkCmp0076) { // Skip conversion in case old behavior has been explicitly requested - if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076) == - cmPolicies::OLD) { + if (checkCmp0076 == CheckCMP0076::Yes && + this->Makefile->GetPolicyStatus(cmPolicies::CMP0076) == + cmPolicies::OLD) { return content; } @@ -76,7 +126,7 @@ std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent( std::string absoluteSrc; if (cmSystemTools::FileIsFullPath(src) || cmGeneratorExpression::Find(src) == 0 || - (!isInterfaceContent && + (isInterfaceContent == IsInterface::No && (this->Makefile->GetCurrentSourceDirectory() == tgt->GetMakefile()->GetCurrentSourceDirectory()))) { absoluteSrc = src; @@ -95,28 +145,33 @@ std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent( bool issueMessage = true; bool useAbsoluteContent = false; std::ostringstream e; - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076)) { - case cmPolicies::WARN: - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0076) << "\n"; - break; - case cmPolicies::OLD: - issueMessage = false; - break; - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0076)); - break; - case cmPolicies::NEW: { - issueMessage = false; - useAbsoluteContent = true; - break; + if (checkCmp0076 == CheckCMP0076::Yes) { + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076)) { + case cmPolicies::WARN: + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0076) << "\n"; + break; + case cmPolicies::OLD: + issueMessage = false; + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0076)); + break; + case cmPolicies::NEW: { + issueMessage = false; + useAbsoluteContent = true; + break; + } } + } else { + issueMessage = false; + useAbsoluteContent = true; } if (issueMessage) { - if (isInterfaceContent) { + if (isInterfaceContent == IsInterface::Yes) { e << "An interface source of target \"" << tgt->GetName() << "\" has a relative path."; } else { @@ -129,6 +184,133 @@ std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent( return useAbsoluteContent ? absoluteContent : content; } +bool TargetSourcesImpl::HandleFileSetMode( + const std::string& scope, const std::vector<std::string>& content, + bool /*prepend*/, bool /*system*/) +{ + std::vector<std::string> unparsed; + auto args = FileSetArgsParser.Parse(content, &unparsed); + + if (!unparsed.empty()) { + this->SetError( + cmStrCat("Unrecognized keyword: \"", unparsed.front(), "\"")); + return false; + } + + if (args.FileSet.empty()) { + this->SetError("FILE_SET must not be empty"); + return false; + } + + bool const isDefault = args.Type == args.FileSet || + (args.Type.empty() && args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z'); + std::string type = isDefault ? args.FileSet : args.Type; + + auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type); + if (fileSet.second) { + if (!isDefault) { + if (args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z') { + this->SetError( + "Non-default file set name must not start with a capital letter"); + return false; + } + } + if (type.empty()) { + this->SetError("Must specify a TYPE when creating file set"); + return false; + } + if (type != "HEADERS"_s) { + this->SetError("File set TYPE may only be \"HEADERS\""); + return false; + } + + if (args.BaseDirs.empty()) { + args.BaseDirs.emplace_back(this->Makefile->GetCurrentSourceDirectory()); + } + + if (scope == "PRIVATE"_s || scope == "PUBLIC"_s) { + this->Target->AppendProperty(cmTarget::GetFileSetsPropertyName(type), + args.FileSet); + } + if (scope == "INTERFACE"_s || scope == "PUBLIC"_s) { + this->Target->AppendProperty( + cmTarget::GetInterfaceFileSetsPropertyName(type), args.FileSet); + } + } else { + type = fileSet.first->GetType(); + if (!args.Type.empty() && args.Type != type) { + this->SetError(cmStrCat( + "Type \"", args.Type, "\" for file set \"", fileSet.first->GetName(), + "\" does not match original type \"", type, "\"")); + return false; + } + + std::string existingScope = "PRIVATE"; + + auto const fileSetsProperty = cmTarget::GetFileSetsPropertyName(type); + auto const interfaceFileSetsProperty = + cmTarget::GetInterfaceFileSetsPropertyName(type); + std::vector<std::string> fileSets; + std::vector<std::string> interfaceFileSets; + cmExpandList(this->Target->GetSafeProperty(fileSetsProperty), fileSets); + cmExpandList(this->Target->GetSafeProperty(interfaceFileSetsProperty), + interfaceFileSets); + + if (std::find(interfaceFileSets.begin(), interfaceFileSets.end(), + args.FileSet) != interfaceFileSets.end()) { + existingScope = "INTERFACE"; + } + if (std::find(fileSets.begin(), fileSets.end(), args.FileSet) != + fileSets.end()) { + if (existingScope == "INTERFACE"_s) { + existingScope = "PUBLIC"; + } + } else if (existingScope != "INTERFACE"_s) { + this->SetError(cmStrCat("File set \"", args.FileSet, "\" is not in ", + fileSetsProperty, " or ", + interfaceFileSetsProperty)); + return false; + } + + if (scope != existingScope) { + this->SetError( + cmStrCat("Scope ", scope, " for file set \"", args.FileSet, + "\" does not match original scope ", existingScope)); + return false; + } + } + + auto files = this->Join(this->ConvertToAbsoluteContent( + this->Target, args.Files, IsInterface::Yes, CheckCMP0076::No)); + if (!files.empty()) { + fileSet.first->AddFileEntry( + BT<std::string>(files, this->Makefile->GetBacktrace())); + } + + auto baseDirectories = this->Join(this->ConvertToAbsoluteContent( + this->Target, args.BaseDirs, IsInterface::Yes, CheckCMP0076::No)); + if (!baseDirectories.empty()) { + fileSet.first->AddDirectoryEntry( + BT<std::string>(baseDirectories, this->Makefile->GetBacktrace())); + if (type == "HEADERS"_s) { + for (auto const& dir : cmExpandedList(baseDirectories)) { + auto interfaceDirectoriesGenex = + cmStrCat("$<BUILD_INTERFACE:", dir, ">"); + if (scope == "PRIVATE"_s || scope == "PUBLIC"_s) { + this->Target->AppendProperty("INCLUDE_DIRECTORIES", + interfaceDirectoriesGenex); + } + if (scope == "INTERFACE"_s || scope == "PUBLIC"_s) { + this->Target->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES", + interfaceDirectoriesGenex); + } + } + } + } + + return true; +} + } // namespace bool cmTargetSourcesCommand(std::vector<std::string> const& args, diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index cc9e158..cd468b9 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -211,7 +211,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, char retChar[16]; const char* retStr; if (worked) { - sprintf(retChar, "%i", retVal); + snprintf(retChar, sizeof(retChar), "%i", retVal); retStr = retChar; } else { retStr = "FAILED_TO_RUN"; diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index 969a2c2..cbd241b 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmVSSetupHelper.h" +#include <utility> + #include "cmsys/Encoding.hxx" #include "cmsys/FStream.hxx" @@ -46,17 +48,36 @@ const CLSID CLSID_SetupConfiguration = { /* clang-format on */ #endif +namespace { const WCHAR* Win10SDKComponent = L"Microsoft.VisualStudio.Component.Windows10SDK"; const WCHAR* Win81SDKComponent = L"Microsoft.VisualStudio.Component.Windows81SDK"; const WCHAR* ComponentType = L"Component"; +bool LoadVSInstanceVCToolsetVersion(VSInstanceInfo& vsInstanceInfo) +{ + std::string const vcRoot = vsInstanceInfo.GetInstallLocation(); + std::string vcToolsVersionFile = + vcRoot + "/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt"; + std::string vcToolsVersion; + cmsys::ifstream fin(vcToolsVersionFile.c_str()); + if (!fin || !cmSystemTools::GetLineFromStream(fin, vcToolsVersion)) { + return false; + } + vcToolsVersion = cmTrimWhitespace(vcToolsVersion); + std::string const vcToolsDir = vcRoot + "/VC/Tools/MSVC/" + vcToolsVersion; + if (!cmSystemTools::FileIsDirectory(vcToolsDir)) { + return false; + } + vsInstanceInfo.VCToolsetVersion = vcToolsVersion; + return true; +} +} + std::string VSInstanceInfo::GetInstallLocation() const { - std::string loc = cmsys::Encoding::ToNarrow(this->VSInstallLocation); - cmSystemTools::ConvertToUnixSlashes(loc); - return loc; + return this->VSInstallLocation; } cmVSSetupAPIHelper::cmVSSetupAPIHelper(unsigned int version) @@ -83,10 +104,12 @@ cmVSSetupAPIHelper::~cmVSSetupAPIHelper() CoUninitialize(); } -bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation) +bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation, + std::string const& vsInstallVersion) { this->SpecifiedVSInstallLocation = vsInstallLocation; cmSystemTools::ConvertToUnixSlashes(this->SpecifiedVSInstallLocation); + this->SpecifiedVSInstallVersion = vsInstallVersion; chosenInstanceInfo = VSInstanceInfo(); return this->EnumerateAndChooseVSInstance(); } @@ -152,29 +175,17 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( if (pInstance == NULL) return false; - SmartBSTR bstrId; - if (SUCCEEDED(pInstance->GetInstanceId(&bstrId))) { - vsInstanceInfo.InstanceId = std::wstring(bstrId); - } else { - return false; - } - InstanceState state; if (FAILED(pInstance->GetState(&state))) { return false; } - ULONGLONG ullVersion = 0; SmartBSTR bstrVersion; if (FAILED(pInstance->GetInstallationVersion(&bstrVersion))) { return false; } else { - vsInstanceInfo.Version = std::wstring(bstrVersion); - if (FAILED(setupHelper->ParseVersion(bstrVersion, &ullVersion))) { - vsInstanceInfo.ullVersion = 0; - } else { - vsInstanceInfo.ullVersion = ullVersion; - } + vsInstanceInfo.Version = + cmsys::Encoding::ToNarrow(std::wstring(bstrVersion)); } // Reboot may have been required before the installation path was created. @@ -183,26 +194,15 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( if (FAILED(pInstance->GetInstallationPath(&bstrInstallationPath))) { return false; } else { - vsInstanceInfo.VSInstallLocation = std::wstring(bstrInstallationPath); + vsInstanceInfo.VSInstallLocation = + cmsys::Encoding::ToNarrow(std::wstring(bstrInstallationPath)); + cmSystemTools::ConvertToUnixSlashes(vsInstanceInfo.VSInstallLocation); } } // Check if a compiler is installed with this instance. - { - std::string const vcRoot = vsInstanceInfo.GetInstallLocation(); - std::string vcToolsVersionFile = - vcRoot + "/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt"; - std::string vcToolsVersion; - cmsys::ifstream fin(vcToolsVersionFile.c_str()); - if (!fin || !cmSystemTools::GetLineFromStream(fin, vcToolsVersion)) { - return false; - } - vcToolsVersion = cmTrimWhitespace(vcToolsVersion); - std::string const vcToolsDir = vcRoot + "/VC/Tools/MSVC/" + vcToolsVersion; - if (!cmSystemTools::FileIsDirectory(vcToolsDir)) { - return false; - } - vsInstanceInfo.VCToolsetVersion = vcToolsVersion; + if (!LoadVSInstanceVCToolsetVersion(vsInstanceInfo)) { + return false; } // Reboot may have been required before the product package was registered @@ -264,7 +264,7 @@ bool cmVSSetupAPIHelper::GetVSInstanceVersion(std::string& vsInstanceVersion) bool isInstalled = this->EnumerateAndChooseVSInstance(); if (isInstalled) { - vsInstanceVersion = cmsys::Encoding::ToNarrow(chosenInstanceInfo.Version); + vsInstanceVersion = chosenInstanceInfo.Version; } return isInstalled; @@ -298,7 +298,7 @@ bool cmVSSetupAPIHelper::IsEWDKEnabled() bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() { bool isVSInstanceExists = false; - if (chosenInstanceInfo.VSInstallLocation.compare(L"") != 0) { + if (chosenInstanceInfo.VSInstallLocation.compare("") != 0) { return true; } @@ -311,12 +311,11 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() if (envVSVersion.empty() || envVsInstallDir.empty()) return false; - chosenInstanceInfo.VSInstallLocation = - std::wstring(envVsInstallDir.begin(), envVsInstallDir.end()); - chosenInstanceInfo.Version = - std::wstring(envVSVersion.begin(), envVSVersion.end()); - chosenInstanceInfo.VCToolsetVersion = envVSVersion; - chosenInstanceInfo.ullVersion = std::stoi(envVSVersion); + chosenInstanceInfo.VSInstallLocation = envVsInstallDir; + chosenInstanceInfo.Version = envVSVersion; + if (!LoadVSInstanceVCToolsetVersion(chosenInstanceInfo)) { + return false; + } chosenInstanceInfo.IsWin10SDKInstalled = true; chosenInstanceInfo.IsWin81SDKInstalled = !envWindowsSdkDir81.empty(); return true; @@ -343,7 +342,9 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() return false; } - std::wstring const wantVersion = std::to_wstring(this->Version) + L'.'; + std::string const wantVersion = std::to_string(this->Version) + '.'; + + bool specifiedLocationNotSpecifiedVersion = false; SmartCOMPtr<ISetupInstance> instance; while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) { @@ -371,6 +372,16 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() std::string currentVSLocation = instanceInfo.GetInstallLocation(); if (cmSystemTools::ComparePath(currentVSLocation, this->SpecifiedVSInstallLocation)) { + if (this->SpecifiedVSInstallVersion.empty() || + instanceInfo.Version == this->SpecifiedVSInstallVersion) { + chosenInstanceInfo = instanceInfo; + return true; + } + specifiedLocationNotSpecifiedVersion = true; + } + } else if (!this->SpecifiedVSInstallVersion.empty()) { + // We are looking for a specific version. + if (instanceInfo.Version == this->SpecifiedVSInstallVersion) { chosenInstanceInfo = instanceInfo; return true; } @@ -392,6 +403,13 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() } } + if (!this->SpecifiedVSInstallLocation.empty() && + !specifiedLocationNotSpecifiedVersion) { + // The VS Installer does not know about the specified location. + // Check for one directly on disk. + return this->LoadSpecifiedVSInstanceFromDisk(); + } + if (vecVSInstances.size() > 0) { isVSInstanceExists = true; int index = ChooseVSInstance(vecVSInstances); @@ -454,6 +472,32 @@ int cmVSSetupAPIHelper::ChooseVSInstance( return chosenIndex; } +bool cmVSSetupAPIHelper::LoadSpecifiedVSInstanceFromDisk() +{ + if (!cmSystemTools::FileIsDirectory(this->SpecifiedVSInstallLocation)) { + return false; + } + VSInstanceInfo vsInstanceInfo; + vsInstanceInfo.VSInstallLocation = this->SpecifiedVSInstallLocation; + // FIXME: Is there a better way to get SDK information? + vsInstanceInfo.IsWin10SDKInstalled = true; + vsInstanceInfo.IsWin81SDKInstalled = false; + + if (!this->SpecifiedVSInstallVersion.empty()) { + // Assume the version specified by the user is correct. + vsInstanceInfo.Version = this->SpecifiedVSInstallVersion; + } else { + return false; + } + + if (!LoadVSInstanceVCToolsetVersion(vsInstanceInfo)) { + return false; + } + + chosenInstanceInfo = std::move(vsInstanceInfo); + return true; +} + bool cmVSSetupAPIHelper::Initialize() { if (initializationFailure) diff --git a/Source/cmVSSetupHelper.h b/Source/cmVSSetupHelper.h index 61a3ac7..44c883b 100644 --- a/Source/cmVSSetupHelper.h +++ b/Source/cmVSSetupHelper.h @@ -84,11 +84,9 @@ private: struct VSInstanceInfo { - std::wstring InstanceId; - std::wstring VSInstallLocation; - std::wstring Version; + std::string VSInstallLocation; + std::string Version; std::string VCToolsetVersion; - ULONGLONG ullVersion = 0; // A.B.C.D = (A<<48)|(B<<32)|(C<<16)|D bool IsWin10SDKInstalled = false; bool IsWin81SDKInstalled = false; @@ -101,7 +99,8 @@ public: cmVSSetupAPIHelper(unsigned int version); ~cmVSSetupAPIHelper(); - bool SetVSInstance(std::string const& vsInstallLocation); + bool SetVSInstance(std::string const& vsInstallLocation, + std::string const& vsInstallVersion); bool IsVSInstalled(); bool GetVSInstanceInfo(std::string& vsInstallLocation); @@ -118,6 +117,7 @@ private: bool& bWin10SDK, bool& bWin81SDK); int ChooseVSInstance(const std::vector<VSInstanceInfo>& vecVSInstances); bool EnumerateAndChooseVSInstance(); + bool LoadSpecifiedVSInstanceFromDisk(); unsigned int Version; @@ -134,4 +134,5 @@ private: bool IsEWDKEnabled(); std::string SpecifiedVSInstallLocation; + std::string SpecifiedVSInstallVersion; }; diff --git a/Source/cmXMLParser.h b/Source/cmXMLParser.h index 7e805d7..176252d 100644 --- a/Source/cmXMLParser.h +++ b/Source/cmXMLParser.h @@ -21,6 +21,7 @@ class cmXMLParser { public: cmXMLParser(); + cmXMLParser(const cmXMLParser& /*other*/) = default; virtual ~cmXMLParser(); //! Parse given XML string diff --git a/Source/cmXMLSafe.cxx b/Source/cmXMLSafe.cxx index d31a239..4014635 100644 --- a/Source/cmXMLSafe.cxx +++ b/Source/cmXMLSafe.cxx @@ -73,7 +73,7 @@ std::ostream& operator<<(std::ostream& os, cmXMLSafe const& self) } else { // Use a human-readable hex value for this invalid character. char buf[16]; - sprintf(buf, "%X", ch); + snprintf(buf, sizeof(buf), "%X", ch); os << "[NON-XML-CHAR-0x" << buf << "]"; } @@ -82,7 +82,7 @@ std::ostream& operator<<(std::ostream& os, cmXMLSafe const& self) ch = static_cast<unsigned char>(*first++); // Use a human-readable hex value for this invalid byte. char buf[16]; - sprintf(buf, "%X", ch); + snprintf(buf, sizeof(buf), "%X", ch); os << "[NON-UTF-8-BYTE-0x" << buf << "]"; } } diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index bdddc4e..8376d4d 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1112,7 +1112,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, int count; if (countFile) { if (1 != fscanf(countFile, "%i", &count)) { - cmSystemTools::Message("Could not read from count file."); + std::cerr << "Could not read from count file.\n"; } fclose(countFile); } else { @@ -1426,8 +1426,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, action = cmSystemTools::TarActionExtract; } break; default: { - cmSystemTools::Message( - std::string("tar: Unknown argument: ") + flag, "Warning"); + std::cerr << "tar: Unknown argument: " << flag << "\n"; } } } @@ -1448,8 +1447,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, } } else if (action == cmSystemTools::TarActionCreate) { if (files.empty()) { - cmSystemTools::Message("tar: No files or directories specified", - "Warning"); + std::cerr << "tar: No files or directories specified\n"; } if (!cmSystemTools::CreateTar(outFile, files, compress, verbose, mtime, format)) { @@ -1588,7 +1586,11 @@ int cmcmd::HashSumFile(std::vector<std::string> const& args, std::cerr << "Error: " << filename << " is a directory" << std::endl; retval++; } else { - std::string value = cmSystemTools::ComputeFileHash(filename, algo); + std::string value +#ifndef CMAKE_BOOTSTRAP + = cmSystemTools::ComputeFileHash(filename, algo) +#endif + ; if (value.empty()) { // To mimic "md5sum/shasum" behavior in a shell: std::cerr << filename << ": No such file or directory" << std::endl; @@ -1684,7 +1686,7 @@ static void cmcmdProgressReport(std::string const& dir, std::string const& num) return; } if (1 != fscanf(progFile, "%i", &count)) { - cmSystemTools::Message("Could not read from progress file."); + std::cerr << "Could not read from progress file.\n"; } fclose(progFile); @@ -2135,8 +2137,8 @@ struct NumberFormatter { } }; -std::ostream& operator<<(std::ostream& stream, - NumberFormatter const& formatter) +static std::ostream& operator<<(std::ostream& stream, + NumberFormatter const& formatter) { auto const& flags = stream.flags(); if (formatter.Format == FORMAT_DECIMAL) { diff --git a/Source/kwsys/Configure.hxx.in b/Source/kwsys/Configure.hxx.in index 29a2dd1..8d47340 100644 --- a/Source/kwsys/Configure.hxx.in +++ b/Source/kwsys/Configure.hxx.in @@ -16,11 +16,11 @@ @KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP@ #if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute) -# define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_attribute(x) +# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_attribute(x) #elif defined(__has_cpp_attribute) -# define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_cpp_attribute(x) +# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_cpp_attribute(x) #else -# define @KWSYS_NAMESPACE@__has_cpp_attribute(x) 0 +# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) 0 #endif #if __cplusplus >= 201103L @@ -31,13 +31,13 @@ #ifndef @KWSYS_NAMESPACE@_FALLTHROUGH # if __cplusplus >= 201703L && \ - @KWSYS_NAMESPACE@__has_cpp_attribute(fallthrough) + @KWSYS_NAMESPACE@_has_cpp_attribute(fallthrough) # define @KWSYS_NAMESPACE@_FALLTHROUGH [[fallthrough]] # elif __cplusplus >= 201103L && \ - @KWSYS_NAMESPACE@__has_cpp_attribute(gnu::fallthrough) + @KWSYS_NAMESPACE@_has_cpp_attribute(gnu::fallthrough) # define @KWSYS_NAMESPACE@_FALLTHROUGH [[gnu::fallthrough]] # elif __cplusplus >= 201103L && \ - @KWSYS_NAMESPACE@__has_cpp_attribute(clang::fallthrough) + @KWSYS_NAMESPACE@_has_cpp_attribute(clang::fallthrough) # define @KWSYS_NAMESPACE@_FALLTHROUGH [[clang::fallthrough]] # endif #endif @@ -45,7 +45,7 @@ # define @KWSYS_NAMESPACE@_FALLTHROUGH static_cast<void>(0) #endif -#undef @KWSYS_NAMESPACE@__has_cpp_attribute +#undef @KWSYS_NAMESPACE@_has_cpp_attribute /* If building a C++ file in kwsys itself, give the source file access to the macros without a configured namespace. */ diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index 2e8aa83..6e31cbf 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -99,18 +99,21 @@ Status Directory::Load(std::string const& name, std::string* errorMessage) this->Clear(); intptr_t srchHandle; char* buf; + size_t bufLength; size_t n = name.size(); if (name.back() == '/' || name.back() == '\\') { - buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name.c_str()); + bufLength = n + 1 + 1; + buf = new char[bufLength]; + snprintf(buf, bufLength, "%s*", name.c_str()); } else { // Make sure the slashes in the wildcard suffix are consistent with the // rest of the path - buf = new char[n + 2 + 1]; + bufLength = n + 2 + 1; + buf = new char[bufLength]; if (name.find('\\') != std::string::npos) { - sprintf(buf, "%s\\*", name.c_str()); + snprintf(buf, bufLength, "%s\\*", name.c_str()); } else { - sprintf(buf, "%s/*", name.c_str()); + snprintf(buf, bufLength, "%s/*", name.c_str()); } } struct _wfinddata_t data; // data of current file @@ -148,13 +151,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, { intptr_t srchHandle; char* buf; + size_t bufLength; size_t n = name.size(); if (name.back() == '/') { + bufLength = n + 1 + 1; buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name.c_str()); + snprintf(buf, bufLength, "%s*", name.c_str()); } else { + bufLength = n + 2 + 1; buf = new char[n + 2 + 1]; - sprintf(buf, "%s/*", name.c_str()); + snprintf(buf, bufLength, "%s/*", name.c_str()); } struct _wfinddata_t data; // data of current file diff --git a/Source/kwsys/DynamicLoader.cxx b/Source/kwsys/DynamicLoader.cxx index 66ee9ea..8afc2e8 100644 --- a/Source/kwsys/DynamicLoader.cxx +++ b/Source/kwsys/DynamicLoader.cxx @@ -275,20 +275,20 @@ const char* DynamicLoader::LastError() if (length < 1) { /* FormatMessage failed. Use a default message. */ - _snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE, - "DynamicLoader encountered error 0x%X. " - "FormatMessage failed with error 0x%X", - error, GetLastError()); + snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE, + "DynamicLoader encountered error 0x%lX. " + "FormatMessage failed with error 0x%lX", + error, GetLastError()); return str; } if (!WideCharToMultiByte(CP_UTF8, 0, lpMsgBuf, -1, str, DYNLOAD_ERROR_BUFFER_SIZE, nullptr, nullptr)) { /* WideCharToMultiByte failed. Use a default message. */ - _snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE, - "DynamicLoader encountered error 0x%X. " - "WideCharToMultiByte failed with error 0x%X", - error, GetLastError()); + snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE, + "DynamicLoader encountered error 0x%lX. " + "WideCharToMultiByte failed with error 0x%lX", + error, GetLastError()); } return str; @@ -436,9 +436,14 @@ namespace KWSYS_NAMESPACE { DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary( const std::string& libname, int flags) { - CHECK_OPEN_FLAGS(flags, 0, nullptr); + CHECK_OPEN_FLAGS(flags, RTLDGlobal, nullptr); + + int llFlags = RTLD_LAZY; + if (flags & RTLDGlobal) { + llFlags |= RTLD_GLOBAL; + } - return dlopen(libname.c_str(), RTLD_LAZY); + return dlopen(libname.c_str(), llFlags); } int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib) diff --git a/Source/kwsys/DynamicLoader.hxx.in b/Source/kwsys/DynamicLoader.hxx.in index 539c742..4edd31c 100644 --- a/Source/kwsys/DynamicLoader.hxx.in +++ b/Source/kwsys/DynamicLoader.hxx.in @@ -73,7 +73,12 @@ public: // This is currently only supported on Windows. SearchBesideLibrary = 0x00000001, - AllOpenFlags = SearchBesideLibrary + // Make loaded symbols visible globally + // + // This is currently only supported on *nix systems. + RTLDGlobal = 0x00000002, + + AllOpenFlags = SearchBesideLibrary | RTLDGlobal }; /** Load a dynamic library into the current process. diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index a8a15dd..1963b27 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -2287,7 +2287,8 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int sig, #endif default: cp->ProcessResults[idx].ExitException = kwsysProcess_Exception_Other; - sprintf(cp->ProcessResults[idx].ExitExceptionString, "Signal %d", sig); + snprintf(cp->ProcessResults[idx].ExitExceptionString, + KWSYSPE_PIPE_BUFFER_SIZE + 1, "Signal %d", sig); break; } } @@ -2540,7 +2541,7 @@ static void kwsysProcessKill(pid_t process_id) int pid; if (sscanf(d->d_name, "%d", &pid) == 1 && pid != 0) { struct stat finfo; - sprintf(fname, "/proc/%d/stat", pid); + snprintf(fname, sizeof(fname), "/proc/%d/stat", pid); if (stat(fname, &finfo) == 0) { FILE* f = fopen(fname, "r"); if (f) { diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c index 8f01684..e97973e 100644 --- a/Source/kwsys/ProcessWin32.c +++ b/Source/kwsys/ProcessWin32.c @@ -29,7 +29,7 @@ a UNIX-style select system call. # define KWSYS_WINDOWS_DEPRECATED_GetVersionEx #endif #include <io.h> /* _unlink */ -#include <stdio.h> /* sprintf */ +#include <stdio.h> /* snprintf */ #include <string.h> /* strlen, strdup */ #ifndef _MAX_FNAME @@ -1867,18 +1867,18 @@ void kwsysProcessCleanup(kwsysProcess* cp, DWORD error) KWSYSPE_PIPE_BUFFER_SIZE, 0); if (length < 1) { /* FormatMessage failed. Use a default message. */ - _snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE, - "Process execution failed with error 0x%X. " - "FormatMessage failed with error 0x%X", - error, GetLastError()); + snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE, + "Process execution failed with error 0x%lX. " + "FormatMessage failed with error 0x%lX", + error, GetLastError()); } if (!WideCharToMultiByte(CP_UTF8, 0, err_msg, -1, cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE, NULL, NULL)) { /* WideCharToMultiByte failed. Use a default message. */ - _snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE, - "Process execution failed with error 0x%X. " - "WideCharToMultiByte failed with error 0x%X", - error, GetLastError()); + snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE, + "Process execution failed with error 0x%lX. " + "WideCharToMultiByte failed with error 0x%lX", + error, GetLastError()); } } @@ -2144,8 +2144,8 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int code, case STATUS_NO_MEMORY: default: cp->ProcessResults[idx].ExitException = kwsysProcess_Exception_Other; - _snprintf(cp->ProcessResults[idx].ExitExceptionString, - KWSYSPE_PIPE_BUFFER_SIZE, "Exit code 0x%x\n", code); + snprintf(cp->ProcessResults[idx].ExitExceptionString, + KWSYSPE_PIPE_BUFFER_SIZE, "Exit code 0x%x\n", code); break; } } diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in index 091334b..d6ae75c 100644 --- a/Source/kwsys/SharedForward.h.in +++ b/Source/kwsys/SharedForward.h.in @@ -457,9 +457,9 @@ static void kwsys_shared_forward_strerror(char* message) message, KWSYS_SHARED_FORWARD_MAXPATH, 0); if (length < 1 || length > KWSYS_SHARED_FORWARD_MAXPATH) { /* FormatMessage failed. Use a default message. */ - _snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH, - "Error 0x%X (FormatMessage failed with error 0x%X)", original, - GetLastError()); + snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH, + "Error 0x%lX (FormatMessage failed with error 0x%lX)", original, + GetLastError()); } # else /* Implementation for UNIX. */ diff --git a/Source/kwsys/Status.cxx b/Source/kwsys/Status.cxx index 503d1e1..edda7a0 100644 --- a/Source/kwsys/Status.cxx +++ b/Source/kwsys/Status.cxx @@ -53,7 +53,7 @@ std::string Status::GetString() const LocalFree(message); } break; #endif - }; + } return err; } diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index f2bf85f..ecb9bf3 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -1267,7 +1267,9 @@ public: private: void* GetRealAddress() const { - return (void*)((char*)this->Address - (char*)this->BinaryBaseAddress); + return reinterpret_cast<void*>( + static_cast<char*>(this->Address) - + static_cast<char*>(this->BinaryBaseAddress)); } std::string GetFileName(const std::string& path) const; @@ -2789,19 +2791,20 @@ bool SystemInformationImplementation::RetrieveProcessorSerialNumber() // ; ecx: middle 32 bits are the processor signature bits // ; edx: bottom 32 bits are the processor signature bits char sn[128]; - sprintf(sn, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x", - ((SerialNumber[1] & 0xff000000) >> 24), - ((SerialNumber[1] & 0x00ff0000) >> 16), - ((SerialNumber[1] & 0x0000ff00) >> 8), - ((SerialNumber[1] & 0x000000ff) >> 0), - ((SerialNumber[2] & 0xff000000) >> 24), - ((SerialNumber[2] & 0x00ff0000) >> 16), - ((SerialNumber[2] & 0x0000ff00) >> 8), - ((SerialNumber[2] & 0x000000ff) >> 0), - ((SerialNumber[3] & 0xff000000) >> 24), - ((SerialNumber[3] & 0x00ff0000) >> 16), - ((SerialNumber[3] & 0x0000ff00) >> 8), - ((SerialNumber[3] & 0x000000ff) >> 0)); + snprintf(sn, sizeof(sn), + "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x", + ((SerialNumber[1] & 0xff000000) >> 24), + ((SerialNumber[1] & 0x00ff0000) >> 16), + ((SerialNumber[1] & 0x0000ff00) >> 8), + ((SerialNumber[1] & 0x000000ff) >> 0), + ((SerialNumber[2] & 0xff000000) >> 24), + ((SerialNumber[2] & 0x00ff0000) >> 16), + ((SerialNumber[2] & 0x0000ff00) >> 8), + ((SerialNumber[2] & 0x000000ff) >> 0), + ((SerialNumber[3] & 0xff000000) >> 24), + ((SerialNumber[3] & 0x00ff0000) >> 16), + ((SerialNumber[3] & 0x0000ff00) >> 8), + ((SerialNumber[3] & 0x000000ff) >> 0)); this->ChipID.SerialNumber = sn; return true; @@ -3749,24 +3752,24 @@ long long SystemInformationImplementation::GetProcMemoryAvailable( ResourceLimitType rlim; ierr = GetResourceLimit(RLIMIT_DATA, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); + memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail); } ierr = GetResourceLimit(RLIMIT_AS, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); + memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail); } #elif defined(__APPLE__) struct rlimit rlim; int ierr; ierr = getrlimit(RLIMIT_DATA, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); + memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail); } ierr = getrlimit(RLIMIT_RSS, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); + memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail); } #endif @@ -4068,7 +4071,7 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable) // install ours struct sigaction sa; - sa.sa_sigaction = (SigAction)StacktraceSignalHandler; + sa.sa_sigaction = static_cast<SigAction>(StacktraceSignalHandler); sa.sa_flags = SA_SIGINFO | SA_RESETHAND; # ifdef SA_RESTART sa.sa_flags |= SA_RESTART; @@ -4564,7 +4567,8 @@ bool SystemInformationImplementation::ParseSysCtl() this->AvailablePhysicalMemory = 0; vm_statistics_data_t vmstat; mach_msg_type_number_t count = HOST_VM_INFO_COUNT; - if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, + if (host_statistics(mach_host_self(), HOST_VM_INFO, + reinterpret_cast<host_info_t>(&vmstat), &count) == KERN_SUCCESS) { err = kw_sysctlbyname_int64("hw.pagesize", &tempInt64); if (err == 0) { @@ -5395,8 +5399,8 @@ bool SystemInformationImplementation::QueryOSInformation() } } - sprintf(operatingSystem, "%ls (Build %ld)", osvi.szCSDVersion, - osvi.dwBuildNumber & 0xFFFF); + snprintf(operatingSystem, sizeof(operatingSystem), "%ls (Build %ld)", + osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); this->OSVersion = operatingSystem; } else # endif // VER_NT_WORKSTATION @@ -5439,9 +5443,10 @@ bool SystemInformationImplementation::QueryOSInformation() // Display version, service pack (if any), and build number. if (osvi.dwMajorVersion <= 4) { // NB: NT 4.0 and earlier. - sprintf(operatingSystem, "version %ld.%ld %ls (Build %ld)", - osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion, - osvi.dwBuildNumber & 0xFFFF); + snprintf(operatingSystem, sizeof(operatingSystem), + "version %ld.%ld %ls (Build %ld)", osvi.dwMajorVersion, + osvi.dwMinorVersion, osvi.szCSDVersion, + osvi.dwBuildNumber & 0xFFFF); this->OSVersion = operatingSystem; } else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { // Windows XP and .NET server. @@ -5467,8 +5472,8 @@ bool SystemInformationImplementation::QueryOSInformation() } } else { // Windows 2000 and everything else. - sprintf(operatingSystem, "%ls (Build %ld)", osvi.szCSDVersion, - osvi.dwBuildNumber & 0xFFFF); + snprintf(operatingSystem, sizeof(operatingSystem), "%ls (Build %ld)", + osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); this->OSVersion = operatingSystem; } break; diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index bd900fe..6a8520fe 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -34,6 +34,10 @@ #include <utility> #include <vector> +#ifdef _WIN32 +# include <cwchar> +#endif + // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. #if 0 @@ -103,6 +107,9 @@ # if defined(_MSC_VER) && _MSC_VER >= 1800 # define KWSYS_WINDOWS_DEPRECATED_GetVersionEx # endif +# ifndef IO_REPARSE_TAG_APPEXECLINK +# define IO_REPARSE_TAG_APPEXECLINK (0x8000001BL) +# endif // from ntifs.h, which can only be used by drivers typedef struct _REPARSE_DATA_BUFFER { @@ -132,8 +139,46 @@ typedef struct _REPARSE_DATA_BUFFER { UCHAR DataBuffer[1]; } GenericReparseBuffer; + struct + { + ULONG Version; + WCHAR StringList[1]; + // In version 3, there are 4 NUL-terminated strings: + // * Package ID + // * Entry Point + // * Executable Path + // * Application Type + } AppExecLinkReparseBuffer; } DUMMYUNIONNAME; } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; + +namespace { +WCHAR* GetAppExecLink(PREPARSE_DATA_BUFFER data, size_t& len) +{ + // We only know the layout of version 3. + if (data->AppExecLinkReparseBuffer.Version != 3) { + return nullptr; + } + + WCHAR* pstr = data->AppExecLinkReparseBuffer.StringList; + + // Skip the package id and entry point strings. + for (int i = 0; i < 2; ++i) { + len = std::wcslen(pstr); + if (len == 0) { + return nullptr; + } + pstr += len + 1; + } + + // The third string is the executable path. + len = std::wcslen(pstr); + if (len == 0) { + return nullptr; + } + return pstr; +} +} #endif #if !KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H @@ -1343,8 +1388,8 @@ bool SystemTools::FileExists(const std::string& filename) return false; } #if defined(_WIN32) - DWORD attr = - GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()); + const std::wstring path = Encoding::ToWindowsExtendedPath(filename); + DWORD attr = GetFileAttributesW(path.c_str()); if (attr == INVALID_FILE_ATTRIBUTES) { return false; } @@ -1352,12 +1397,38 @@ bool SystemTools::FileExists(const std::string& filename) if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { // Using 0 instead of GENERIC_READ as it allows reading of file attributes // even if we do not have permission to read the file itself - HANDLE handle = - CreateFileW(Encoding::ToWindowsExtendedPath(filename).c_str(), 0, 0, - nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); + HANDLE handle = CreateFileW(path.c_str(), 0, 0, nullptr, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, nullptr); if (handle == INVALID_HANDLE_VALUE) { - return false; + // A reparse point may be an execution alias (Windows Store app), which + // is similar to a symlink but it cannot be opened as a regular file. + // We must look at the reparse point data explicitly. + handle = CreateFileW( + path.c_str(), 0, 0, nullptr, OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nullptr); + + if (handle == INVALID_HANDLE_VALUE) { + return false; + } + + byte buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; + DWORD bytesReturned = 0; + + if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, nullptr, 0, buffer, + MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &bytesReturned, + nullptr)) { + CloseHandle(handle); + return false; + } + + CloseHandle(handle); + + PREPARSE_DATA_BUFFER data = + reinterpret_cast<PREPARSE_DATA_BUFFER>(&buffer[0]); + + // Assume that file exists if it is an execution alias. + return data->ReparseTag == IO_REPARSE_TAG_APPEXECLINK; } CloseHandle(handle); @@ -3011,11 +3082,7 @@ bool SystemTools::FileIsDirectory(const std::string& inName) bool SystemTools::FileIsExecutable(const std::string& name) { -#if defined(_WIN32) - return SystemTools::FileExists(name, true); -#else return !FileIsDirectory(name) && TestFileAccess(name, TEST_FILE_EXECUTE); -#endif } bool SystemTools::FileIsSymlink(const std::string& name) @@ -3164,6 +3231,15 @@ Status SystemTools::ReadSymlink(std::string const& newName, data->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR); substituteNameData = data->MountPointReparseBuffer.PathBuffer + data->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR); + } else if (data->ReparseTag == IO_REPARSE_TAG_APPEXECLINK) { + // The reparse buffer is a list of 0-terminated non-empty strings, + // terminated by an empty string (0-0). We need the third string. + size_t destLen; + substituteNameData = GetAppExecLink(data, destLen); + if (substituteNameData == nullptr || destLen == 0) { + return Status::Windows(ERROR_SYMLINK_NOT_SUPPORTED); + } + substituteNameLength = static_cast<USHORT>(destLen); } else { return Status::Windows(ERROR_REPARSE_TAG_MISMATCH); } @@ -4552,10 +4628,10 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() } res += " "; - sprintf(buffer, "%ld", osvi.dwMajorVersion); + snprintf(buffer, sizeof(buffer), "%ld", osvi.dwMajorVersion); res += buffer; res += "."; - sprintf(buffer, "%ld", osvi.dwMinorVersion); + snprintf(buffer, sizeof(buffer), "%ld", osvi.dwMinorVersion); res += buffer; } @@ -4575,7 +4651,7 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() if (lRet == ERROR_SUCCESS) { res += " Service Pack 6a (Build "; - sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF); + snprintf(buffer, sizeof(buffer), "%ld", osvi.dwBuildNumber & 0xFFFF); res += buffer; res += ")"; } else // Windows NT 4.0 prior to SP6a @@ -4583,7 +4659,7 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() res += " "; res += osvi.szCSDVersion; res += " (Build "; - sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF); + snprintf(buffer, sizeof(buffer), "%ld", osvi.dwBuildNumber & 0xFFFF); res += buffer; res += ")"; } @@ -4594,7 +4670,7 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() res += " "; res += osvi.szCSDVersion; res += " (Build "; - sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF); + snprintf(buffer, sizeof(buffer), "%ld", osvi.dwBuildNumber & 0xFFFF); res += buffer; res += ")"; } diff --git a/Source/kwsys/testDirectory.cxx b/Source/kwsys/testDirectory.cxx index a847462..79bdc98 100644 --- a/Source/kwsys/testDirectory.cxx +++ b/Source/kwsys/testDirectory.cxx @@ -19,7 +19,7 @@ file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ #include <testSystemTools.h> -int _doLongPathTest() +static int _doLongPathTest() { using namespace kwsys; static const int LONG_PATH_THRESHOLD = 512; @@ -77,7 +77,7 @@ int _doLongPathTest() return res; } -int _nonExistentDirectoryTest() +static int _nonExistentDirectoryTest() { using namespace kwsys; int res = 0; @@ -105,7 +105,7 @@ int _nonExistentDirectoryTest() return res; } -int _copyDirectoryTest() +static int _copyDirectoryTest() { using namespace kwsys; const std::string source(TEST_SYSTEMTOOLS_BINARY_DIR diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx index 9ba204e..806c01a 100644 --- a/Source/kwsys/testDynamicLoader.cxx +++ b/Source/kwsys/testDynamicLoader.cxx @@ -11,20 +11,20 @@ // Needed for __GLIBC__ test macro. #ifdef __linux__ # include <features.h> -#endif // Will define LIBDL_SO macro on systems with glibc. -#ifdef __GLIBC__ -# include <gnu/lib-names.h> +# ifdef __GLIBC__ +# include <gnu/lib-names.h> // Define to LIBC_SO, if not defined by above header. -# ifndef LIBDL_SO -# define LIBDL_SO LIBC_SO +# ifndef LIBDL_SO +# define LIBDL_SO LIBC_SO +# endif # endif -#endif // Define the LIBDL_SO macro, if not defined above. -#ifndef LIBDL_SO -# define LIBDL_SO "libdl.so" +# ifndef LIBDL_SO +# define LIBDL_SO "libdl.so" +# endif #endif // Work-around CMake dependency scanning limitation. This must @@ -40,6 +40,10 @@ // left on disk. #include <testSystemTools.h> +// For TestDynamicLoaderData, which, though not referenced literally, +// is referenced semantically. +#include "testDynload.h" + static std::string GetLibName(const char* lname, const char* subdir = nullptr) { // Construct proper name of lib diff --git a/Source/kwsys/testDynload.c b/Source/kwsys/testDynload.c index 33a431e..83056c0 100644 --- a/Source/kwsys/testDynload.c +++ b/Source/kwsys/testDynload.c @@ -6,6 +6,8 @@ # define DL_EXPORT #endif +#include "testDynload.h" + DL_EXPORT int TestDynamicLoaderData = 0; DL_EXPORT void TestDynamicLoaderSymbolPointer(void) diff --git a/Source/kwsys/testDynload.h b/Source/kwsys/testDynload.h new file mode 100644 index 0000000..dc0d7a1 --- /dev/null +++ b/Source/kwsys/testDynload.h @@ -0,0 +1,9 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ +#ifdef _WIN32 +# define DL_EXPORT __declspec(dllexport) +#else +# define DL_EXPORT +#endif + +extern DL_EXPORT int TestDynamicLoaderData; diff --git a/Source/kwsys/testEncoding.cxx b/Source/kwsys/testEncoding.cxx index ee93e8d..1d605cb 100644 --- a/Source/kwsys/testEncoding.cxx +++ b/Source/kwsys/testEncoding.cxx @@ -80,7 +80,7 @@ static int testRobustEncoding() std::ios::fmtflags const& flags = std::cout.flags(); int ret = 0; - char cstr[] = { (char)-1, 0 }; + char cstr[] = { static_cast<char>(-1), 0 }; // this conversion could fail std::wstring wstr = kwsys::Encoding::ToWide(cstr); @@ -89,7 +89,7 @@ static int testRobustEncoding() const wchar_t* wcstr = wstr.c_str(); std::cout << "ToWide(NULL) returned"; for (size_t i = 0; i < wstr.size(); i++) { - std::cout << " " << std::hex << (int)wcstr[i]; + std::cout << " " << std::hex << static_cast<int>(wcstr[i]); } std::cout << std::endl; ret++; @@ -99,7 +99,7 @@ static int testRobustEncoding() const wchar_t* wcstr = wstr.c_str(); std::cout << "ToWide(\"\") returned"; for (size_t i = 0; i < wstr.size(); i++) { - std::cout << " " << std::hex << (int)wcstr[i]; + std::cout << " " << std::hex << static_cast<int>(wcstr[i]); } std::cout << std::endl; ret++; @@ -160,7 +160,9 @@ static int testCommandLineArguments() { int status = 0; - char const* argv[2] = { "./app.exe", (char const*)helloWorldStrings[1] }; + char const* argv[2] = { + "./app.exe", reinterpret_cast<char const*>(helloWorldStrings[1]) + }; kwsys::Encoding::CommandLineArguments args(2, argv); kwsys::Encoding::CommandLineArguments arg2 = diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in index 632bb80..c47266a 100644 --- a/Templates/TestDriver.cxx.in +++ b/Templates/TestDriver.cxx.in @@ -63,7 +63,7 @@ static char* lowercase(const char* string) return new_string; } -int isTestSkipped(const char *name, int n_skipped_tests, char *skipped_tests[]) { +static int isTestSkipped(const char *name, int n_skipped_tests, char *skipped_tests[]) { int i; for (i = 0; i < n_skipped_tests; i++) { if (strcmp(name, skipped_tests[i]) == 0) { diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt index 65207d8..1b7e57d 100644 --- a/Tests/Assembler/CMakeLists.txt +++ b/Tests/Assembler/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required (VERSION 3.8) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(Assembler C) message("CTEST_FULL_OUTPUT ") set(CMAKE_VERBOSE_MAKEFILE 1) diff --git a/Tests/BundleTest/BundleLib.cxx b/Tests/BundleTest/BundleLib.cxx index d25ad27..cfb5f7d 100644 --- a/Tests/BundleTest/BundleLib.cxx +++ b/Tests/BundleTest/BundleLib.cxx @@ -20,7 +20,8 @@ int findBundleFile(char* exec, const char* file) { int res; char* nexec = strdup(exec); - char* fpath = (char*)malloc(strlen(exec) + 100); + size_t fpathlen = strlen(nexec) + 1 + strlen(file); + char* fpath = (char*)malloc(fpathlen); int cc; int cnt = 0; printf("Process executable name: %s\n", exec); @@ -36,7 +37,7 @@ int findBundleFile(char* exec, const char* file) } } printf("Process executable path: %s\n", nexec); - sprintf(fpath, "%s/%s", nexec, file); + snprintf(fpath, fpathlen, "%s/%s", nexec, file); printf("Check for file: %s\n", fpath); res = fileExists(fpath); free(nexec); diff --git a/Tests/CMakeCommands/add_compile_options/CMakeLists.txt b/Tests/CMakeCommands/add_compile_options/CMakeLists.txt index 6e5160b..a6b3ffe 100644 --- a/Tests/CMakeCommands/add_compile_options/CMakeLists.txt +++ b/Tests/CMakeCommands/add_compile_options/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 2.8.12) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() + project(add_compile_options) add_compile_options(-DTEST_OPTION) diff --git a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt index 362133e..869a941 100644 --- a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 2.8.12) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() + project(target_compile_options) add_executable(target_compile_options diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt index 07ec4e3..52080bd 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -3,6 +3,10 @@ # 2.8.12 cmake_minimum_required(VERSION 2.8) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() + project(target_link_libraries) file(WRITE diff --git a/Tests/CMakeLib/testCTestBinPacker.cxx b/Tests/CMakeLib/testCTestBinPacker.cxx index abdbefb..772f417 100644 --- a/Tests/CMakeLib/testCTestBinPacker.cxx +++ b/Tests/CMakeLib/testCTestBinPacker.cxx @@ -224,7 +224,7 @@ static const std::vector<AllocationComparison> comparisons{ /* clang-format on */ }; -bool TestExpectedPackResult(const ExpectedPackResult& expected) +static bool TestExpectedPackResult(const ExpectedPackResult& expected) { std::vector<cmCTestBinPackerAllocation> roundRobinAllocations; roundRobinAllocations.reserve(expected.SlotsNeeded.size()); diff --git a/Tests/CMakeLib/testCTestResourceAllocator.cxx b/Tests/CMakeLib/testCTestResourceAllocator.cxx index 33d6b91..72e06e5 100644 --- a/Tests/CMakeLib/testCTestResourceAllocator.cxx +++ b/Tests/CMakeLib/testCTestResourceAllocator.cxx @@ -12,7 +12,7 @@ static const cmCTestResourceSpec spec{ { { /* clang-format on */ } } }; -bool testInitializeFromResourceSpec() +static bool testInitializeFromResourceSpec() { bool retval = true; @@ -39,7 +39,7 @@ bool testInitializeFromResourceSpec() return retval; } -bool testAllocateResource() +static bool testAllocateResource() { bool retval = true; @@ -216,7 +216,7 @@ bool testAllocateResource() return retval; } -bool testDeallocateResource() +static bool testDeallocateResource() { bool retval = true; @@ -370,7 +370,7 @@ bool testDeallocateResource() return retval; } -bool testResourceFree() +static bool testResourceFree() { bool retval = true; diff --git a/Tests/CMakeLib/testCTestResourceGroups.cxx b/Tests/CMakeLib/testCTestResourceGroups.cxx index c3532a6..776d65d 100644 --- a/Tests/CMakeLib/testCTestResourceGroups.cxx +++ b/Tests/CMakeLib/testCTestResourceGroups.cxx @@ -104,7 +104,7 @@ static const std::vector<ExpectedParseResult> expectedResults{ /* clang-format on */ }; -bool TestExpectedParseResult(const ExpectedParseResult& expected) +static bool TestExpectedParseResult(const ExpectedParseResult& expected) { std::vector<std::vector<cmCTestTestHandler::cmCTestTestResourceRequirement>> result; diff --git a/Tests/CMakeLib/testOptional.cxx b/Tests/CMakeLib/testOptional.cxx index 9d4b72a..2007fff 100644 --- a/Tests/CMakeLib/testOptional.cxx +++ b/Tests/CMakeLib/testOptional.cxx @@ -116,7 +116,7 @@ public: # define END_IGNORE_UNINITIALIZED #endif -void swap(EventLogger& e1, EventLogger& e2) +static void swap(EventLogger& e1, EventLogger& e2) { BEGIN_IGNORE_UNINITIALIZED events.push_back({ Event::SWAP, &e1, &e2, e2.Value }); @@ -180,37 +180,37 @@ EventLogger& EventLogger::operator=(int value) return *this; } -bool operator==(const EventLogger& lhs, const EventLogger& rhs) +static bool operator==(const EventLogger& lhs, const EventLogger& rhs) { events.push_back({ Event::COMPARE_EE_EQ, &lhs, &rhs, lhs.Value }); return lhs.Value == rhs.Value; } -bool operator!=(const EventLogger& lhs, const EventLogger& rhs) +static bool operator!=(const EventLogger& lhs, const EventLogger& rhs) { events.push_back({ Event::COMPARE_EE_NE, &lhs, &rhs, lhs.Value }); return lhs.Value != rhs.Value; } -bool operator<(const EventLogger& lhs, const EventLogger& rhs) +static bool operator<(const EventLogger& lhs, const EventLogger& rhs) { events.push_back({ Event::COMPARE_EE_LT, &lhs, &rhs, lhs.Value }); return lhs.Value < rhs.Value; } -bool operator<=(const EventLogger& lhs, const EventLogger& rhs) +static bool operator<=(const EventLogger& lhs, const EventLogger& rhs) { events.push_back({ Event::COMPARE_EE_LE, &lhs, &rhs, lhs.Value }); return lhs.Value <= rhs.Value; } -bool operator>(const EventLogger& lhs, const EventLogger& rhs) +static bool operator>(const EventLogger& lhs, const EventLogger& rhs) { events.push_back({ Event::COMPARE_EE_GT, &lhs, &rhs, lhs.Value }); return lhs.Value > rhs.Value; } -bool operator>=(const EventLogger& lhs, const EventLogger& rhs) +static bool operator>=(const EventLogger& lhs, const EventLogger& rhs) { events.push_back({ Event::COMPARE_EE_GE, &lhs, &rhs, lhs.Value }); return lhs.Value >= rhs.Value; diff --git a/Tests/CMakeLib/testRST.cxx b/Tests/CMakeLib/testRST.cxx index 28d80a5..77f2a66 100644 --- a/Tests/CMakeLib/testRST.cxx +++ b/Tests/CMakeLib/testRST.cxx @@ -8,7 +8,8 @@ #include "cmRST.h" #include "cmSystemTools.h" -void reportLine(std::ostream& os, bool ret, std::string const& line, bool eol) +static void reportLine(std::ostream& os, bool ret, std::string const& line, + bool eol) { if (ret) { os << "\"" << line << "\" (" << (eol ? "with EOL" : "without EOL") << ")"; diff --git a/Tests/CMakeLib/testRST.expect b/Tests/CMakeLib/testRST.expect index 4870f65..5e3cdb1 100644 --- a/Tests/CMakeLib/testRST.expect +++ b/Tests/CMakeLib/testRST.expect @@ -116,6 +116,12 @@ A literal block can be empty:: .. note:: Notes are called out. +.. versionadded:: 1.2 + Version blocks are preserved. + +.. versionchanged:: 2.3 + Version blocks are preserved. + substituted text with multiple lines becomes one line End of first include. diff --git a/Tests/CMakeLib/testRST.rst b/Tests/CMakeLib/testRST.rst index 44931a7..4139801 100644 --- a/Tests/CMakeLib/testRST.rst +++ b/Tests/CMakeLib/testRST.rst @@ -123,6 +123,12 @@ A literal block can be empty:: .. note:: Notes are called out. +.. versionadded:: 1.2 + Version blocks are preserved. + +.. versionchanged:: 2.3 + Version blocks are preserved. + .. |substitution| replace:: |nested substitution| with multiple lines becomes one line diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx index a003205..c924083 100644 --- a/Tests/CMakeLib/testUVProcessChain.cxx +++ b/Tests/CMakeLib/testUVProcessChain.cxx @@ -64,14 +64,15 @@ bool operator==(const cmUVProcessChain::Status* actual, return true; } -bool resultsMatch(const std::vector<const cmUVProcessChain::Status*>& actual, - const std::vector<ExpectedStatus>& expected) +static bool resultsMatch( + const std::vector<const cmUVProcessChain::Status*>& actual, + const std::vector<ExpectedStatus>& expected) { return actual.size() == expected.size() && std::equal(actual.begin(), actual.end(), expected.begin()); } -std::string getInput(std::istream& input) +static std::string getInput(std::istream& input) { char buffer[1024]; std::ostringstream str; @@ -103,8 +104,9 @@ std::ostream& operator<<( return func(stream); } -void printResults(const std::vector<const cmUVProcessChain::Status*>& actual, - const std::vector<ExpectedStatus>& expected) +static void printResults( + const std::vector<const cmUVProcessChain::Status*>& actual, + const std::vector<ExpectedStatus>& expected) { std::cout << "Expected: " << std::endl; for (auto const& e : expected) { @@ -129,8 +131,8 @@ void printResults(const std::vector<const cmUVProcessChain::Status*>& actual, } } -bool checkExecution(cmUVProcessChainBuilder& builder, - std::unique_ptr<cmUVProcessChain>& chain) +static bool checkExecution(cmUVProcessChainBuilder& builder, + std::unique_ptr<cmUVProcessChain>& chain) { std::vector<const cmUVProcessChain::Status*> status; @@ -171,7 +173,7 @@ bool checkExecution(cmUVProcessChainBuilder& builder, return true; } -bool checkOutput(std::istream& outputStream, std::istream& errorStream) +static bool checkOutput(std::istream& outputStream, std::istream& errorStream) { std::string output = getInput(outputStream); if (output != "HELO WRD!") { diff --git a/Tests/CMakeLib/testUVProcessChainHelper.cxx b/Tests/CMakeLib/testUVProcessChainHelper.cxx index 9c25834..bc0ef8e 100644 --- a/Tests/CMakeLib/testUVProcessChainHelper.cxx +++ b/Tests/CMakeLib/testUVProcessChainHelper.cxx @@ -7,7 +7,7 @@ #include <string> #include <thread> -std::string getStdin() +static std::string getStdin() { char buffer[1024]; std::ostringstream str; diff --git a/Tests/CMakeLib/testUVStreambuf.cxx b/Tests/CMakeLib/testUVStreambuf.cxx index b86ed76..760fa29 100644 --- a/Tests/CMakeLib/testUVStreambuf.cxx +++ b/Tests/CMakeLib/testUVStreambuf.cxx @@ -15,9 +15,10 @@ #define TEST_STR_LINE_3 "with libuv's uv_stream_t." #define TEST_STR TEST_STR_LINE_1 "\n" TEST_STR_LINE_2 "\n" TEST_STR_LINE_3 -bool writeDataToStreamPipe(uv_loop_t& loop, cm::uv_pipe_ptr& inputPipe, - char* outputData, unsigned int outputDataLength, - const char* /* unused */) +static bool writeDataToStreamPipe(uv_loop_t& loop, cm::uv_pipe_ptr& inputPipe, + char* outputData, + unsigned int outputDataLength, + const char* /* unused */) { int err; @@ -66,9 +67,11 @@ bool writeDataToStreamPipe(uv_loop_t& loop, cm::uv_pipe_ptr& inputPipe, return true; } -bool writeDataToStreamProcess(uv_loop_t& loop, cm::uv_pipe_ptr& inputPipe, - char* outputData, unsigned int /* unused */, - const char* cmakeCommand) +static bool writeDataToStreamProcess(uv_loop_t& loop, + cm::uv_pipe_ptr& inputPipe, + char* outputData, + unsigned int /* unused */, + const char* cmakeCommand) { int err; @@ -130,7 +133,7 @@ bool writeDataToStreamProcess(uv_loop_t& loop, cm::uv_pipe_ptr& inputPipe, return true; } -bool testUVStreambufRead( +static bool testUVStreambufRead( bool (*cb)(uv_loop_t& loop, cm::uv_pipe_ptr& inputPipe, char* outputData, unsigned int outputDataLength, const char* cmakeCommand), const char* cmakeCommand) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 7a8e362..d2cfa3f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1380,6 +1380,13 @@ if(BUILD_TESTING) --test-command ${CMAKE_CTEST_COMMAND} -V ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Environment") + set_property(TEST Environment APPEND + PROPERTY ENVIRONMENT + "SET_FROM_AMBIENT_unset=base" + "SET_FROM_AMBIENT_replace=base" + "SET_FROM_AMBIENT_string=base" + "SET_FROM_AMBIENT_path=base" + "SET_FROM_AMBIENT_list=base") add_test(QtAutomocNoQt ${CMAKE_CTEST_COMMAND} --build-and-test diff --git a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt index 9c203c7..c7e3105 100644 --- a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 2.8.12) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(CheckCXXCompilerFlag) message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") diff --git a/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt index 9a9bb2a..3d65b7a 100644 --- a/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt @@ -48,4 +48,15 @@ if (CMAKE_COMPILER_IS_GNUCC) if (CSE_RESULT_O3) message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3") endif () + + string(APPEND CMAKE_C_FLAGS " -pedantic-errors") + unset(CS_RESULT_PEDANTIC_ERRORS CACHE) + message(STATUS "Testing with -pedantic-errors") + + check_symbol_exists(fopen "stdio.h" CSE_RESULT_PEDANTIC_ERRORS) + + if(NOT CSE_RESULT_PEDANTIC_ERRORS) + message(SEND_ERROR "CheckSymbolExists reported an existing symbol as nonexisting with -pedantic-errors") + endif() + endif () diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt index e6db5b7..0fbfb83 100644 --- a/Tests/CompileOptions/CMakeLists.txt +++ b/Tests/CompileOptions/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.0) if(POLICY CMP0092) cmake_policy(SET CMP0092 NEW) endif() +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(NOT _isMultiConfig AND NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build" FORCE) diff --git a/Tests/Environment/CMakeLists.txt b/Tests/Environment/CMakeLists.txt index 17009bd..abcf33c 100644 --- a/Tests/Environment/CMakeLists.txt +++ b/Tests/Environment/CMakeLists.txt @@ -27,7 +27,31 @@ set_tests_properties(Environment2 EchoEnvironment2 PROPERTIES ) set_property(TEST EchoEnvironment3 + PROPERTY ENVIRONMENT + "SET_FROM_ENVIRONMENT_PROPERTY_unset=base" + "SET_FROM_ENVIRONMENT_PROPERTY_replace=base" + "SET_FROM_ENVIRONMENT_PROPERTY_string=base" + "SET_FROM_ENVIRONMENT_PROPERTY_path=base" + "SET_FROM_ENVIRONMENT_PROPERTY_list=base" +) + +set_property(TEST EchoEnvironment3 PROPERTY ENVIRONMENT_MODIFICATION + # Modifying variables set in the ambient environment (see properties for + # this test in `Tests/CMakeLists.txt`). + "SET_FROM_AMBIENT_unset=unset:" + "SET_FROM_AMBIENT_replace=set:new" + "SET_FROM_AMBIENT_string=string_append:new" + "SET_FROM_AMBIENT_path=path_list_append:new" + "SET_FROM_AMBIENT_list=cmake_list_append:new" + + # Modifying variables set in the `ENVIRONMENT` property. + "SET_FROM_ENVIRONMENT_PROPERTY_unset=unset:" + "SET_FROM_ENVIRONMENT_PROPERTY_replace=set:new" + "SET_FROM_ENVIRONMENT_PROPERTY_string=string_append:new" + "SET_FROM_ENVIRONMENT_PROPERTY_path=path_list_append:new" + "SET_FROM_ENVIRONMENT_PROPERTY_list=cmake_list_append:new" + # Variables expected to be unset. "UNSET_EXPLICIT=set:value" "UNSET_EXPLICIT=unset:" @@ -45,6 +69,12 @@ set_property(TEST EchoEnvironment3 "STRING_MANIP=string_append:suffix" "STRING_MANIP=string_prepend:prefix" + # String manipulation on non-existent. + "STRING_DNE=string_append:post-" + "STRING_DNE=string_prepend:-pre" + "STRING_DNE=string_append:suffix" + "STRING_DNE=string_prepend:prefix" + # Path manipulation. "PATH_MANIP=set:core" "PATH_MANIP=path_list_append:post" @@ -52,10 +82,22 @@ set_property(TEST EchoEnvironment3 "PATH_MANIP=path_list_append:suffix" "PATH_MANIP=path_list_prepend:prefix" + # Path manipulation on non-existent. + "PATH_DNE=path_list_append:post" + "PATH_DNE=path_list_prepend:pre" + "PATH_DNE=path_list_append:suffix" + "PATH_DNE=path_list_prepend:prefix" + # CMake list manipulation. "CMAKE_LIST_MANIP=set:core" "CMAKE_LIST_MANIP=cmake_list_append:post" "CMAKE_LIST_MANIP=cmake_list_prepend:pre" "CMAKE_LIST_MANIP=cmake_list_append:suffix" "CMAKE_LIST_MANIP=cmake_list_prepend:prefix" + + # CMake list manipulation on non-existent. + "CMAKE_LIST_DNE=cmake_list_append:post" + "CMAKE_LIST_DNE=cmake_list_prepend:pre" + "CMAKE_LIST_DNE=cmake_list_append:suffix" + "CMAKE_LIST_DNE=cmake_list_prepend:prefix" ) diff --git a/Tests/Environment/check_mod.cmake b/Tests/Environment/check_mod.cmake index 16d02f2..0f885f0 100644 --- a/Tests/Environment/check_mod.cmake +++ b/Tests/Environment/check_mod.cmake @@ -14,18 +14,42 @@ else () set(path_sep ":") endif () +set(unexpect_SET_FROM_AMBIENT_unset "") +set(unexpect_SET_FROM_ENVIRONMENT_PROPERTY_unset "") set(unexpect_UNSET_EXPLICIT "") set(unexpect_UNSET_VIA_RESET "") set(expect_DIRECT "new") set(expect_STRING_MANIP "prefix-pre-core-post-suffix") set(expect_PATH_MANIP "prefix${path_sep}pre${path_sep}core${path_sep}post${path_sep}suffix") set(expect_CMAKE_LIST_MANIP "prefix;pre;core;post;suffix") +set(expect_STRING_DNE "prefix-prepost-suffix") +set(expect_PATH_DNE "prefix${path_sep}pre${path_sep}post${path_sep}suffix") +set(expect_CMAKE_LIST_DNE "prefix;pre;post;suffix") +set(expect_SET_FROM_AMBIENT_replace "new") +set(expect_SET_FROM_AMBIENT_string "basenew") +set(expect_SET_FROM_AMBIENT_path "base${path_sep}new") +set(expect_SET_FROM_AMBIENT_list "base;new") +set(expect_SET_FROM_ENVIRONMENT_PROPERTY_replace "new") +set(expect_SET_FROM_ENVIRONMENT_PROPERTY_string "basenew") +set(expect_SET_FROM_ENVIRONMENT_PROPERTY_path "base${path_sep}new") +set(expect_SET_FROM_ENVIRONMENT_PROPERTY_list "base;new") set(expected_vars + SET_FROM_AMBIENT_replace + SET_FROM_AMBIENT_string + SET_FROM_AMBIENT_path + SET_FROM_AMBIENT_list + SET_FROM_ENVIRONMENT_PROPERTY_replace + SET_FROM_ENVIRONMENT_PROPERTY_string + SET_FROM_ENVIRONMENT_PROPERTY_path + SET_FROM_ENVIRONMENT_PROPERTY_list DIRECT STRING_MANIP PATH_MANIP - CMAKE_LIST_MANIP) + CMAKE_LIST_MANIP + STRING_DNE + PATH_DNE + CMAKE_LIST_DNE) while (out) string(FIND "${out}" "\n" nl_pos) diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 3a490c2..a79efd0 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required (VERSION 2.7.20090711) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(Export C CXX) # Pretend that RelWithDebInfo should link to debug libraries to test diff --git a/Tests/ExportImport/Import/CMakeLists.txt b/Tests/ExportImport/Import/CMakeLists.txt index 0063130..e6dcd65 100644 --- a/Tests/ExportImport/Import/CMakeLists.txt +++ b/Tests/ExportImport/Import/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required (VERSION 2.7.20090711) cmake_policy(SET CMP0025 NEW) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(Import C CXX) # Import everything in a subdirectory. diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index 69899e9..cdc08c4 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required (VERSION 3.1) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(testf C CXX Fortran) message("CTEST_FULL_OUTPUT ") diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt index dd29fe5..5be1e97 100644 --- a/Tests/IncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required (VERSION 2.6) -project(IncludeDirectories) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() + +project(IncludeDirectories) if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4) OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") OR CMAKE_C_COMPILER_ID STREQUAL AppleClang diff --git a/Tests/LinkStatic/CMakeLists.txt b/Tests/LinkStatic/CMakeLists.txt index 60a270b..ad3b111 100644 --- a/Tests/LinkStatic/CMakeLists.txt +++ b/Tests/LinkStatic/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 2.8.4.20110303 FATAL_ERROR) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(LinkStatic C) if(NOT CMAKE_C_COMPILER_ID MATCHES "GNU|LCC") diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt index 694073a..8898f3b 100644 --- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt +++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 3.1.0) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(WriteCompilerDetectionHeader) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/Tests/RunCMake/CMP0129/C.cmake b/Tests/RunCMake/CMP0129/C.cmake new file mode 100644 index 0000000..e9ebe90 --- /dev/null +++ b/Tests/RunCMake/CMP0129/C.cmake @@ -0,0 +1,8 @@ +if(SET_CMP0129) + cmake_policy(SET CMP0129 ${SET_CMP0129}) +endif() + +enable_language(C) +set(CMAKE_VERBOSE_MAKEFILE TRUE) +include(CompareCompilerVersion.cmake) +compare_compiler_version(C) diff --git a/Tests/RunCMake/CMP0129/CMakeLists.txt b/Tests/RunCMake/CMP0129/CMakeLists.txt new file mode 100644 index 0000000..d8200fc --- /dev/null +++ b/Tests/RunCMake/CMP0129/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.22) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CMP0129/CXX.cmake b/Tests/RunCMake/CMP0129/CXX.cmake new file mode 100644 index 0000000..ffb81b8 --- /dev/null +++ b/Tests/RunCMake/CMP0129/CXX.cmake @@ -0,0 +1,8 @@ +if(SET_CMP0129) + cmake_policy(SET CMP0129 ${SET_CMP0129}) +endif() + +enable_language(CXX) +set(CMAKE_VERBOSE_MAKEFILE TRUE) +include(CompareCompilerVersion.cmake) +compare_compiler_version(CXX) diff --git a/Tests/RunCMake/CMP0129/CompareCompilerVersion.cmake b/Tests/RunCMake/CMP0129/CompareCompilerVersion.cmake new file mode 100644 index 0000000..e4ba191 --- /dev/null +++ b/Tests/RunCMake/CMP0129/CompareCompilerVersion.cmake @@ -0,0 +1,41 @@ +function(compare_compiler_version lang) + cmake_policy(GET CMP0129 LCC_FALLBACK_MODE) + if(${CMAKE_${lang}_COMPILER} STREQUAL "LCC" OR ${CMAKE_${lang}_COMPILER} STREQUAL "GNU") + execute_process(COMMAND ${CMAKE_${lang}_COMPILER} --version OUTPUT_VARIABLE output) + if("${output}" MATCHES [[lcc:([0-9]+.[0-9]+.([0-9]+)):]]) + set(native_version ${CMAKE_MATCH_1}) + else() + message(FATAL_ERROR "Can not identify native LCC version for language ${lang}.") + endif() + if("${output}" MATCHES [[\(GCC\) ([0-9]+.[0-9]+.([0-9]+)) compatible]]) + set(simulated_version ${CMAKE_MATCH_1}) + else() + message(FATAL_ERROR "Can not identify simulated GNU version for language ${lang}.") + endif() + message(STATUS "Compiler native version is ${native_version}, simulated version is ${simulated_version}.") + if("${LCC_FALLBACK_MODE}" STREQUAL "NEW") + if(NOT "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "LCC") + message(FATAL_ERROR "Policy is in NEW mode, but compiler identification is ${CMAKE_${lang}_COMPILER_ID} instead of LCC.") + endif() + if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" STREQUAL "${native_version}") + message(FATAL_ERROR "Policy is in NEW mode, but compiler version is ${CMAKE_${lang}_COMPILER_VERSION} instead of ${native_version}.") + endif() + if(NOT "${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "GNU") + message(FATAL_ERROR "Policy is in NEW mode, but simulated compiler identification is ${CMAKE_${lang}_SIMULATE_ID} instead of GNU.") + endif() + if(NOT "${CMAKE_${lang}_SIMULATE_VERSION}" STREQUAL "${simulated_version}") + message(FATAL_ERROR "Policy is in NEW mode, but simulated compiler version is ${CMAKE_${lang}_SIMULATE_VERSION} instead of ${simulated_version}.") + endif() + else() + if(NOT "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "GNU") + message(FATAL_ERROR "Policy is in OLD mode, but compiler identification is ${CMAKE_${lang}_COMPILER_ID} instead of GNU.") + endif() + if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" STREQUAL "${simulated_version}") + message(FATAL_ERROR "Policy is in OLD mode, but compiler version is ${CMAKE_${lang}_COMPILER_VERSION} instead of ${simulated_version}.") + endif() + if(${CMAKE_${lang}_SIMULATE_VERSION} OR ${CMAKE_${lang}_SIMULATE_ID) + message(FATAL_ERROR "Policy is in OLD mode, but simulated compiler ID/version is ${CMAKE_${lang}_COMPILER_ID}/${CMAKE_${lang}_COMPILER_VERSION} instead of undefined.") + endif() + endif() + endif() +endfunction() diff --git a/Tests/RunCMake/CMP0129/Fortran.cmake b/Tests/RunCMake/CMP0129/Fortran.cmake new file mode 100644 index 0000000..abaca7e --- /dev/null +++ b/Tests/RunCMake/CMP0129/Fortran.cmake @@ -0,0 +1,15 @@ +include(CheckLanguage) +check_language(Fortran) +if(NOT CMAKE_Fortran_COMPILER) + # No Fortran compiler, skipping Fortran test + return() +endif() + +if(SET_CMP0129) + cmake_policy(SET CMP0129 ${SET_CMP0129}) +endif() + +enable_language(Fortran) +set(CMAKE_VERBOSE_MAKEFILE TRUE) +include(CompareCompilerVersion.cmake) +compare_compiler_version(Fortran) diff --git a/Tests/RunCMake/CMP0129/RunCMakeTest.cmake b/Tests/RunCMake/CMP0129/RunCMakeTest.cmake new file mode 100644 index 0000000..1b0e11b --- /dev/null +++ b/Tests/RunCMake/CMP0129/RunCMakeTest.cmake @@ -0,0 +1,8 @@ +set(RunCMake_TEST_NO_CMP0129 ON) +include(RunCMake) + +foreach(lang C CXX Fortran) + run_cmake(${lang}) + run_cmake_with_options(${lang} "-DSET_CMP0129=NEW") + run_cmake_with_options(${lang} "-DSET_CMP0129=OLD") +endforeach() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index c566b42..5dc7031 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -345,7 +345,7 @@ if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG AND CMAKE_EXECUTABLE_FORMAT STRE add_RunCMake_test(RuntimePath) endif() add_RunCMake_test(ScriptMode) -add_RunCMake_test(Swift -DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER}) +add_RunCMake_test(Swift -DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) add_RunCMake_test(TargetObjects) add_RunCMake_test(TargetProperties) add_RunCMake_test(ToolchainFile) @@ -927,3 +927,7 @@ endif() if(WIN32) add_RunCMake_test(Win32GenEx) endif() + +if("${CMAKE_C_COMPILER_ID}" STREQUAL "LCC" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "LCC" OR "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "LCC") + add_RunCMake_test("CMP0129") +endif() diff --git a/Tests/RunCMake/CPack/CMakeLists.txt b/Tests/RunCMake/CPack/CMakeLists.txt index 1b3dbb2..c81b34e 100644 --- a/Tests/RunCMake/CPack/CMakeLists.txt +++ b/Tests/RunCMake/CPack/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "") project(${RunCMake_TEST} CXX) diff --git a/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt b/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt index 0421e28..30cb9ae 100644 --- a/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt +++ b/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.13) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() + project(${RunCMake_TEST} LANGUAGES NONE) include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt index 3df3e52..6a932f1 100644 --- a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt +++ b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt @@ -1 +1 @@ -^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":3}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]},{"kind":"toolchains","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":false,"version":{.*}}$ +^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":4}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]},{"kind":"toolchains","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":false,"version":{.*}}$ diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 92a64f9..b31088d 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -12,7 +12,7 @@ def read_codemodel_json_data(filename): def check_objects(o, g): assert is_list(o) assert len(o) == 1 - check_index_object(o[0], "codemodel", 2, 3, check_object_codemodel(g)) + check_index_object(o[0], "codemodel", 2, 4, check_object_codemodel(g)) def check_backtrace(t, b, backtrace): btg = t["backtraceGraph"] @@ -188,6 +188,31 @@ def check_directory(c): expected_keys.append("runtimeDependencySetType") assert is_string(a["runtimeDependencySetType"], e["runtimeDependencySetType"]) + if e.get("fileSetName", None) is not None: + expected_keys.append("fileSetName") + assert is_string(a["fileSetName"], e["fileSetName"]) + + if e.get("fileSetType", None) is not None: + expected_keys.append("fileSetType") + assert is_string(a["fileSetType"], e["fileSetType"]) + + if e.get("fileSetDirectories", None) is not None: + expected_keys.append("fileSetDirectories") + assert is_list(a["fileSetDirectories"]) + assert len(a["fileSetDirectories"]) == len(e["fileSetDirectories"]) + for ad, ed in zip(a["fileSetDirectories"], e["fileSetDirectories"]): + assert matches(ad, ed) + + if e.get("fileSetTarget", None) is not None: + expected_keys.append("fileSetTarget") + et = e["fileSetTarget"] + at = a["fileSetTarget"] + assert is_dict(at) + assert sorted(at.keys()) == ["id", "index"] + assert matches(at["id"], et["id"]) + assert is_int(at["index"]) + assert c["targets"][at["index"]]["name"] == et["index"] + if e["backtrace"] is not None: expected_keys.append("backtrace") check_backtrace(d, a["backtrace"], e["backtrace"]) @@ -628,6 +653,7 @@ def gen_check_directories(c, g): read_codemodel_json_data("directories/dir.json"), read_codemodel_json_data("directories/dir_dir.json"), read_codemodel_json_data("directories/external.json"), + read_codemodel_json_data("directories/fileset.json"), ] if matches(g["name"], "^Visual Studio "): @@ -729,6 +755,9 @@ def gen_check_targets(c, g, inSource): read_codemodel_json_data("targets/all_build_external.json"), read_codemodel_json_data("targets/zero_check_external.json"), read_codemodel_json_data("targets/generated_exe.json"), + + read_codemodel_json_data("targets/c_headers_1.json"), + read_codemodel_json_data("targets/c_headers_2.json"), ] if cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero'] and g["name"] != "Xcode": diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json new file mode 100644 index 0000000..4774a13 --- /dev/null +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json @@ -0,0 +1,203 @@ +{ + "source": "^fileset$", + "build": "^fileset$", + "parentSource": "^\\.$", + "childSources": null, + "targetIds": [ + "^c_headers_1::@6b8db101d64c125f29fe$", + "^c_headers_2::@6b8db101d64c125f29fe$" + ], + "projectName": "codemodel-v2", + "minimumCMakeVersion": "3.12", + "hasInstallRule": true, + "installers": [ + { + "component": "Unspecified", + "type": "target", + "destination": "lib", + "paths": [ + "^fileset/((Debug|Release|MinSizeRel|RelWithDebInfo)/)?(lib)?c_headers_1\\.(a|lib)?$" + ], + "isExcludeFromAll": null, + "isForAllComponents": null, + "isOptional": null, + "targetId": "^c_headers_1::@6b8db101d64c125f29fe$", + "targetIndex": "c_headers_1", + "targetIsImportLibrary": null, + "targetInstallNamelink": null, + "exportName": null, + "exportTargets": null, + "scriptFile": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 20, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "component": "Headers", + "type": "fileSet", + "destination": "include", + "paths": [ + "^fileset/error\\.c$", + "^fileset/other\\.c$" + ], + "isExcludeFromAll": null, + "isForAllComponents": null, + "isOptional": null, + "targetId": null, + "targetIndex": null, + "targetIsImportLibrary": null, + "targetInstallNamelink": null, + "exportName": null, + "exportTargets": null, + "scriptFile": null, + "fileSetName": "HEADERS", + "fileSetType": "HEADERS", + "fileSetDirectories": [ + "^fileset$" + ], + "fileSetTarget": { + "id": "^c_headers_1::@6b8db101d64c125f29fe$", + "index": "c_headers_1" + }, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 20, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "component": "Unspecified", + "type": "fileSet", + "destination": "include/dir", + "paths": [ + "^fileset/dir/h2\\.h$" + ], + "isExcludeFromAll": null, + "isForAllComponents": null, + "isOptional": null, + "targetId": null, + "targetIndex": null, + "targetIsImportLibrary": null, + "targetInstallNamelink": null, + "exportName": null, + "exportTargets": null, + "scriptFile": null, + "fileSetName": "b", + "fileSetType": "HEADERS", + "fileSetDirectories": [ + "^fileset/dir$" + ], + "fileSetTarget": { + "id": "^c_headers_1::@6b8db101d64c125f29fe$", + "index": "c_headers_1" + }, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 20, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "component": "Unspecified", + "type": "fileSet", + "destination": "include", + "paths": [ + "^fileset/h3\\.h$" + ], + "isExcludeFromAll": null, + "isForAllComponents": null, + "isOptional": null, + "targetId": null, + "targetIndex": null, + "targetIsImportLibrary": null, + "targetInstallNamelink": null, + "exportName": null, + "exportTargets": null, + "scriptFile": null, + "fileSetName": "c", + "fileSetType": "HEADERS", + "fileSetDirectories": [ + "^fileset$" + ], + "fileSetTarget": { + "id": "^c_headers_1::@6b8db101d64c125f29fe$", + "index": "c_headers_1" + }, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 20, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "component": "Unspecified", + "type": "target", + "destination": "lib", + "paths": [ + "^fileset/((Debug|Release|MinSizeRel|RelWithDebInfo)/)?(lib)?c_headers_2\\.(a|lib)?$" + ], + "isExcludeFromAll": null, + "isForAllComponents": null, + "isOptional": null, + "targetId": "^c_headers_2::@6b8db101d64c125f29fe$", + "targetIndex": "c_headers_2", + "targetIsImportLibrary": null, + "targetInstallNamelink": null, + "exportName": null, + "exportTargets": null, + "scriptFile": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 25, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] +} diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json index 99287fb..22b4536 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json @@ -10,7 +10,8 @@ "^interface$", "^object$", "^.*/Tests/RunCMake/FileAPIExternalSource$", - "^dir$" + "^dir$", + "^fileset$" ], "targetIds": [ "^ALL_BUILD::@6890427a1f51a3e7e1df$", @@ -47,7 +48,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 38, + "line": 39, "command": "install", "hasParent": true }, @@ -92,7 +93,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -140,7 +141,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -185,7 +186,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -229,7 +230,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -273,7 +274,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 46, + "line": 47, "command": "install", "hasParent": true }, @@ -320,7 +321,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 48, + "line": 49, "command": "install", "hasParent": true }, @@ -365,7 +366,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 49, + "line": 50, "command": "install", "hasParent": true }, @@ -414,7 +415,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 50, + "line": 51, "command": "install", "hasParent": true }, @@ -466,7 +467,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 51, + "line": 52, "command": "install", "hasParent": true }, @@ -515,7 +516,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 52, + "line": 53, "command": "install", "hasParent": true }, @@ -557,7 +558,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 53, + "line": 54, "command": "install", "hasParent": true }, @@ -599,7 +600,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 54, + "line": 55, "command": "install", "hasParent": true }, diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json index 4d0cdc0..0d6c4a1 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json @@ -13,7 +13,8 @@ "directorySources": [ "^\\.$", "^dir$", - "^dir/dir$" + "^dir/dir$", + "^fileset$" ], "targetIds": [ "^ALL_BUILD::@6890427a1f51a3e7e1df$", @@ -24,6 +25,8 @@ "^c_shared_lib::@6890427a1f51a3e7e1df$", "^c_shared_exe::@6890427a1f51a3e7e1df$", "^c_static_lib::@6890427a1f51a3e7e1df$", - "^c_static_exe::@6890427a1f51a3e7e1df$" + "^c_static_exe::@6890427a1f51a3e7e1df$", + "^c_headers_1::@6b8db101d64c125f29fe$", + "^c_headers_2::@6b8db101d64c125f29fe$" ] } diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json index d023f99..4e772a7 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json @@ -186,6 +186,14 @@ { "id": "^generated_exe::@[0-9a-f]+$", "backtrace": null + }, + { + "id": "^c_headers_1::@6b8db101d64c125f29fe$", + "backtrace": null + }, + { + "id": "^c_headers_2::@6b8db101d64c125f29fe$", + "backtrace": null } ] } diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json new file mode 100644 index 0000000..c189623 --- /dev/null +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json @@ -0,0 +1,231 @@ +{ + "name": "c_headers_1", + "id": "^c_headers_1::@6b8db101d64c125f29fe$", + "directorySource": "^fileset$", + "projectName": "codemodel-v2", + "type": "STATIC_LIBRARY", + "isGeneratorProvided": null, + "sources": [ + { + "path": "^fileset/empty\\.c$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "C", + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 1, + "command": "add_library", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^fileset/error\\.c$", + "isGenerated": null, + "sourceGroupName": "Header Files", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 3, + "command": "target_sources", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^fileset/other\\.c$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 3, + "command": "target_sources", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^fileset/h1\\.h$", + "isGenerated": null, + "sourceGroupName": "Header Files", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 3, + "command": "target_sources", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^fileset/dir/h2\\.h$", + "isGenerated": null, + "sourceGroupName": "Header Files", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 7, + "command": "target_sources", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], + "sourceGroups": [ + { + "name": "Source Files", + "sourcePaths": [ + "^fileset/empty\\.c$", + "^fileset/other\\.c$" + ] + }, + { + "name": "Header Files", + "sourcePaths": [ + "^fileset/error\\.c$", + "^fileset/h1\\.h$", + "^fileset/dir/h2\\.h$" + ] + } + ], + "compileGroups": [ + { + "language": "C", + "sourcePaths": [ + "^fileset/empty\\.c$" + ], + "includes": [ + { + "path": "^.*/Tests/RunCMake/FileAPI/fileset$", + "isSystem": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 3, + "command": "target_sources", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^.*/Tests/RunCMake/FileAPI/fileset/dir$", + "isSystem": null, + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 7, + "command": "target_sources", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], + "defines": null, + "compileCommandFragments": null + } + ], + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 1, + "command": "add_library", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ], + "folder": null, + "nameOnDisk": "^(lib)?c_headers_1\\.(a|lib)$", + "artifacts": [ + { + "path": "^fileset/((Debug|Release|RelWithDebInfo|MinSizeRel)/)?(lib)?c_headers_1\\.(a|lib)$", + "_dllExtra": false + } + ], + "build": "^fileset$", + "source": "^fileset$", + "install": { + "prefix": "^(/usr/local|[A-Za-z]:.*/codemodel-v2)$", + "destinations": [ + { + "path": "lib", + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 20, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + }, + "link": null, + "archive": { + "lto": null + }, + "dependencies": [ + { + "id": "^ZERO_CHECK::@6890427a1f51a3e7e1df$", + "backtrace": null + } + ] +} diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json new file mode 100644 index 0000000..75fe58c --- /dev/null +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json @@ -0,0 +1,105 @@ +{ + "name": "c_headers_2", + "id": "^c_headers_2::@6b8db101d64c125f29fe$", + "directorySource": "^fileset$", + "projectName": "codemodel-v2", + "type": "STATIC_LIBRARY", + "isGeneratorProvided": null, + "sources": [ + { + "path": "^fileset/empty\\.c$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "C", + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 15, + "command": "add_library", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], + "sourceGroups": [ + { + "name": "Source Files", + "sourcePaths": [ + "^fileset/empty\\.c$" + ] + } + ], + "compileGroups": [ + { + "language": "C", + "sourcePaths": [ + "^fileset/empty\\.c$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": null + } + ], + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 15, + "command": "add_library", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ], + "folder": null, + "nameOnDisk": "^(lib)?c_headers_2\\.(a|lib)$", + "artifacts": [ + { + "path": "^fileset/((Debug|Release|RelWithDebInfo|MinSizeRel)/)?(lib)?c_headers_2\\.(a|lib)$", + "_dllExtra": false + } + ], + "build": "^fileset$", + "source": "^fileset$", + "install": { + "prefix": "^(/usr/local|[A-Za-z]:.*/codemodel-v2)$", + "destinations": [ + { + "path": "lib", + "backtrace": [ + { + "file": "^fileset/CMakeLists\\.txt$", + "line": 25, + "command": "install", + "hasParent": true + }, + { + "file": "^fileset/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + }, + "link": null, + "archive": { + "lto": null + }, + "dependencies": [ + { + "id": "^ZERO_CHECK::@6890427a1f51a3e7e1df$", + "backtrace": null + } + ] +} diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json index e3a8d0b..b4318dd 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json @@ -115,7 +115,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -145,7 +145,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -175,7 +175,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 46, + "line": 47, "command": "install", "hasParent": true }, diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json index 385fa62..5769f0c 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json @@ -136,7 +136,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 38, + "line": 39, "command": "install", "hasParent": true }, diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json index 73e8e12..1fe4d67 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json @@ -91,7 +91,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -121,7 +121,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 41, + "line": 42, "command": "install", "hasParent": true }, @@ -151,7 +151,7 @@ "backtrace": [ { "file": "^codemodel-v2\\.cmake$", - "line": 46, + "line": 47, "command": "install", "hasParent": true }, diff --git a/Tests/RunCMake/FileAPI/codemodel-v2.cmake b/Tests/RunCMake/FileAPI/codemodel-v2.cmake index da928eb..019eb87 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2.cmake +++ b/Tests/RunCMake/FileAPI/codemodel-v2.cmake @@ -22,6 +22,7 @@ add_subdirectory(interface) add_subdirectory(custom) add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../FileAPIExternalSource" "${CMAKE_CURRENT_BINARY_DIR}/../FileAPIExternalBuild") add_subdirectory(dir) +add_subdirectory(fileset) set_property(TARGET c_shared_lib PROPERTY LIBRARY_OUTPUT_DIRECTORY lib) set_property(TARGET c_shared_lib PROPERTY RUNTIME_OUTPUT_DIRECTORY lib) diff --git a/Tests/RunCMake/FileAPI/fileset/CMakeLists.txt b/Tests/RunCMake/FileAPI/fileset/CMakeLists.txt new file mode 100644 index 0000000..f80f12b --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/CMakeLists.txt @@ -0,0 +1,25 @@ +add_library(c_headers_1 STATIC empty.c) + +target_sources(c_headers_1 + PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES error.c other.c + PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h + ) +target_sources(c_headers_1 + PUBLIC FILE_SET b TYPE HEADERS BASE_DIRS "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>" FILES "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir/h2.h>" + ) +target_sources(c_headers_1 + INTERFACE FILE_SET c TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h3.h + ) +source_group("Source Files" FILES "${CMAKE_CURRENT_SOURCE_DIR}/other.c") + +add_library(c_headers_2 STATIC empty.c) +target_sources(c_headers_2 + INTERFACE FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h + ) + +install(TARGETS c_headers_1 + FILE_SET HEADERS DESTINATION include COMPONENT Headers + FILE_SET b DESTINATION include/dir + FILE_SET c + ) +install(TARGETS c_headers_2) diff --git a/Tests/RunCMake/FileAPI/fileset/dir/h2.h b/Tests/RunCMake/FileAPI/fileset/dir/h2.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/dir/h2.h diff --git a/Tests/RunCMake/FileAPI/fileset/empty.c b/Tests/RunCMake/FileAPI/fileset/empty.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/empty.c diff --git a/Tests/RunCMake/FileAPI/fileset/error.c b/Tests/RunCMake/FileAPI/fileset/error.c new file mode 100644 index 0000000..f10e687 --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/error.c @@ -0,0 +1 @@ +#error "This should not be compiled" diff --git a/Tests/RunCMake/FileAPI/fileset/h1.h b/Tests/RunCMake/FileAPI/fileset/h1.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/h1.h diff --git a/Tests/RunCMake/FileAPI/fileset/h3.h b/Tests/RunCMake/FileAPI/fileset/h3.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/h3.h diff --git a/Tests/RunCMake/FileAPI/fileset/other.c b/Tests/RunCMake/FileAPI/fileset/other.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FileAPI/fileset/other.c diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate-result.txt b/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate-stderr.txt b/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate-stderr.txt new file mode 100644 index 0000000..ef71404 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Generator + + Visual Studio [^ +]+ + + given instance specification + + Test Instance,version=1\.2\.3\.4,version=1\.2\.3\.4 + + that contains duplicate field key 'version'\.$ diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate.cmake b/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldDuplicate.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldNoComma-result.txt b/Tests/RunCMake/GeneratorInstance/BadFieldNoComma-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldNoComma-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldNoComma-stderr.txt b/Tests/RunCMake/GeneratorInstance/BadFieldNoComma-stderr.txt new file mode 100644 index 0000000..d6c73c8 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldNoComma-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Generator + + Visual Studio [^ +]+ + + given instance specification + + Test Instance,nocomma + + that contains a field after the first ',' with no '='\.$ diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldNoComma.cmake b/Tests/RunCMake/GeneratorInstance/BadFieldNoComma.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldNoComma.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldUnknown-result.txt b/Tests/RunCMake/GeneratorInstance/BadFieldUnknown-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldUnknown-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldUnknown-stderr.txt b/Tests/RunCMake/GeneratorInstance/BadFieldUnknown-stderr.txt new file mode 100644 index 0000000..ecfe229 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldUnknown-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Generator + + Visual Studio [^ +]+ + + given instance specification + + Test Instance,unknown= + + that contains invalid field 'unknown='\.$ diff --git a/Tests/RunCMake/GeneratorInstance/BadFieldUnknown.cmake b/Tests/RunCMake/GeneratorInstance/BadFieldUnknown.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadFieldUnknown.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionFormat1-result.txt b/Tests/RunCMake/GeneratorInstance/BadVersionFormat1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionFormat1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionFormat1-stderr.txt b/Tests/RunCMake/GeneratorInstance/BadVersionFormat1-stderr.txt new file mode 100644 index 0000000..a0894b6 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionFormat1-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Generator + + Visual Studio [^ +]+ + + given instance specification + + version=1\.2\.3 + + but the version field is not 4 integer components starting in [0-9]+\.$ diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionFormat1.cmake b/Tests/RunCMake/GeneratorInstance/BadVersionFormat1.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionFormat1.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionFormat2-result.txt b/Tests/RunCMake/GeneratorInstance/BadVersionFormat2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionFormat2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionFormat2-stderr.txt b/Tests/RunCMake/GeneratorInstance/BadVersionFormat2-stderr.txt new file mode 100644 index 0000000..2b3a23b --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionFormat2-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Generator + + Visual Studio [^ +]+ + + given instance specification + + version=1\.2\.3\.x + + but the version field is not 4 integer components starting in [0-9]+\.$ diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionFormat2.cmake b/Tests/RunCMake/GeneratorInstance/BadVersionFormat2.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionFormat2.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionNumber-result.txt b/Tests/RunCMake/GeneratorInstance/BadVersionNumber-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionNumber-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionNumber-stderr.txt b/Tests/RunCMake/GeneratorInstance/BadVersionNumber-stderr.txt new file mode 100644 index 0000000..3a27341 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionNumber-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at CMakeLists.txt:[0-9] \(project\): + Generator + + Visual Studio [^ +]+ + + could not find specified instance of Visual Studio: + + version=[0-9]+\.999\.99999\.999$ diff --git a/Tests/RunCMake/GeneratorInstance/BadVersionNumber.cmake b/Tests/RunCMake/GeneratorInstance/BadVersionNumber.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/BadVersionNumber.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake b/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake index 7750c2e..9761f0c 100644 --- a/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake +++ b/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake @@ -11,3 +11,4 @@ elseif(NOT IS_DIRECTORY "${CMAKE_GENERATOR_INSTANCE}") " ${CMAKE_GENERATOR_INSTANCE}\n" "which is not an existing directory.") endif() +file(WRITE "${CMAKE_BINARY_DIR}/instance.txt" "${CMAKE_GENERATOR_INSTANCE}") diff --git a/Tests/RunCMake/GeneratorInstance/PortableNoVersion-result.txt b/Tests/RunCMake/GeneratorInstance/PortableNoVersion-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/PortableNoVersion-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/PortableNoVersion-stderr.txt b/Tests/RunCMake/GeneratorInstance/PortableNoVersion-stderr.txt new file mode 100644 index 0000000..baa17aa --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/PortableNoVersion-stderr.txt @@ -0,0 +1,13 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Generator + + Visual Studio [^ +]+ + + could not find specified instance of Visual Studio: + + [^ +]+/Tests/RunCMake/GeneratorInstance + + The directory exists, but the instance is not known to the Visual Studio + Installer, and no 'version=' field was given\.$ diff --git a/Tests/RunCMake/GeneratorInstance/PortableNoVersion.cmake b/Tests/RunCMake/GeneratorInstance/PortableNoVersion.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/PortableNoVersion.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorInstance/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorInstance/RunCMakeTest.cmake index e7f9ccb..dfcdcf8 100644 --- a/Tests/RunCMake/GeneratorInstance/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorInstance/RunCMakeTest.cmake @@ -1,14 +1,40 @@ include(RunCMake) -if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio 1[56789]") +if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[56789])") + set(vs_major "${CMAKE_MATCH_1}") + set(RunCMake_GENERATOR_INSTANCE "") run_cmake(DefaultInstance) + set(instance_txt "${RunCMake_BINARY_DIR}/DefaultInstance-build/instance.txt") + if(EXISTS "${instance_txt}") + file(READ "${instance_txt}" default_instance) + endif() set(RunCMake_GENERATOR_INSTANCE "${RunCMake_SOURCE_DIR}/instance_does_not_exist") run_cmake(MissingInstance) set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/MissingInstance-toolchain.cmake) run_cmake(MissingInstanceToolchain) unset(RunCMake_TEST_OPTIONS) + + set(RunCMake_GENERATOR_INSTANCE "Test Instance,nocomma") + run_cmake(BadFieldNoComma) + set(RunCMake_GENERATOR_INSTANCE "Test Instance,unknown=") + run_cmake(BadFieldUnknown) + set(RunCMake_GENERATOR_INSTANCE "Test Instance,version=1.2.3.4,version=1.2.3.4") + run_cmake(BadFieldDuplicate) + set(RunCMake_GENERATOR_INSTANCE "version=1.2.3") + run_cmake(BadVersionFormat1) + set(RunCMake_GENERATOR_INSTANCE "version=1.2.3.x") + run_cmake(BadVersionFormat2) + set(RunCMake_GENERATOR_INSTANCE "version=${vs_major}.999.99999.999") + run_cmake(BadVersionNumber) + if(IS_DIRECTORY "${default_instance}") + set(RunCMake_GENERATOR_INSTANCE "${default_instance},version=${vs_major}.999.99999.999") + run_cmake(WrongVersion) + endif() + + set(RunCMake_GENERATOR_INSTANCE "${RunCMake_SOURCE_DIR}") + run_cmake(PortableNoVersion) else() set(RunCMake_GENERATOR_INSTANCE "") run_cmake(NoInstance) diff --git a/Tests/RunCMake/GeneratorInstance/WrongVersion-result.txt b/Tests/RunCMake/GeneratorInstance/WrongVersion-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/WrongVersion-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorInstance/WrongVersion-stderr.txt b/Tests/RunCMake/GeneratorInstance/WrongVersion-stderr.txt new file mode 100644 index 0000000..156a9ee --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/WrongVersion-stderr.txt @@ -0,0 +1,10 @@ +^CMake Error at CMakeLists.txt:[0-9] \(project\): + Generator + + Visual Studio [^ +]+ + + could not find specified instance of Visual Studio: + + [^, +]+,version=[0-9]+\.999\.99999\.999$ diff --git a/Tests/RunCMake/GeneratorInstance/WrongVersion.cmake b/Tests/RunCMake/GeneratorInstance/WrongVersion.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorInstance/WrongVersion.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index 3363a57..6f79b78 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -92,6 +92,9 @@ function(run_cmake test) if(APPLE) list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0025=NEW) endif() + if(NOT RunCMake_TEST_NO_CMP0129 AND CMAKE_C_COMPILER_ID STREQUAL "LCC") + list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0129=NEW) + endif() if(RunCMake_MAKE_PROGRAM) list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}") endif() diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index 1db202e..21d5a25 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -6,11 +6,14 @@ if(RunCMake_GENERATOR STREQUAL Xcode) endif() elseif(RunCMake_GENERATOR STREQUAL Ninja) if(CMAKE_Swift_COMPILER) - run_cmake(Win32ExecutableDisallowed) - - set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Darwin) - run_cmake(SwiftMultiArch) - unset(RunCMake_TEST_OPTIONS) + if (CMAKE_SYSTEM_NAME MATCHES "Windows") + run_cmake_with_options(Win32ExecutableDisallowed) + else() + run_cmake_with_options(Win32ExecutableIgnored) + set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Darwin) + run_cmake(SwiftMultiArch) + unset(RunCMake_TEST_OPTIONS) + endif() endif() elseif(RunCMake_GENERATOR STREQUAL "Ninja Multi-Config") if(CMAKE_Swift_COMPILER) diff --git a/Tests/RunCMake/Swift/Win32ExecutableIgnored.cmake b/Tests/RunCMake/Swift/Win32ExecutableIgnored.cmake new file mode 100644 index 0000000..02d5447 --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableIgnored.cmake @@ -0,0 +1,4 @@ +enable_language(Swift) +add_executable(E E.swift) +set_target_properties(E PROPERTIES + WIN32_EXECUTABLE TRUE) diff --git a/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt b/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt index 1939097..138a69d 100644 --- a/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt +++ b/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt @@ -1,2 +1,11 @@ -^INSTALL TARGETS - target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION\. -INSTALL TARGETS - target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION\.$ +^CMake Warning \(dev\) at TARGETS-Defaults-Cache.cmake:[0-9]+ \(install\): + Target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning \(dev\) at TARGETS-Defaults-Cache.cmake:[0-9]+ \(install\): + Target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt b/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt index 1939097..5f56986 100644 --- a/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt +++ b/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt @@ -1,2 +1,11 @@ -^INSTALL TARGETS - target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION\. -INSTALL TARGETS - target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION\.$ +^CMake Warning \(dev\) at TARGETS-Defaults.cmake:[0-9]+ \(install\): + Target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. ++ +CMake Warning \(dev\) at TARGETS-Defaults.cmake:[0-9]+ \(install\): + Target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/target_sources/FileSetChangeScope-result.txt b/Tests/RunCMake/target_sources/FileSetChangeScope-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetChangeScope-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt b/Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt new file mode 100644 index 0000000..600d006 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetChangeScope\.cmake:[0-9]+ \(target_sources\): + target_sources Scope PUBLIC for file set "a" does not match original scope + INTERFACE +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetChangeScope.cmake b/Tests/RunCMake/target_sources/FileSetChangeScope.cmake new file mode 100644 index 0000000..9d835fe --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetChangeScope.cmake @@ -0,0 +1,5 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS) +target_sources(lib1 PUBLIC FILE_SET a) diff --git a/Tests/RunCMake/target_sources/FileSetChangeType-result.txt b/Tests/RunCMake/target_sources/FileSetChangeType-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetChangeType-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt b/Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt new file mode 100644 index 0000000..85fc718 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetChangeType\.cmake:[0-9]+ \(target_sources\): + target_sources Type "RESOURCES" for file set "a" does not match original + type "HEADERS" +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetChangeType.cmake b/Tests/RunCMake/target_sources/FileSetChangeType.cmake new file mode 100644 index 0000000..69eb6bc --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetChangeType.cmake @@ -0,0 +1,5 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS) +target_sources(lib1 PRIVATE FILE_SET a TYPE RESOURCES) diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt new file mode 100644 index 0000000..faf0f5a --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetDefaultWrongType\.cmake:[0-9]+ \(target_sources\): + target_sources File set TYPE may only be "HEADERS" +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake b/Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake new file mode 100644 index 0000000..c810d66 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET UNKNOWN) diff --git a/Tests/RunCMake/target_sources/FileSetDirectories.cmake b/Tests/RunCMake/target_sources/FileSetDirectories.cmake new file mode 100644 index 0000000..af30b1e --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetDirectories.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_subdirectory(dir3) +add_subdirectory(dir4) diff --git a/Tests/RunCMake/target_sources/FileSetExport.cmake b/Tests/RunCMake/target_sources/FileSetExport.cmake new file mode 100644 index 0000000..cde826a --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetExport.cmake @@ -0,0 +1,21 @@ +enable_language(C) + +add_library(lib1 STATIC lib1.c) +target_sources(lib1 + PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES error.c + PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h + PUBLIC FILE_SET b TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h2.h + INTERFACE FILE_SET c TYPE HEADERS BASE_DIRS "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>" FILES "$<1:dir/dir.h>" + INTERFACE FILE_SET d TYPE HEADERS BASE_DIRS FILES "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty.h" + INTERFACE FILE_SET e TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>" FILES "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty2.h" + INTERFACE FILE_SET f TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES "${CMAKE_CURRENT_SOURCE_DIR}/empty3.h" + INTERFACE FILE_SET g TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dir1" "${CMAKE_CURRENT_SOURCE_DIR}/dir2" FILES "${CMAKE_CURRENT_SOURCE_DIR}/dir1/file1.h" "${CMAKE_CURRENT_SOURCE_DIR}/dir2/file2.h" + INTERFACE FILE_SET dir3 TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dir3" FILES dir3/dir3.h + ) + +install(TARGETS lib1 EXPORT export FILE_SET HEADERS FILE_SET a FILE_SET b FILE_SET c DESTINATION include/dir FILE_SET d FILE_SET e FILE_SET f DESTINATION include/$<IF:$<CONFIG:Debug>,debug,release> FILE_SET g FILE_SET dir3 DESTINATION include/dir3) +install(EXPORT export FILE export.cmake NAMESPACE install:: DESTINATION lib/cmake) +export(EXPORT export FILE export.cmake NAMESPACE export::) + +add_library(lib2 STATIC lib2.c) +target_link_libraries(lib2 PRIVATE lib1) diff --git a/Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt b/Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt b/Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt new file mode 100644 index 0000000..9a2ca6a --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt @@ -0,0 +1,10 @@ +^CMake Error at FileSetFileNoExist\.cmake:[0-9]+ \(add_library\): + Cannot find source file: + + [^ +]*/Tests/RunCMake/target_sources/noexist\.h +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) + + +CMake Generate step failed\. Build files cannot be regenerated correctly\.$ diff --git a/Tests/RunCMake/target_sources/FileSetFileNoExist.cmake b/Tests/RunCMake/target_sources/FileSetFileNoExist.cmake new file mode 100644 index 0000000..0df8186 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetFileNoExist.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES noexist.h) diff --git a/Tests/RunCMake/target_sources/FileSetImport.cmake b/Tests/RunCMake/target_sources/FileSetImport.cmake new file mode 100644 index 0000000..9c7358a --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetImport.cmake @@ -0,0 +1,97 @@ +enable_language(C) + +get_property(_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + +function(assert_prop_eq tgt prop value) + unset(actual_value) + get_property(actual_value TARGET ${tgt} PROPERTY ${prop}) + if(NOT actual_value STREQUAL value) + message(SEND_ERROR "Expected value of ${prop}:\n ${value}\nActual value:\n ${actual_value}") + endif() +endfunction() + +get_filename_component(export_build_dir "${CMAKE_BINARY_DIR}" DIRECTORY) +string(APPEND export_build_dir "/FileSetExport-build") + +include("${export_build_dir}/export.cmake") +include("${export_build_dir}/install/lib/cmake/export.cmake") + +assert_prop_eq(export::lib1 HEADER_SETS "") +assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3") +assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c") +assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(export::lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/h2.h") +assert_prop_eq(export::lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(export::lib1 HEADER_SET_c "$<1:dir/dir.h>") +assert_prop_eq(export::lib1 HEADER_DIRS_c "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>") +assert_prop_eq(export::lib1 HEADER_SET_d "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty.h") +assert_prop_eq(export::lib1 HEADER_DIRS_d "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(export::lib1 HEADER_SET_e "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty2.h") +assert_prop_eq(export::lib1 HEADER_DIRS_e "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>") +assert_prop_eq(export::lib1 HEADER_SET_f "${CMAKE_CURRENT_SOURCE_DIR}/empty3.h") +assert_prop_eq(export::lib1 HEADER_DIRS_f "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(export::lib1 HEADER_SET_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1/file1.h;${CMAKE_CURRENT_SOURCE_DIR}/dir2/file2.h") +assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2") +assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir1>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir2>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir3>") + +assert_prop_eq(install::lib1 HEADER_SETS "") +assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3") +assert_prop_eq(install::lib1 HEADER_SET "${export_build_dir}/install/include/error.c") +assert_prop_eq(install::lib1 HEADER_DIRS "${export_build_dir}/install/include") +assert_prop_eq(install::lib1 HEADER_SET_b "${export_build_dir}/install/include/h2.h") +assert_prop_eq(install::lib1 HEADER_DIRS_b "${export_build_dir}/install/include") +assert_prop_eq(install::lib1 HEADER_SET_c "${export_build_dir}/install/include/dir/dir.h") +assert_prop_eq(install::lib1 HEADER_DIRS_c "${export_build_dir}/install/include/dir") +if(_multi_config) + assert_prop_eq(install::lib1 HEADER_SET_d "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug/empty.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release/empty.h>") +else() + assert_prop_eq(install::lib1 HEADER_SET_d "${export_build_dir}/install/include/debug/empty.h") +endif() +assert_prop_eq(install::lib1 HEADER_DIRS_d "${export_build_dir}/install/include") +if(_multi_config) + assert_prop_eq(install::lib1 HEADER_SET_e "$<$<CONFIG:Debug>:${export_build_dir}/install/include/empty2.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/empty2.h>") +else() + assert_prop_eq(install::lib1 HEADER_SET_e "${export_build_dir}/install/include/empty2.h") +endif() +assert_prop_eq(install::lib1 HEADER_DIRS_e "${export_build_dir}/install/include") +if(_multi_config) + assert_prop_eq(install::lib1 HEADER_SET_f "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug/empty3.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release/empty3.h>") + assert_prop_eq(install::lib1 HEADER_DIRS_f "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release>") +else() + assert_prop_eq(install::lib1 HEADER_SET_f "${export_build_dir}/install/include/debug/empty3.h") + assert_prop_eq(install::lib1 HEADER_DIRS_f "${export_build_dir}/install/include/debug") +endif() +assert_prop_eq(install::lib1 HEADER_SET_g "${export_build_dir}/install/include/file1.h;${export_build_dir}/install/include/file2.h") +assert_prop_eq(install::lib1 HEADER_DIRS_g "${export_build_dir}/install/include") +if(_multi_config) + assert_prop_eq(install::lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug>>;$<BUILD_INTERFACE:$<$<CONFIG:Release>:${export_build_dir}/install/include/release>>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir3>") +else() + assert_prop_eq(install::lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/debug>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir3>") +endif() + +file(GLOB_RECURSE actual + LIST_DIRECTORIES TRUE + RELATIVE "${CMAKE_BINARY_DIR}/../FileSetExport-build/install/include" + "${CMAKE_BINARY_DIR}/../FileSetExport-build/install/include/*" + ) +if(actual) + list(SORT actual) +endif() +if(_multi_config) + set(expect "^debug;debug/empty\\.h;debug/empty3\\.h;dir;dir/dir\\.h;dir3;dir3/dir3\.h;empty2\\.h;error\\.c;file1\\.h;file2\\.h;h2\\.h;release;release/empty\\.h;release/empty3\\.h$") +else() + set(expect "^debug;debug/empty\\.h;debug/empty3\\.h;dir;dir/dir\\.h;dir3;dir3/dir3\.h;empty2\\.h;error\\.c;file1\\.h;file2\\.h;h2\\.h$") +endif() +if(NOT "${actual}" MATCHES "${expect}") + message(SEND_ERROR "Installed files: + ${actual} +do not match what we expected: + ${expect} +in directory: + ${CMAKE_INSTALL_PREFIX}") +endif() + +add_library(lib2_export STATIC lib2.c) +target_link_libraries(lib2_export PRIVATE export::lib1) +add_library(lib2_install STATIC lib2.c) +target_link_libraries(lib2_install PRIVATE install::lib1) diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt new file mode 100644 index 0000000..694f227 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetInstallMissingSetsInterface\.cmake:[0-9]+ \(install\): + install TARGETS target lib1 is exported but not all of its file sets are + installed +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake new file mode 100644 index 0000000..face69e --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake @@ -0,0 +1,5 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h) +install(TARGETS lib1 EXPORT a) diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake new file mode 100644 index 0000000..84778d1 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake @@ -0,0 +1,9 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h) +install(TARGETS lib1 EXPORT a) + +add_library(lib2 STATIC empty.c) +target_sources(lib2 INTERFACE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h) +install(TARGETS lib2) diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt b/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt new file mode 100644 index 0000000..3972c89 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetNoExistInterface\.cmake:[0-9]+ \(set_property\): + Header set "a" has not yet been created\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake b/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake new file mode 100644 index 0000000..266bc61 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake @@ -0,0 +1,7 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +set_property(TARGET lib1 PROPERTY INTERFACE_HEADER_SETS "a") + +# Error happens at configure-time, so this doesn't help. +target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS) diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt new file mode 100644 index 0000000..336bafe --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetNoExistPrivate\.cmake:[0-9]+ \(set_property\): + Header set "a" has not yet been created\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake b/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake new file mode 100644 index 0000000..f501912 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake @@ -0,0 +1,7 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +set_property(TARGET lib1 PROPERTY HEADER_SETS "a") + +# Error happens at configure-time, so this doesn't help. +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS) diff --git a/Tests/RunCMake/target_sources/FileSetNoScope-result.txt b/Tests/RunCMake/target_sources/FileSetNoScope-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoScope-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt new file mode 100644 index 0000000..835ffe7 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetNoScope\.cmake:[0-9]+ \(target_sources\): + target_sources File set "a" is not in HEADER_SETS or INTERFACE_HEADER_SETS +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoScope.cmake b/Tests/RunCMake/target_sources/FileSetNoScope.cmake new file mode 100644 index 0000000..79ff341 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoScope.cmake @@ -0,0 +1,6 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h) +set_property(TARGET lib1 PROPERTY HEADER_SETS) +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS FILES h2.h) diff --git a/Tests/RunCMake/target_sources/FileSetNoType-result.txt b/Tests/RunCMake/target_sources/FileSetNoType-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoType-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetNoType-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoType-stderr.txt new file mode 100644 index 0000000..5405fdb --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoType-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetNoType\.cmake:[0-9]+ \(target_sources\): + target_sources Must specify a TYPE when creating file set +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoType.cmake b/Tests/RunCMake/target_sources/FileSetNoType.cmake new file mode 100644 index 0000000..961525d --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetNoType.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a) diff --git a/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt new file mode 100644 index 0000000..551b9e7 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at FileSetOverlappingBaseDirs\.cmake:[0-9]+ \(target_sources\): + Base directories in file set cannot be subdirectories of each other: + + [^ +]*/Tests/RunCMake/target_sources/\. + [^ +]*/Tests/RunCMake/target_sources/dir3 +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake new file mode 100644 index 0000000..eba4191 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS $<1:${CMAKE_CURRENT_SOURCE_DIR}/.$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/dir3> FILES h1.h) diff --git a/Tests/RunCMake/target_sources/FileSetProperties.cmake b/Tests/RunCMake/target_sources/FileSetProperties.cmake new file mode 100644 index 0000000..ce010a3 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetProperties.cmake @@ -0,0 +1,67 @@ +enable_language(C) + +function(assert_prop_undef tgt prop) + unset(actual_value) + get_property(actual_value TARGET ${tgt} PROPERTY ${prop}) + if(DEFINED actual_value) + message(SEND_ERROR "${prop} should be undefined, actual value:\n ${actual_value}") + endif() +endfunction() + +function(assert_prop_eq tgt prop value) + unset(actual_value) + get_property(actual_value TARGET ${tgt} PROPERTY ${prop}) + if(NOT actual_value STREQUAL value) + message(SEND_ERROR "Expected value of ${prop}:\n ${value}\nActual value:\n ${actual_value}") + endif() +endfunction() + +add_library(lib1 STATIC empty.c) +assert_prop_eq(lib1 HEADER_SETS "") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "") +assert_prop_undef(lib1 INCLUDE_DIRECTORIES) +assert_prop_undef(lib1 INTERFACE_INCLUDE_DIRECTORIES) + +target_sources(lib1 PUBLIC FILE_SET a TYPE HEADERS BASE_DIRS "." FILES h1.h h2.h) +assert_prop_eq(lib1 HEADER_SETS "a") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a") +assert_prop_eq(lib1 HEADER_DIRS_a "${CMAKE_CURRENT_SOURCE_DIR}/.") +assert_prop_eq(lib1 HEADER_SET_a "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h") +assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>") +assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>") + +target_sources(lib1 PUBLIC FILE_SET a FILES h3.h) +assert_prop_eq(lib1 HEADER_SETS "a") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a") +assert_prop_eq(lib1 HEADER_DIRS_a "${CMAKE_CURRENT_SOURCE_DIR}/.") +assert_prop_eq(lib1 HEADER_SET_a "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h;${CMAKE_CURRENT_SOURCE_DIR}/h3.h") +assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>") +assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>") + +target_sources(lib1 PRIVATE FILE_SET b TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dir" FILES dir/dir.h) +assert_prop_eq(lib1 HEADER_SETS "a;b") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a") +assert_prop_eq(lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}/dir") +assert_prop_eq(lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/dir/dir.h") +assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>") +assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>") + +target_sources(lib1 INTERFACE FILE_SET c TYPE HEADERS) +assert_prop_eq(lib1 HEADER_SETS "a;b") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a;c") +assert_prop_eq(lib1 HEADER_DIRS_c "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(lib1 HEADER_SET_c "") +assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>") +assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>") + +target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h) +assert_prop_eq(lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h1.h") +assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>") +assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>") + +target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h2.h) +assert_prop_eq(lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h") +assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>") +assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>") diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt new file mode 100644 index 0000000..f4bd447 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt @@ -0,0 +1,12 @@ +CMake Error at FileSetWrongBaseDirs\.cmake:[0-9]+ \(target_sources\): + File: + + [^ +]*/Tests/RunCMake/target_sources/h1\.h + + must be in one of the file set's base directories: + + [^ +]*/Tests/RunCMake/target_sources/dir3 +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake new file mode 100644 index 0000000..38d3abd --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/dir3 FILES h1.h) diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt new file mode 100644 index 0000000..6bb0ec6 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt @@ -0,0 +1,10 @@ +CMake Error at reldir/CMakeLists\.txt:[0-9]+ \(target_sources\): + File: + + [^ +]*/Tests/RunCMake/target_sources/reldir/\.\./h1\.h + + must be in one of the file set's base directories: + + [^ +]*/Tests/RunCMake/target_sources/reldir/\. diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake new file mode 100644 index 0000000..2ca8a8e --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake @@ -0,0 +1,3 @@ +enable_language(C) + +add_subdirectory(reldir) diff --git a/Tests/RunCMake/target_sources/FileSetWrongType-result.txt b/Tests/RunCMake/target_sources/FileSetWrongType-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongType-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt new file mode 100644 index 0000000..8ffa786 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetWrongType\.cmake:[0-9]+ \(target_sources\): + target_sources File set TYPE may only be "HEADERS" +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetWrongType.cmake b/Tests/RunCMake/target_sources/FileSetWrongType.cmake new file mode 100644 index 0000000..b7dee72 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetWrongType.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +target_sources(lib1 PRIVATE FILE_SET a TYPE UNKNOWN) diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake index 9d64927..9828fa2 100644 --- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake @@ -21,3 +21,60 @@ run_cmake(AddCustomTargetInterfaceSources) run_cmake(AddCustomTargetSources) run_cmake(AddCustomTargetCheckProperty) run_cmake(AddCustomTargetGenx) + +run_cmake(FileSetProperties) +run_cmake(FileSetNoType) +run_cmake(FileSetWrongType) +run_cmake(FileSetDefaultWrongType) +run_cmake(FileSetChangeScope) +run_cmake(FileSetChangeType) +run_cmake(FileSetWrongBaseDirs) +run_cmake(FileSetWrongBaseDirsRelative) +run_cmake(FileSetOverlappingBaseDirs) +run_cmake(FileSetInstallMissingSetsPrivate) +run_cmake(FileSetInstallMissingSetsInterface) +run_cmake(FileSetNoScope) +run_cmake(FileSetNoExistPrivate) +run_cmake(FileSetNoExistInterface) +run_cmake(FileSetDirectories) + +set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW) +run_cmake(FileSetFileNoExist) +unset(RunCMake_TEST_OPTIONS) + +function(run_export_import name) + if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(_config_options "-DCMAKE_CONFIGURATION_TYPES=Debug\\\\;Release") + else() + set(_config_options -DCMAKE_BUILD_TYPE=Debug) + endif() + + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}Export-build") + set(RunCMake_TEST_OPTIONS "--install-prefix=${RunCMake_TEST_BINARY_DIR}/install" ${_config_options}) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(${name}Export) + run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --build . --config Debug) + run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --install . --config Debug) + if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --build . --config Release) + run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --install . --config Release) + endif() + unset(RunCMake_TEST_OPTIONS) + + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}Import-build") + unset(RunCMake_TEST_OPTIONS) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(${name}Import) + run_cmake_command(${name}Import-build ${CMAKE_COMMAND} --build . --config Debug) + if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + run_cmake_command(${name}Import-build ${CMAKE_COMMAND} --build . --config Release) + endif() + + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) +endfunction() + +run_export_import(FileSet) diff --git a/Tests/RunCMake/target_sources/debug/empty.h b/Tests/RunCMake/target_sources/debug/empty.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/debug/empty.h diff --git a/Tests/RunCMake/target_sources/debug/empty2.h b/Tests/RunCMake/target_sources/debug/empty2.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/debug/empty2.h diff --git a/Tests/RunCMake/target_sources/dir/dir.h b/Tests/RunCMake/target_sources/dir/dir.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/dir/dir.h diff --git a/Tests/RunCMake/target_sources/dir1/file1.h b/Tests/RunCMake/target_sources/dir1/file1.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/dir1/file1.h diff --git a/Tests/RunCMake/target_sources/dir2/file2.h b/Tests/RunCMake/target_sources/dir2/file2.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/dir2/file2.h diff --git a/Tests/RunCMake/target_sources/dir3/CMakeLists.txt b/Tests/RunCMake/target_sources/dir3/CMakeLists.txt new file mode 100644 index 0000000..e23ceb8 --- /dev/null +++ b/Tests/RunCMake/target_sources/dir3/CMakeLists.txt @@ -0,0 +1 @@ +add_library(lib1 STATIC ../empty.c) diff --git a/Tests/RunCMake/target_sources/dir3/dir3.h b/Tests/RunCMake/target_sources/dir3/dir3.h new file mode 100644 index 0000000..e45c25a --- /dev/null +++ b/Tests/RunCMake/target_sources/dir3/dir3.h @@ -0,0 +1,4 @@ +#ifndef DIR3_H +#define DIR3_H + +#endif diff --git a/Tests/RunCMake/target_sources/dir4/CMakeLists.txt b/Tests/RunCMake/target_sources/dir4/CMakeLists.txt new file mode 100644 index 0000000..6475685 --- /dev/null +++ b/Tests/RunCMake/target_sources/dir4/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(lib1 PRIVATE FILE_SET HEADERS BASE_DIRS ${CMAKE_SOURCE_DIR} FILES + $<1:dir3.h> + dir4.h + ) diff --git a/Tests/RunCMake/target_sources/dir4/dir4.h b/Tests/RunCMake/target_sources/dir4/dir4.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/dir4/dir4.h diff --git a/Tests/RunCMake/target_sources/empty.c b/Tests/RunCMake/target_sources/empty.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/empty.c diff --git a/Tests/RunCMake/target_sources/empty3.h b/Tests/RunCMake/target_sources/empty3.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/empty3.h diff --git a/Tests/RunCMake/target_sources/error.c b/Tests/RunCMake/target_sources/error.c new file mode 100644 index 0000000..f10e687 --- /dev/null +++ b/Tests/RunCMake/target_sources/error.c @@ -0,0 +1 @@ +#error "This should not be compiled" diff --git a/Tests/RunCMake/target_sources/h1.h b/Tests/RunCMake/target_sources/h1.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/h1.h diff --git a/Tests/RunCMake/target_sources/h2.h b/Tests/RunCMake/target_sources/h2.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/h2.h diff --git a/Tests/RunCMake/target_sources/h3.h b/Tests/RunCMake/target_sources/h3.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/h3.h diff --git a/Tests/RunCMake/target_sources/lib1.c b/Tests/RunCMake/target_sources/lib1.c new file mode 100644 index 0000000..95042de --- /dev/null +++ b/Tests/RunCMake/target_sources/lib1.c @@ -0,0 +1,6 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + void lib1(void) +{ +} diff --git a/Tests/RunCMake/target_sources/lib2.c b/Tests/RunCMake/target_sources/lib2.c new file mode 100644 index 0000000..a060dc9 --- /dev/null +++ b/Tests/RunCMake/target_sources/lib2.c @@ -0,0 +1,8 @@ +#include <dir3.h> + +#ifdef _WIN32 +__declspec(dllexport) +#endif + void lib2(void) +{ +} diff --git a/Tests/RunCMake/target_sources/reldir/CMakeLists.txt b/Tests/RunCMake/target_sources/reldir/CMakeLists.txt new file mode 100644 index 0000000..df22b25 --- /dev/null +++ b/Tests/RunCMake/target_sources/reldir/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(lib1 STATIC ../empty.c) +target_sources(lib1 PRIVATE FILE_SET HEADERS BASE_DIRS . FILES ../h1.h) diff --git a/Tests/RunCMake/target_sources/release/empty.h b/Tests/RunCMake/target_sources/release/empty.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/release/empty.h diff --git a/Tests/RunCMake/target_sources/release/empty2.h b/Tests/RunCMake/target_sources/release/empty2.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_sources/release/empty2.h diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 28a990d..4f2cc5c 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -60,10 +60,10 @@ if(CMake_TEST_ISPC) endif() run_cmake(ISPCDuplicateTarget${ninja}) endif() -if(CMAKE_C_COMPILER_ID MATCHES "GNU|LCC" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4) +if((CMAKE_C_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4) OR CMAKE_C_COMPILER_ID MATCHES "LCC") run_cmake(CStandardGNU) endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|LCC" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) +if((CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) OR CMAKE_C_COMPILER_ID MATCHES "LCC") run_cmake(CxxStandardGNU) endif() diff --git a/Tests/SetLang/CMakeLists.txt b/Tests/SetLang/CMakeLists.txt index 5b2eb19..14e9d6e 100644 --- a/Tests/SetLang/CMakeLists.txt +++ b/Tests/SetLang/CMakeLists.txt @@ -1,5 +1,8 @@ # test forcing a source file language to c++ from c cmake_minimum_required (VERSION 2.6) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(SetLang) # force this to be verbose so I can debug a dashboard entry set(CMAKE_VERBOSE_MAKEFILE 1) diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index e35e0d3..b1b9d57 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required (VERSION 2.8.12) +if(POLICY CMP0129) + cmake_policy(SET CMP0129 NEW) +endif() project(TryCompile) macro(TEST_ASSERT value msg) @@ -341,6 +341,7 @@ CMAKE_CXX_SOURCES="\ cmFileCommand \ cmFileCopier \ cmFileInstaller \ + cmFileSet \ cmFileTime \ cmFileTimeCache \ cmFileTimes \ @@ -386,6 +387,7 @@ CMAKE_CXX_SOURCES="\ cmInstallCommandArguments \ cmInstallDirectoryGenerator \ cmInstallExportGenerator \ + cmInstallFileSetGenerator \ cmInstallFilesCommand \ cmInstallFilesGenerator \ cmInstallGenerator \ |