diff options
364 files changed, 4928 insertions, 5820 deletions
diff --git a/Auxiliary/cmake.m4 b/Auxiliary/cmake.m4 index 7beff41..a40c0ae 100644 --- a/Auxiliary/cmake.m4 +++ b/Auxiliary/cmake.m4 @@ -13,7 +13,7 @@ fi # $2: language (e.g. C/CXX/Fortran) # $3: The compiler ID, defaults to GNU. # Possible values are: GNU, Intel, Clang, SunPro, HP, XL, VisualAge, PGI, -# PathScale, Cray, SCO, MIPSpro, MSVC +# PathScale, Cray, SCO, MSVC # $4: optional extra arguments to cmake, e.g. "-DCMAKE_SIZEOF_VOID_P=8" # $5: optional path to cmake binary AC_DEFUN([CMAKE_FIND_PACKAGE], [ diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake index dc9f0ba..78e22cc 100644 --- a/CMakeCPack.cmake +++ b/CMakeCPack.cmake @@ -102,9 +102,6 @@ if(CMake_INSTALL_COMPONENTS) if(WIN32 AND NOT CYGWIN) list(APPEND _CPACK_IFW_COMPONENTS_ALL cmcldeps) endif() - if(APPLE) - list(APPEND _CPACK_IFW_COMPONENTS_ALL cmakexbuild) - endif() if(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME) set(_CPACK_IFW_COMPONENT_UNSPECIFIED_NAME ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}) diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in index a08c97d..2a4bcc5 100644 --- a/CMakeCPackOptions.cmake.in +++ b/CMakeCPackOptions.cmake.in @@ -109,16 +109,6 @@ if(CPACK_GENERATOR MATCHES "IFW") set(CPACK_IFW_COMPONENT_CMCLDEPS_VERSION "@CMake_IFW_ROOT_COMPONENT_VERSION@") - set(CPACK_COMPONENT_CMAKEXBUILD_DISPLAY_NAME "cmakexbuild") - set(CPACK_COMPONENT_CMAKEXBUILD_DESCRIPTION - "The \"cmakexbuild\" executable is a wrapper program for \"xcodebuild\"") - set(CPACK_COMPONENT_CMAKEXBUILD_REQUIRED TRUE) - set(CPACK_COMPONENT_CMAKEXBUILD_GROUP Tools) - set(CPACK_IFW_COMPONENT_CMAKEXBUILD_NAME "CMakeXBuild") - set(CPACK_IFW_COMPONENT_CMAKEXBUILD_PRIORITY 85) - set(CPACK_IFW_COMPONENT_CMAKEXBUILD_VERSION - "@CMake_IFW_ROOT_COMPONENT_VERSION@") - # Dialogs set(CPACK_COMPONENT_GROUP_DIALOGS_DISPLAY_NAME "Interactive Dialogs") set(CPACK_COMPONENT_GROUP_DIALOGS_DESCRIPTION diff --git a/CMakeLists.txt b/CMakeLists.txt index bd130ec..69e3064 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -445,14 +445,6 @@ macro (CMAKE_BUILD_UTILITIES) endif() #--------------------------------------------------------------------- - # Build Compress library for CTest. - set(CMAKE_COMPRESS_INCLUDES - "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress") - set(CMAKE_COMPRESS_LIBRARIES "cmcompress") - add_subdirectory(Utilities/cmcompress) - CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty") - - #--------------------------------------------------------------------- # Build expat library for CMake, CTest, and libarchive. if(CMAKE_USE_SYSTEM_EXPAT) find_package(EXPAT) diff --git a/CompileFlags.cmake b/CompileFlags.cmake index 5d0e144..c8a039a 100644 --- a/CompileFlags.cmake +++ b/CompileFlags.cmake @@ -44,6 +44,15 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc") endif() endif() +# Workaround for TOC Overflow on ppc64 +if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-bbigtoc") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-multi-toc") +endif() + if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION) if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13) diff --git a/Help/command/cmake_parse_arguments.rst b/Help/command/cmake_parse_arguments.rst index c8327e2..196d90f 100644 --- a/Help/command/cmake_parse_arguments.rst +++ b/Help/command/cmake_parse_arguments.rst @@ -59,6 +59,11 @@ All remaining arguments are collected in a variable where recognized. This can be checked afterwards to see whether your macro was called with unrecognized parameters. +``<one_value_keywords>`` and ``<multi_value_keywords>`` that where given no +values at all are collected in a variable ``<prefix>_KEYWORDS_MISSING_VALUES`` +that will be undefined if all keywords received values. This can be checked +to see if there where keywords without any values given. + As an example here a ``my_install()`` macro, which takes similar arguments as the real :command:`install` command: @@ -77,7 +82,7 @@ Assume ``my_install()`` has been called like this: .. code-block:: cmake - my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub) + my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub CONFIGURATIONS) After the ``cmake_parse_arguments`` call the macro will have set or undefined the following variables:: @@ -89,6 +94,8 @@ the following variables:: MY_INSTALL_TARGETS = "foo;bar" MY_INSTALL_CONFIGURATIONS <UNDEFINED> # was not used MY_INSTALL_UNPARSED_ARGUMENTS = "blub" # nothing expected after "OPTIONAL" + MY_INSTALL_KEYWORDS_MISSING_VALUES = "CONFIGURATIONS" + # No value for "CONFIGURATIONS" given You can then continue and process these variables. @@ -97,5 +104,6 @@ one_value_keyword another recognized keyword follows, this is interpreted as the beginning of the new option. E.g. ``my_install(TARGETS foo DESTINATION OPTIONAL)`` would result in ``MY_INSTALL_DESTINATION`` set to ``"OPTIONAL"``, but as ``OPTIONAL`` -is a keyword itself ``MY_INSTALL_DESTINATION`` will be empty and -``MY_INSTALL_OPTIONAL`` will therefore be set to ``TRUE``. +is a keyword itself ``MY_INSTALL_DESTINATION`` will be empty (but added +to ``MY_INSTALL_KEYWORDS_MISSING_VALUES``) and ``MY_INSTALL_OPTIONAL`` will +therefore be set to ``TRUE``. diff --git a/Help/command/file.rst b/Help/command/file.rst index db4d6fc..465e567 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -26,8 +26,8 @@ Synopsis file(`MAKE_DIRECTORY`_ [<dir>...]) file({`COPY`_ | `INSTALL`_} <file>... DESTINATION <dir> [...]) file(`SIZE`_ <filename> <out-var>) - file(`READ_SYMLINK`_ <filename> <out-var>) - file(`CREATE_LINK`_ <file> <new-file> [...]) + file(`READ_SYMLINK`_ <linkname> <out-var>) + file(`CREATE_LINK`_ <original> <linkname> [...]) `Path Conversion`_ file(`RELATIVE_PATH`_ <out-var> <directory> <file>) @@ -350,22 +350,22 @@ pointing to a file and is readable. .. code-block:: cmake - file(READ_SYMLINK <filename> <variable>) + file(READ_SYMLINK <linkname> <variable>) -Read the symlink at ``<filename>`` and put the result in ``<variable>``. -Requires that ``<filename>`` is a valid path pointing to a symlink. If -``<filename>`` does not exist, or is not a symlink, an error is thrown. +This subcommand queries the symlink ``<linkname>`` and stores the path it +points to in the result ``<variable>``. If ``<linkname>`` does not exist or +is not a symlink, CMake issues a fatal error. Note that this command returns the raw symlink path and does not resolve -relative symlinks. If you want to resolve the relative symlink yourself, you -could do something like this: +a relative path. The following is an example of how to ensure that an +absolute path is obtained: .. code-block:: cmake - set(filename "/path/to/foo.sym") - file(READ_SYMLINK "${filename}" result) + set(linkname "/path/to/foo.sym") + file(READ_SYMLINK "${linkname}" result) if(NOT IS_ABSOLUTE "${result}") - get_filename_component(dir "${filename}" DIRECTORY) + get_filename_component(dir "${linkname}" DIRECTORY) set(result "${dir}/${result}") endif() @@ -373,23 +373,23 @@ could do something like this: .. code-block:: cmake - file(CREATE_LINK <file> <new-file> + file(CREATE_LINK <original> <linkname> [RESULT <result>] [COPY_ON_ERROR] [SYMBOLIC]) -Create a link to ``<file>`` at ``<new-file>``. +Create a link ``<linkname>`` that points to ``<original>``. +It will be a hard link by default, but providing the ``SYMBOLIC`` option +results in a symbolic link instead. Hard links require that ``original`` +exists and is a file, not a directory. If ``<linkname>`` already exists, +it will be overwritten. -It is a hard link by default. This can be changed to symbolic links by -using ``SYMBOLIC``. The original file needs to exist for hard links. - -The ``<result>`` variable, if specified, gets the status of the operation. -It is set to ``0`` in case of success. Otherwise, it contains the error -generated. In case of failures, if ``RESULT`` is not specified, a fatal error -is emitted. +The ``<result>`` variable, if specified, receives the status of the operation. +It is set to ``0`` upon success or an error message otherwise. If ``RESULT`` +is not specified and the operation fails, a fatal error is emitted. Specifying ``COPY_ON_ERROR`` enables copying the file as a fallback if -creating the link fails. - -Overwrites the ``<new-file>`` if it exists. +creating the link fails. It can be useful for handling situations such as +``<original>`` and ``<linkname>`` being on different drives or mount points, +which would make them unable to support a hard link. Path Conversion ^^^^^^^^^^^^^^^ diff --git a/Help/command/get_filename_component.rst b/Help/command/get_filename_component.rst index f55499a..9bbf877 100644 --- a/Help/command/get_filename_component.rst +++ b/Help/command/get_filename_component.rst @@ -15,14 +15,13 @@ Sets ``<var>`` to a component of ``<FileName>``, where ``<mode>`` is one of: NAME = File name without directory EXT = File name longest extension (.b.c from d/a.b.c) NAME_WE = File name without directory or longest extension - LAST_EXT = File name last extention (.c from d/a.b.c) + LAST_EXT = File name last extension (.c from d/a.b.c) NAME_WLE = File name without directory or last extension PATH = Legacy alias for DIRECTORY (use for CMake <= 2.8.11) Paths are returned with forward slashes and have no trailing slashes. -The longest file extension is always considered. If the optional -``CACHE`` argument is specified, the result variable is added to the -cache. +If the optional ``CACHE`` argument is specified, the result variable is +added to the cache. .. code-block:: cmake diff --git a/Help/command/install.rst b/Help/command/install.rst index a0e8c37..4cef787 100644 --- a/Help/command/install.rst +++ b/Help/command/install.rst @@ -99,6 +99,7 @@ Windows platforms are unaffected. Installing Targets ^^^^^^^^^^^^^^^^^^ +.. _`install(TARGETS)`: .. _TARGETS: .. code-block:: cmake @@ -265,18 +266,20 @@ the following additional arguments: is not recommended to use ``NAMELINK_SKIP`` in conjunction with ``NAMELINK_COMPONENT``. -The ``install(TARGETS)`` command can also accept the following options at the +The `install(TARGETS)`_ command can also accept the following options at the top level: ``EXPORT`` This option associates the installed target files with an export called ``<export-name>``. It must appear before any target options. To actually - install the export file itself, call ``install(EXPORT)``, documented below. + install the export file itself, call `install(EXPORT)`_, documented below. + See documentation of the :prop_tgt:`EXPORT_NAME` target property to change + the name of the exported target. ``INCLUDES DESTINATION`` This option specifies a list of directories which will be added to the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property of the - ``<targets>`` when exported by the :command:`install(EXPORT)` command. If a + ``<targets>`` when exported by the `install(EXPORT)`_ command. If a relative path is specified, it is treated as relative to the ``$<INSTALL_PREFIX>``. @@ -310,7 +313,7 @@ targets that link to the object libraries in their implementation. Installing a target with the :prop_tgt:`EXCLUDE_FROM_ALL` target property set to ``TRUE`` has undefined behavior. -:command:`install(TARGETS)` can install targets that were created in +`install(TARGETS)`_ can install targets that were created in other directories. When using such cross-directory install rules, running ``make install`` (or similar) from a subdirectory will not guarantee that targets from other directories are up-to-date. You can use @@ -325,6 +328,8 @@ use "generator expressions" with the syntax ``$<...>``. See the Installing Files ^^^^^^^^^^^^^^^^ +.. _`install(FILES)`: +.. _`install(PROGRAMS)`: .. _FILES: .. _PROGRAMS: @@ -402,6 +407,7 @@ use "generator expressions" with the syntax ``$<...>``. See the Installing Directories ^^^^^^^^^^^^^^^^^^^^^^ +.. _`install(DIRECTORY)`: .. _DIRECTORY: .. code-block:: cmake @@ -526,6 +532,8 @@ manual for available expressions. Custom Installation Logic ^^^^^^^^^^^^^^^^^^^^^^^^^ +.. _`install(CODE)`: +.. _`install(SCRIPT)`: .. _CODE: .. _SCRIPT: @@ -555,6 +563,7 @@ name, not the file's contents). See the Installing Exports ^^^^^^^^^^^^^^^^^^ +.. _`install(EXPORT)`: .. _EXPORT: .. code-block:: cmake @@ -571,7 +580,7 @@ Installing Exports The ``EXPORT`` form generates and installs a CMake file containing code to import targets from the installation tree into another project. Target installations are associated with the export ``<export-name>`` -using the ``EXPORT`` option of the ``install(TARGETS)`` signature +using the ``EXPORT`` option of the `install(TARGETS)`_ signature documented above. The ``NAMESPACE`` option will prepend ``<namespace>`` to the target names as they are written to the import file. By default the generated file will be called ``<export-name>.cmake`` but the ``FILE`` diff --git a/Help/command/list.rst b/Help/command/list.rst index bfcdf34..4444af7 100644 --- a/Help/command/list.rst +++ b/Help/command/list.rst @@ -21,6 +21,9 @@ Synopsis list(`APPEND`_ <list> [<element>...]) list(`FILTER`_ <list> {INCLUDE | EXCLUDE} REGEX <regex>) list(`INSERT`_ <list> <index> [<element>...]) + list(`POP_BACK`_ <list> [<out-var>...]) + list(`POP_FRONT`_ <list> [<out-var>...]) + list(`PREPEND`_ <list> [<element>...]) list(`REMOVE_ITEM`_ <list> <value>...) list(`REMOVE_AT`_ <list> <index>...) list(`REMOVE_DUPLICATES`_ <list>) @@ -33,8 +36,9 @@ Synopsis Introduction ^^^^^^^^^^^^ -The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``REMOVE_AT``, -``REMOVE_ITEM``, ``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create +The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``PREPEND``, +``POP_BACK``, ``POP_FRONT``, ``REMOVE_AT``, ``REMOVE_ITEM``, +``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create new values for the list within the current CMake variable scope. Similar to the :command:`set` command, the LIST command creates new variable values in the current scope, even if the list itself is actually defined in a parent @@ -142,6 +146,34 @@ For more information on regular expressions see also the Inserts elements to the list to the specified location. +.. _POP_BACK: + +.. code-block:: cmake + + list(POP_BACK <list> [<out-var>...]) + +If no variable name is given, removes exactly one element. Otherwise, +assign the last element's value to the given variable and removes it, +up to the last variable name given. + +.. _POP_FRONT: + +.. code-block:: cmake + + list(POP_FRONT <list> [<out-var>...]) + +If no variable name is given, removes exactly one element. Otherwise, +assign the first element's value to the given variable and removes it, +up to the last variable name given. + +.. _PREPEND: + +.. code-block:: cmake + + list(PREPEND <list> [<element> ...]) + +Insert elements to the 0th position in the list. + .. _REMOVE_ITEM: .. code-block:: cmake @@ -164,7 +196,8 @@ Removes items at given indices from the list. list(REMOVE_DUPLICATES <list>) -Removes duplicated items in the list. +Removes duplicated items in the list. The relative order of items is preserved, +but if duplicates are encountered, only the first instance is preserved. .. _TRANSFORM: diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst index 77f42a1..ca8fc77 100644 --- a/Help/command/try_compile.rst +++ b/Help/command/try_compile.rst @@ -12,12 +12,12 @@ Try Compiling Whole Projects .. code-block:: cmake - try_compile(RESULT_VAR <bindir> <srcdir> + try_compile(<resultVar> <bindir> <srcdir> <projectName> [<targetName>] [CMAKE_FLAGS <flags>...] [OUTPUT_VARIABLE <var>]) Try building a project. The success or failure of the ``try_compile``, -i.e. ``TRUE`` or ``FALSE`` respectively, is returned in ``RESULT_VAR``. +i.e. ``TRUE`` or ``FALSE`` respectively, is returned in ``<resultVar>``. In this form, ``<srcdir>`` should contain a complete CMake project with a ``CMakeLists.txt`` file and all sources. The ``<bindir>`` and ``<srcdir>`` @@ -30,7 +30,7 @@ Try Compiling Source Files .. code-block:: cmake - try_compile(RESULT_VAR <bindir> <srcfile|SOURCES srcfile...> + try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...> [CMAKE_FLAGS <flags>...] [COMPILE_DEFINITIONS <defs>...] [LINK_OPTIONS <options>...] @@ -42,13 +42,19 @@ Try Compiling Source Files [<LANG>_EXTENSIONS <bool>] ) -Try building an executable from one or more source files. The success or -failure of the ``try_compile``, i.e. ``TRUE`` or ``FALSE`` respectively, is -returned in ``RESULT_VAR``. +Try building an executable or static library from one or more source files +(which one is determined by the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` +variable). The success or failure of the ``try_compile``, i.e. ``TRUE`` or +``FALSE`` respectively, is returned in ``<resultVar>``. -In this form the user need only supply one or more source files that include a -definition for ``main``. CMake will create a ``CMakeLists.txt`` file to build -the source(s) as an executable that looks something like this: +In this form, one or more source files must be provided. If +:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is unset or is set to ``EXECUTABLE``, +the sources must include a definition for ``main`` and CMake will create a +``CMakeLists.txt`` file to build the source(s) as an executable. +If :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``STATIC_LIBRARY``, +a static library will be built instead and no definition for ``main`` is +required. For an executable, the generated ``CMakeLists.txt`` file would +contain something like the following: .. code-block:: cmake @@ -73,7 +79,7 @@ The options are: in the generated test project. ``COPY_FILE <fileName>`` - Copy the linked executable to the given ``<fileName>``. + Copy the built executable or static library to the given ``<fileName>``. ``COPY_FILE_ERROR <var>`` Use after ``COPY_FILE`` to capture into variable ``<var>`` any error @@ -88,12 +94,12 @@ The options are: given to the ``CMAKE_FLAGS`` option will be ignored. ``LINK_OPTIONS <options>...`` - Specify link step options to pass to :command:`target_link_options` or - to :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated - project, depending of the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable. + Specify link step options to pass to :command:`target_link_options` or to + set the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated + project, depending on the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable. ``OUTPUT_VARIABLE <var>`` - Store the output from the build process the given variable. + Store the output from the build process in the given variable. ``<LANG>_STANDARD <std>`` Specify the :prop_tgt:`C_STANDARD`, :prop_tgt:`CXX_STANDARD`, @@ -114,7 +120,7 @@ passed to ``cmake`` to avoid this clean. However, multiple sequential ``try_compile`` operations reuse this single output directory. If you use ``--debug-trycompile``, you can only debug one ``try_compile`` call at a time. The recommended procedure is to protect all ``try_compile`` calls in your -project by ``if(NOT DEFINED RESULT_VAR)`` logic, configure with cmake +project by ``if(NOT DEFINED <resultVar>)`` logic, configure with cmake all the way through once, then delete the cache entry associated with the try_compile call of interest, and then re-run cmake again with ``--debug-trycompile``. @@ -139,8 +145,8 @@ behavior at link time, the ``check_pie_supported()`` command from the :module:`CheckPIESupported` module must be called before using the :command:`try_compile` command. -The current settings of :policy:`CMP0065` and :policy:`CMP0083` are set in the -generated project. +The current settings of :policy:`CMP0065` and :policy:`CMP0083` are propagated +through to the generated test project. Set the :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` variable to choose a build configuration. @@ -150,7 +156,9 @@ the type of target used for the source file signature. Set the :variable:`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable to specify variables that must be propagated into the test project. This variable is -meant for use only in toolchain files. +meant for use only in toolchain files and is only honored by the +``try_compile()`` command for the source files form, not when given a whole +project. If :policy:`CMP0067` is set to ``NEW``, or any of the ``<LANG>_STANDARD``, ``<LANG>_STANDARD_REQUIRED``, or ``<LANG>_EXTENSIONS`` options are used, diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst index 137402f..d401ebe 100644 --- a/Help/command/try_run.rst +++ b/Help/command/try_run.rst @@ -12,8 +12,8 @@ Try Compiling and Running Source Files .. code-block:: cmake - try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR - bindir srcfile [CMAKE_FLAGS <flags>...] + try_run(<runResultVar> <compileResultVar> + <bindir> <srcfile> [CMAKE_FLAGS <flags>...] [COMPILE_DEFINITIONS <defs>...] [LINK_OPTIONS <options>...] [LINK_LIBRARIES <libs>...] @@ -23,9 +23,9 @@ Try Compiling and Running Source Files [ARGS <args>...]) Try compiling a ``<srcfile>``. Returns ``TRUE`` or ``FALSE`` for success -or failure in ``COMPILE_RESULT_VAR``. If the compile succeeded, runs the -executable and returns its exit code in ``RUN_RESULT_VAR``. If the -executable was built, but failed to run, then ``RUN_RESULT_VAR`` will be +or failure in ``<compileResultVar>``. If the compile succeeded, runs the +executable and returns its exit code in ``<runResultVar>``. If the +executable was built, but failed to run, then ``<runResultVar>`` will be set to ``FAILED_TO_RUN``. See the :command:`try_compile` command for information on how the test project is constructed to build the source file. @@ -85,10 +85,10 @@ presetting them in some CMake script file to the values the executable would have produced if it had been run on its actual target platform. These cache entries are: -``<RUN_RESULT_VAR>`` +``<runResultVar>`` Exit code if the executable were to be run on the target platform. -``<RUN_RESULT_VAR>__TRYRUN_OUTPUT`` +``<runResultVar>__TRYRUN_OUTPUT`` Output from stdout and stderr if the executable were to be run on the target platform. This is created only if the ``RUN_OUTPUT_VARIABLE`` or ``OUTPUT_VARIABLE`` option was used. diff --git a/Help/generator/Xcode.rst b/Help/generator/Xcode.rst index 71430c7..d893ac5 100644 --- a/Help/generator/Xcode.rst +++ b/Help/generator/Xcode.rst @@ -3,9 +3,7 @@ Xcode Generate Xcode project files. -This supports Xcode 3.0 and above. Support for Xcode versions prior -to Xcode 5 is deprecated and will be dropped in a future version of -CMake. +This supports Xcode 5.0 and above. Toolset Selection ^^^^^^^^^^^^^^^^^ diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst index 71a8b00..d9b939f 100644 --- a/Help/manual/cmake-modules.7.rst +++ b/Help/manual/cmake-modules.7.rst @@ -178,7 +178,6 @@ They are normally called through the :command:`find_package` command. /module/FindMPEG2 /module/FindMPEG /module/FindMPI - /module/FindOctave /module/FindODBC /module/FindOpenACC /module/FindOpenAL diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 409b5b1..9470d6c 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -51,6 +51,14 @@ 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.15 +================================= + +.. toctree:: + :maxdepth: 1 + + CMP0089: Compiler id for IBM Clang-based XL compilers is now XLClang. </policy/CMP0089> + Policies Introduced by CMake 3.14 ================================= diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 4366c0d..3d4536b 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -334,6 +334,7 @@ Properties on Targets /prop_tgt/VS_IOT_STARTUP_TASK /prop_tgt/VS_KEYWORD /prop_tgt/VS_MOBILE_EXTENSIONS_VERSION + /prop_tgt/VS_NO_SOLUTION_DEPLOY /prop_tgt/VS_SCC_AUXPATH /prop_tgt/VS_SCC_LOCALPATH /prop_tgt/VS_SCC_PROJECTNAME diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst index bcf75ac..d1bd69b 100644 --- a/Help/manual/ctest.1.rst +++ b/Help/manual/ctest.1.rst @@ -11,8 +11,9 @@ Synopsis .. parsed-literal:: ctest [<options>] - ctest <path-to-source> <path-to-build> --build-generator <generator> - [<options>...] [-- <build-options>...] [--test-command <test>] + ctest --build-and-test <path-to-source> <path-to-build> + --build-generator <generator> [<options>...] + [--build-options <opts>...] [--test-command <command> [<args>...]] ctest {-D <dashboard> | -M <model> -T <action> | -S <script> | -SP <script>} [-- <dashboard-options>...] diff --git a/Help/module/FindOctave.rst b/Help/module/FindOctave.rst deleted file mode 100644 index 2dbcec4..0000000 --- a/Help/module/FindOctave.rst +++ /dev/null @@ -1 +0,0 @@ -.. cmake-module:: ../../Modules/FindOctave.cmake diff --git a/Help/policy/CMP0083.rst b/Help/policy/CMP0083.rst index b26d6c8..32acf1f 100644 --- a/Help/policy/CMP0083.rst +++ b/Help/policy/CMP0083.rst @@ -23,9 +23,10 @@ which it is used, it is the project's responsibility to use the :prop_tgt:`POSITION_INDEPENDENT_CODE` target property for executables will be honored at link time. -This policy was introduced in CMake version 3.14. CMake version -|release| warns when the policy is not set and uses ``OLD`` behavior. Use -the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly. +This policy was introduced in CMake version 3.14. Use the +:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly. +Unlike most policies, CMake version |release| does not warn when this policy is +not set and simply uses ``OLD`` behavior. .. include:: DEPRECATED.txt diff --git a/Help/policy/CMP0089.rst b/Help/policy/CMP0089.rst new file mode 100644 index 0000000..e549e0c --- /dev/null +++ b/Help/policy/CMP0089.rst @@ -0,0 +1,30 @@ +CMP0089 +------- + +Compiler id for IBM Clang-based XL compilers is now ``XLClang``. + +CMake 3.15 and above recognize that IBM's Clang-based XL compilers +that define ``__ibmxl__`` are a new front-end distinct from ``xlc`` +with a different command line and set of capabilities. +CMake now prefers to present this to projects by setting the +:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``XLClang`` instead +of ``XL``. However, existing projects may assume the compiler id for +Clang-based XL is just ``XL`` as it was in CMake versions prior to 3.15. +Therefore this policy determines for Clang-based XL compilers 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 ``XL``. The +NEW behavior for this policy is to use compiler id ``XLClang``. + +This policy was introduced in CMake version 3.15. 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_CMP0089 <CMAKE_POLICY_WARNING_CMP<NNNN>>` +variable to control the warning. + +.. include:: DEPRECATED.txt diff --git a/Help/prop_sf/OBJECT_OUTPUTS.rst b/Help/prop_sf/OBJECT_OUTPUTS.rst index 6a28553..1ce4866 100644 --- a/Help/prop_sf/OBJECT_OUTPUTS.rst +++ b/Help/prop_sf/OBJECT_OUTPUTS.rst @@ -1,9 +1,9 @@ OBJECT_OUTPUTS -------------- -Additional outputs for a Makefile rule. +Additional outputs for a Ninja or Makefile rule. Additional outputs created by compilation of this source file. If any of these outputs is missing the object will be recompiled. This is -supported only on Makefile generators and will be ignored on other -generators. +supported only on the Ninja and Makefile generators and will be ignored on +other generators. diff --git a/Help/prop_tgt/BUILD_RPATH_USE_ORIGIN.rst b/Help/prop_tgt/BUILD_RPATH_USE_ORIGIN.rst index 511de7a..3378797 100644 --- a/Help/prop_tgt/BUILD_RPATH_USE_ORIGIN.rst +++ b/Help/prop_tgt/BUILD_RPATH_USE_ORIGIN.rst @@ -8,14 +8,14 @@ This property is initialized by the value of the variable On platforms that support runtime paths (``RPATH``) with the ``$ORIGIN`` token, setting this property to ``TRUE`` enables relative -paths in the build ``RPATH`` for executables that point to shared -libraries in the same build tree. +paths in the build ``RPATH`` for executables and shared libraries that +point to shared libraries in the same build tree. -Normally the build ``RPATH`` of an executable contains absolute paths -to the directory of shared libraries. Directories contained within the -build tree can be made relative to enable relocatable builds and to -help achieving reproducible builds by omitting the build directory -from the build environment. +Normally the build ``RPATH`` of a binary contains absolute paths +to the directory of each shared library it links to. The ``RPATH`` +entries for directories contained within the build tree can be made +relative to enable relocatable builds and to help achieve reproducible +builds by omitting the build directory from the build environment. This property has no effect on platforms that do not support the ``$ORIGIN`` token in ``RPATH``, or when the :variable:`CMAKE_SKIP_RPATH` diff --git a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst index e7457e1..0eee297 100644 --- a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst +++ b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst @@ -6,8 +6,16 @@ Exclude the target from the all target. A property on a target that indicates if the target is excluded from the default build target. If it is not, then with a Makefile for example typing make will cause this target to be built. The same -concept applies to the default build of other generators. Installing -a target with EXCLUDE_FROM_ALL set to true has undefined behavior. +concept applies to the default build of other generators. + +With ``EXCLUDE_FROM_ALL`` set to false or not set at all, the target +will be brought up to date as part of doing a ``make install`` or its +equivalent for the CMake generator being used. If a target has +``EXCLUDE_FROM_ALL`` set to true, then any attempt to install that +target has undefined behavior. Note that such a target can still safely +be listed in an :command:`install(TARGETS)` command as long as the install +components the target belongs to are not part of the set of components +that anything tries to install. This property is enabled by default for targets that are created in directories that have :prop_dir:`EXCLUDE_FROM_ALL` set to ``TRUE``. diff --git a/Help/prop_tgt/EXPORT_NAME.rst b/Help/prop_tgt/EXPORT_NAME.rst index 1b4247c..043c57a 100644 --- a/Help/prop_tgt/EXPORT_NAME.rst +++ b/Help/prop_tgt/EXPORT_NAME.rst @@ -3,6 +3,6 @@ EXPORT_NAME Exported name for target files. -This sets the name for the IMPORTED target generated when it this -target is is exported. If not set, the logical target name is used by -default. +This sets the name for the IMPORTED target generated by the +:command:`install(EXPORT)` and :command:`export` commands. +If not set, the logical target name is used by default. diff --git a/Help/prop_tgt/VS_NO_SOLUTION_DEPLOY.rst b/Help/prop_tgt/VS_NO_SOLUTION_DEPLOY.rst new file mode 100644 index 0000000..ffcbde5 --- /dev/null +++ b/Help/prop_tgt/VS_NO_SOLUTION_DEPLOY.rst @@ -0,0 +1,46 @@ +VS_NO_SOLUTION_DEPLOY +--------------------- + +Specify that the target should not be marked for deployment to a Windows CE +or Windows Phone device in the generated Visual Studio solution. + +Be default, all EXE and shared library (DLL) targets are marked to deploy to +the target device in the generated Visual Studio solution. + +Generator expressions are supported. + +There are reasons one might want to exclude a target / generated project from +deployment: + +- The library or executable may not be necessary in the primary deploy/debug + scenario, and excluding from deployment saves time in the + develop/download/debug cycle. +- There may be insufficient space on the target device to accommodate all of + the build products. +- Visual Studio 2013 requires a target device IP address be entered for each + target marked for deployment. For large numbers of targets, this can be + tedious. + NOTE: Visual Studio *will* deploy all project dependencies of a project + tagged for deployment to the IP address configured for that project even + if those dependencies are not tagged for deployment. + + +Example 1 +^^^^^^^^^ + +This shows setting the variable for the target foo. + +.. code-block:: cmake + + add_library(foo SHARED foo.cpp) + set_property(TARGET foo PROPERTY VS_NO_SOLUTION_DEPLOY ON) + +Example 2 +^^^^^^^^^ + +This shows setting the variable for the Release configuration only. + +.. code-block:: cmake + + add_library(foo SHARED foo.cpp) + set_property(TARGET foo PROPERTY VS_NO_SOLUTION_DEPLOY "$<CONFIG:Release>") diff --git a/Help/release/3.14.rst b/Help/release/3.14.rst index 13d209f..e4b4d38 100644 --- a/Help/release/3.14.rst +++ b/Help/release/3.14.rst @@ -166,13 +166,18 @@ Modules :command:`check_fortran_source_runs` command to check if a Fortran source snippet compiles and runs. +* The :module:`CMakePackageConfigHelpers` module's + :command:`write_basic_package_version_file` command gained a new + ``ARCH_INDEPENDENT`` option for supporting architecture-independent + packages. + * The :module:`ExternalProject` module :command:`ExternalProject_Add` command gained ``LOG_DIR`` and ``LOG_MERGED_STDOUTERR`` options to control logging. * The :module:`ExternalProject` module :command:`ExternalProject_Add` command gained ``LOG_PATCH`` to optionally log the patch step. -* The :module:`ExternalProject` module's ``ExternalProject_Add`` command +* The :module:`ExternalProject` module :command:`ExternalProject_Add` command learned to apply ``SOURCE_SUBDIR`` when ``BUILD_IN_SOURCE`` is also used. The ``BUILD_COMMAND`` is run in the given ``SOURCE_SUBDIR`` of the ``SOURCE_DIR``. @@ -211,8 +216,6 @@ Modules mirror the new options to the ``mex`` command in MATLAB R2018a. The option ``MX_LIBRARY`` is no longer needed. -* A :module:`FindOctave` module was added to find GNU octave. - * The :module:`FindPostgreSQL` module now provides imported targets. * The :module:`FindPython`, :module:`FindPython2`, and :module:`FindPython3` @@ -370,3 +373,7 @@ Other Changes :variable:`CPACK_DEBIAN_ARCHIVE_TYPE` variable, because ``dpkg`` has never supported the PAX tar format. The ``paxr`` value will be mapped to ``gnutar`` and a deprecation message emitted. + +* CMake no longer issues a warning if a target listed in an + :command:`install(TARGETS)` command has its :prop_tgt:`EXCLUDE_FROM_ALL` + property set to true. diff --git a/Help/release/dev/0-sample-topic.rst b/Help/release/dev/0-sample-topic.rst new file mode 100644 index 0000000..e4cc01e --- /dev/null +++ b/Help/release/dev/0-sample-topic.rst @@ -0,0 +1,7 @@ +0-sample-topic +-------------- + +* This is a sample release note for the change in a topic. + Developers should add similar notes for each topic branch + making a noteworthy change. Each document should be named + and titled to match the topic name to avoid merge conflicts. diff --git a/Help/release/dev/FindCups-imported-target.rst b/Help/release/dev/FindCups-imported-target.rst new file mode 100644 index 0000000..0fd9178 --- /dev/null +++ b/Help/release/dev/FindCups-imported-target.rst @@ -0,0 +1,4 @@ +FindCups-imported-target +------------------------ + +* The :module:`FindCups` module now provides imported targets. diff --git a/Help/release/dev/add-xlclang.rst b/Help/release/dev/add-xlclang.rst new file mode 100644 index 0000000..77ff938 --- /dev/null +++ b/Help/release/dev/add-xlclang.rst @@ -0,0 +1,5 @@ +add-xlclang +----------- + +* IBM Clang-based XL compilers that define ``__ibmxl__`` now use the + compiler id ``XLClang`` instead of ``XL``. See policy :policy:`CMP0089`. diff --git a/Help/release/dev/cmake_parse_arguments-keywords_missing_values.rst b/Help/release/dev/cmake_parse_arguments-keywords_missing_values.rst new file mode 100644 index 0000000..c7fe96b --- /dev/null +++ b/Help/release/dev/cmake_parse_arguments-keywords_missing_values.rst @@ -0,0 +1,6 @@ +cmake_parse_arguments-keywords_missing_values +--------------------------------------------- + +* The :command:`cmake_parse_arguments` command gained an additional + ``<prefix>_KEYWORDS_MISSING_VALUES`` output variable to report + keyword arguments that were given by the caller with no values. diff --git a/Help/release/dev/deprecate-policy-old.rst b/Help/release/dev/deprecate-policy-old.rst new file mode 100644 index 0000000..b94f4b7 --- /dev/null +++ b/Help/release/dev/deprecate-policy-old.rst @@ -0,0 +1,8 @@ +deprecate-policy-old +-------------------- + +* An explicit deprecation diagnostic was added for policy ``CMP0066`` + (``CMP0065`` and below were already deprecated). + The :manual:`cmake-policies(7)` manual explains that the OLD behaviors + of all policies are deprecated and that projects should port to the + NEW behaviors. diff --git a/Help/release/dev/list-prepend-and-pop-subcommands.rst b/Help/release/dev/list-prepend-and-pop-subcommands.rst new file mode 100644 index 0000000..16b14f1 --- /dev/null +++ b/Help/release/dev/list-prepend-and-pop-subcommands.rst @@ -0,0 +1,4 @@ +list-prepend-and-pop-subcommands +-------------------------------- + +* :command:`list` learned new sub-commands ``PREPEND``, ``POP_FRONT`` and ``POP_BACK``. diff --git a/Help/release/dev/require-xcode-5.rst b/Help/release/dev/require-xcode-5.rst new file mode 100644 index 0000000..6cfe96a --- /dev/null +++ b/Help/release/dev/require-xcode-5.rst @@ -0,0 +1,4 @@ +require-xcode-5 +--------------- + +* The :generator:`Xcode` generator now requires at least Xcode 5. diff --git a/Help/release/dev/vs-wince-no-deploy.rst b/Help/release/dev/vs-wince-no-deploy.rst new file mode 100644 index 0000000..6c18d895 --- /dev/null +++ b/Help/release/dev/vs-wince-no-deploy.rst @@ -0,0 +1,6 @@ +vs_wince_no_deploy +------------------ + +* A :prop_tgt:`VS_NO_SOLUTION_DEPLOY` target property was added to + tell :ref:`Visual Studio Generators` whether to deploy an artifact + to the WinCE or Windows Phone target device. diff --git a/Help/release/index.rst b/Help/release/index.rst index 4fcd4ca..2318e03 100644 --- a/Help/release/index.rst +++ b/Help/release/index.rst @@ -7,6 +7,8 @@ CMake Release Notes This file should include the adjacent "dev.txt" file in development versions but not in release versions. +.. include:: dev.txt + Releases ======== diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst index 5323880..2bb3979 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst +++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst @@ -24,7 +24,6 @@ include: HP = Hewlett-Packard Compiler (hp.com) IAR = IAR Systems (iar.com) Intel = Intel Compiler (intel.com) - MIPSpro = SGI MIPSpro (sgi.com) MSVC = Microsoft Visual Studio (microsoft.com) NVIDIA = NVIDIA CUDA Compiler (nvidia.com) OpenWatcom = Open Watcom (openwatcom.org) diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst index cc80851..e361fd9 100644 --- a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst +++ b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst @@ -6,4 +6,9 @@ Directories implicitly searched by the compiler for header files. CMake does not explicitly specify these directories on compiler command lines for language ``<LANG>``. This prevents system include directories from being treated as user include directories on some -compilers. +compilers, which is important for ``C``, ``CXX``, and ``CUDA`` to +avoid overriding standard library headers. + +This value is not used for ``Fortran`` because it has no standard +library headers and some compilers do not search their implicit +include directories for module ``.mod`` files. diff --git a/Help/variable/CMAKE_MAKE_PROGRAM.rst b/Help/variable/CMAKE_MAKE_PROGRAM.rst index 4f5a50f..56df2df 100644 --- a/Help/variable/CMAKE_MAKE_PROGRAM.rst +++ b/Help/variable/CMAKE_MAKE_PROGRAM.rst @@ -19,15 +19,11 @@ to configure the project: This generator stores ``CMAKE_MAKE_PROGRAM`` in the CMake cache so that it may be edited by the user. -* The :generator:`Xcode` generator sets this to ``xcodebuild`` (or possibly an - otherwise undocumented ``cmakexbuild`` wrapper implementing some - workarounds). +* The :generator:`Xcode` generator sets this to ``xcodebuild``. This generator prefers to lookup the build tool at build time rather than to store ``CMAKE_MAKE_PROGRAM`` in the CMake cache - ahead of time. This is because ``xcodebuild`` is easy to find, - the ``cmakexbuild`` wrapper is needed only for older Xcode versions, - and the path to ``cmakexbuild`` may be outdated if CMake itself moves. + ahead of time. This is because ``xcodebuild`` is easy to find. For compatibility with versions of CMake prior to 3.2, if a user or project explicitly adds ``CMAKE_MAKE_PROGRAM`` to diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst index d179728..fc52e7b 100644 --- a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst +++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst @@ -21,6 +21,8 @@ warn by default: policy :policy:`CMP0067`. * ``CMAKE_POLICY_WARNING_CMP0082`` controls the warning for policy :policy:`CMP0082`. +* ``CMAKE_POLICY_WARNING_CMP0089`` controls the warning for + policy :policy:`CMP0089`. This variable should not be set by a project in CMake code. Project developers running CMake may set this variable in their cache to diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 4d0c681..7aac846 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -57,6 +57,7 @@ function(compiler_id_detection outvar lang) HP Compaq zOS + XLClang XL VisualAge PGI @@ -86,8 +87,6 @@ function(compiler_id_detection outvar lang) SDCC ) endif() - list(APPEND ordered_compilers - MIPSpro) #Currently the only CUDA compilers are NVIDIA if(lang STREQUAL CUDA) @@ -98,6 +97,8 @@ function(compiler_id_detection outvar lang) foreach(Id ${ordered_compilers}) string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n") endforeach() + # Hard-code definitions for compilers that are no longer supported. + string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_MIPSpro 0\n") endif() set(pp_if "#if") diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index dbc41c8..b8c8c5d 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -83,7 +83,7 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C") list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC ) - set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "/?") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "-?") set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft") list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI ) @@ -110,6 +110,10 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ADSP "-version") set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ADSP "Analog Devices") + list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS QCC) + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_QCC "-V") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_QCC "gcc_nto") + include(CMakeDetermineCompilerId) set(userflags) CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT} "${userflags}") diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index d7f6f97..3ec534f 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -139,8 +139,9 @@ if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME) - if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$") + if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$") set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) + set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5}) elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") if(CMAKE_C_COMPILER_TARGET) set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_C_COMPILER_TARGET}-) diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index bd878b2..68cb9fe 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -136,8 +136,9 @@ if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME) - if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$") + if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$") set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) + set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5}) elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if(CMAKE_CXX_COMPILER_TARGET) set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_CXX_COMPILER_TARGET}-) diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index fd1d5fb..e0d2449 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -96,6 +96,12 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Parsed ${lang} implicit include dir info from above output: rv=${rv}\n${log}\n\n") if("${rv}" STREQUAL "done") + # Entries that we have been told to explicitly pass as standard include + # directories will not be implicitly added by the compiler. + if(CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES) + list(REMOVE_ITEM implicit_incdirs ${CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES}) + endif() + # We parsed implicit include directories, so override the default initializer. set(_CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES_INIT "${implicit_incdirs}") endif() diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 83ce392..59dab6d 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -181,7 +181,10 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(vs_version ${CMAKE_MATCH_1}) set(id_platform ${CMAKE_VS_PLATFORM_NAME}) set(id_lang "${lang}") - if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*") + set(id_PostBuildEvent_Command "") + if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm]$") + set(id_cl_var "ClangClExecutable") + elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*") set(id_cl clang.exe) else() set(id_cl cl.exe) @@ -268,7 +271,11 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR}) set(id_src "${src}") set(id_compile "ClCompile") - set(id_PostBuildEvent_Command "for %%i in (${id_cl}) do %40echo CMAKE_${lang}_COMPILER=%%~$PATH:i") + if(id_cl_var) + set(id_PostBuildEvent_Command "echo CMAKE_${lang}_COMPILER=$(${id_cl_var})") + else() + set(id_PostBuildEvent_Command "for %%i in (${id_cl}) do %40echo CMAKE_${lang}_COMPILER=%%~$PATH:i") + endif() set(id_Import_props "") set(id_Import_targets "") set(id_ItemDefinitionGroup_entry "") @@ -824,7 +831,7 @@ function(CMAKE_DIAGNOSE_UNSUPPORTED_CLANG lang envvar) endif() # Test whether an MSVC-like command-line option works. - execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" /? + execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -? RESULT_VARIABLE _clang_result OUTPUT_VARIABLE _clang_stdout ERROR_VARIABLE _clang_stderr) diff --git a/Modules/CMakeDetermineVSServicePack.cmake b/Modules/CMakeDetermineVSServicePack.cmake index 9edc309..a3c4d9c 100644 --- a/Modules/CMakeDetermineVSServicePack.cmake +++ b/Modules/CMakeDetermineVSServicePack.cmake @@ -79,7 +79,7 @@ endfunction() function(_DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR) if(EXISTS ${CMAKE_CXX_COMPILER}) execute_process( - COMMAND ${CMAKE_CXX_COMPILER} /? + COMMAND ${CMAKE_CXX_COMPILER} -? ERROR_VARIABLE _output OUTPUT_QUIET ) diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in index 5995694..30f8d4c 100644 --- a/Modules/CMakeFortranCompilerId.F.in +++ b/Modules/CMakeFortranCompilerId.F.in @@ -96,13 +96,6 @@ # if defined(__FLANG_PATCHLEVEL__) # define COMPILER_VERSION_PATCH DEC(__FLANG_PATCHLEVEL__) # endif -#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) - PRINT *, 'INFO:compiler[MIPSpro]' -# if 0 -! This compiler is either not known or is too old to define an -! identification macro. Try to identify the platform and guess that -! it is the native compiler. -# endif #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) PRINT *, 'INFO:compiler[VisualAge]' #elif defined(__hpux) || defined(__hpux__) diff --git a/Modules/CMakeParseImplicitIncludeInfo.cmake b/Modules/CMakeParseImplicitIncludeInfo.cmake index 21e24b7..6d7732d 100644 --- a/Modules/CMakeParseImplicitIncludeInfo.cmake +++ b/Modules/CMakeParseImplicitIncludeInfo.cmake @@ -92,13 +92,15 @@ function(cmake_parse_implicit_include_line line lang id_var log_var state_var) endif() # XL compiler - if("${CMAKE_${lang}_COMPILER_ID}" STREQUAL "XL" AND "${line}" MATCHES "^/" + if(("${CMAKE_${lang}_COMPILER_ID}" STREQUAL "XL" + OR "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "XLClang") + AND "${line}" MATCHES "^/" AND ( ("${lang}" STREQUAL "Fortran" AND "${line}" MATCHES "/xl[fF]entry " AND "${line}" MATCHES "OSVAR\\([^ ]+\\)") OR ( ("${lang}" STREQUAL "C" OR "${lang}" STREQUAL "CXX") AND - "${line}" MATCHES "/xl[cC]entry " AND + "${line}" MATCHES "/xl[cC]2?entry " AND "${line}" MATCHES " -qosvar=") ) ) # -qnostdinc cancels other stdinc flags, even if present diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake index 7db976b..5e3f195 100644 --- a/Modules/CheckCXXSourceRuns.cmake +++ b/Modules/CheckCXXSourceRuns.cmake @@ -103,7 +103,8 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT) + COMPILE_OUTPUT_VARIABLE OUTPUT + RUN_OUTPUT_VARIABLE RUN_OUTPUT) # if it did not compile make the return value fail code of 1 if(NOT ${VAR}_COMPILED) @@ -118,6 +119,8 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n" "${OUTPUT}\n" + "...and run output:\n" + "${RUN_OUTPUT}\n" "Return value: ${${VAR}}\n" "Source file was:\n${SOURCE}\n") else() @@ -133,6 +136,8 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n" "${OUTPUT}\n" + "...and run output:\n" + "${RUN_OUTPUT}\n" "Return value: ${${VAR}_EXITCODE}\n" "Source file was:\n${SOURCE}\n") endif() diff --git a/Modules/CheckFortranSourceRuns.cmake b/Modules/CheckFortranSourceRuns.cmake index 13fdb0b..a80c13d 100644 --- a/Modules/CheckFortranSourceRuns.cmake +++ b/Modules/CheckFortranSourceRuns.cmake @@ -133,7 +133,8 @@ macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT) + COMPILE_OUTPUT_VARIABLE OUTPUT + RUN_OUTPUT_VARIABLE RUN_OUTPUT) # if it did not compile make the return value fail code of 1 if(NOT ${VAR}_COMPILED) @@ -148,6 +149,8 @@ macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing Fortran SOURCE FILE Test ${VAR} succeeded with the following output:\n" "${OUTPUT}\n" + "...and run output:\n" + "${RUN_OUTPUT}\n" "Return value: ${${VAR}}\n" "Source file was:\n${SOURCE}\n") else() @@ -163,6 +166,8 @@ macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing Fortran SOURCE FILE Test ${VAR} failed with the following output:\n" "${OUTPUT}\n" + "...and run output:\n" + "${RUN_OUTPUT}\n" "Return value: ${${VAR}_EXITCODE}\n" "Source file was:\n${SOURCE}\n") endif() diff --git a/Modules/Compiler/CrayPrgEnv.cmake b/Modules/Compiler/CrayPrgEnv.cmake index 6c1c770..e55e587 100644 --- a/Modules/Compiler/CrayPrgEnv.cmake +++ b/Modules/Compiler/CrayPrgEnv.cmake @@ -1,8 +1,93 @@ # Guard against multiple inclusions -if(__craylinux_crayprgenv) +if(__cmake_craype_crayprgenv) return() endif() -set(__craylinux_crayprgenv 1) +set(__cmake_craype_crayprgenv 1) + +# CrayPrgEnv: loaded when compiling through the Cray compiler wrapper. +# The compiler wrapper can run on a front-end node or a compute node. + +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) # if IN_LIST + +# One-time setup of the craype environment. First, check the wrapper config. +# The wrapper's selection of a compiler (gcc, clang, intel, etc.) and +# default include/library paths is selected using the "module" command. +# The CRAYPE_LINK_TYPE environment variable partly controls if static +# or dynamic binaries are generated (see __cmake_craype_linktype below). +# Running cmake and then changing module and/or linktype configuration +# may cause build problems (since the data in the cmake cache may no +# longer be correct after the change). We can look for this and warn +# the user about it. Second, use the "module" provided PKG_CONFIG_PATH-like +# environment variable to add additional prefixes to the system prefix +# path. +function(__cmake_craype_setupenv) + if(NOT DEFINED __cmake_craype_setupenv_done) # only done once per run + set(__cmake_craype_setupenv_done 1 PARENT_SCOPE) + unset(__cmake_check) + set(CMAKE_CRAYPE_LINKTYPE "$ENV{CRAYPE_LINK_TYPE}" CACHE STRING + "saved value of CRAYPE_LINK_TYPE environment variable") + set(CMAKE_CRAYPE_LOADEDMODULES "$ENV{LOADEDMODULES}" CACHE STRING + "saved value of LOADEDMODULES environment variable") + mark_as_advanced(CMAKE_CRAYPE_LINKTYPE CMAKE_CRAYPE_LOADEDMODULES) + if (NOT "${CMAKE_CRAYPE_LINKTYPE}" STREQUAL "$ENV{CRAYPE_LINK_TYPE}") + string(APPEND __cmake_check "CRAYPE_LINK_TYPE ") + endif() + if (NOT "${CMAKE_CRAYPE_LOADEDMODULES}" STREQUAL "$ENV{LOADEDMODULES}") + string(APPEND __cmake_check "LOADEDMODULES ") + endif() + if(DEFINED __cmake_check) + message(STATUS "NOTE: ${__cmake_check}changed since initial config!") + message(STATUS "NOTE: this may cause unexpected build errors.") + endif() + # loop over variables of interest + foreach(pkgcfgvar PKG_CONFIG_PATH PKG_CONFIG_PATH_DEFAULT + PE_PKG_CONFIG_PATH) + file(TO_CMAKE_PATH "$ENV{${pkgcfgvar}}" pkgcfg) + foreach(path ${pkgcfg}) + string(REGEX REPLACE "(.*)/lib[^/]*/pkgconfig$" "\\1" path "${path}") + if(NOT "${path}" STREQUAL "" AND + NOT "${path}" IN_LIST CMAKE_SYSTEM_PREFIX_PATH) + list(APPEND CMAKE_SYSTEM_PREFIX_PATH "${path}") + endif() + endforeach() + endforeach() + # push it up out of this function into the parent scope + set(CMAKE_SYSTEM_PREFIX_PATH "${CMAKE_SYSTEM_PREFIX_PATH}" PARENT_SCOPE) + endif() +endfunction() + +# The wrapper disables dynamic linking by default. Dynamic linking is +# enabled either by setting $ENV{CRAYPE_LINK_TYPE} to "dynamic" or by +# specifying "-dynamic" to the wrapper when linking. Specifying "-static" +# to the wrapper when linking takes priority over $ENV{CRAYPE_LINK_TYPE}. +# Furthermore, if you specify multiple "-dynamic" and "-static" flags to +# the wrapper when linking, the last one will win. In this case, the +# wrapper will also print a warning like: +# Warning: -dynamic was already seen on command line, overriding with -static. +# +# note that cmake applies both CMAKE_${lang}_FLAGS and CMAKE_EXE_LINKER_FLAGS +# (in that order) to the linking command, so -dynamic can appear in either +# variable. +function(__cmake_craype_linktype lang rv) + # start with ENV, but allow flags to override + if("$ENV{CRAYPE_LINK_TYPE}" STREQUAL "dynamic") + set(linktype dynamic) + else() + set(linktype static) + endif() + # combine flags and convert to a list so we can apply the flags in order + set(linkflags "${CMAKE_${lang}_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}") + string(REPLACE " " ";" linkflags "${linkflags}") + foreach(flag IN LISTS linkflags) + if("${flag}" STREQUAL "-dynamic") + set(linktype dynamic) + elseif("${flag}" STREQUAL "-static") + set(linktype static) + endif() + endforeach() + set(${rv} ${linktype} PARENT_SCOPE) +endfunction() macro(__CrayPrgEnv_setup lang) if(DEFINED ENV{CRAYPE_VERSION}) @@ -13,25 +98,25 @@ macro(__CrayPrgEnv_setup lang) message(STATUS "Cray Programming Environment (unknown version) ${lang}") endif() + # setup the craype environment + __cmake_craype_setupenv() + # Flags for the Cray wrappers set(CMAKE_STATIC_LIBRARY_LINK_${lang}_FLAGS "-static") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared") set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-dynamic") - # If the link type is not explicitly specified in the environment then - # the Cray wrappers assume that the code will be built statically so - # we check the following condition(s) are NOT met - # Compiler flags are explicitly dynamic - # Env var is dynamic and compiler flags are not explicitly static - if(NOT (((CMAKE_${lang}_FLAGS MATCHES "(^| )-dynamic($| )") OR - (CMAKE_EXE_LINKER_FLAGS MATCHES "(^| )-dynamic($| )")) - OR - (("$ENV{CRAYPE_LINK_TYPE}" STREQUAL "dynamic") AND - NOT ((CMAKE_${lang}_FLAGS MATCHES "(^| )-static($| )") OR - (CMAKE_EXE_LINKER_FLAGS MATCHES "(^| )-static($| )"))))) + # determine linktype from environment and compiler flags + __cmake_craype_linktype(${lang} __cmake_craype_${lang}_linktype) + + # switch off shared libs if we get a static linktype + if("${__cmake_craype_${lang}_linktype}" STREQUAL "static") set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) set(BUILD_SHARED_LIBS FALSE CACHE BOOL "") set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") set(CMAKE_LINK_SEARCH_START_STATIC TRUE) endif() + endmacro() + +cmake_policy(POP) diff --git a/Modules/Compiler/GNU-FindBinUtils.cmake b/Modules/Compiler/GNU-FindBinUtils.cmake index 16b7bbd..097fbf3 100644 --- a/Modules/Compiler/GNU-FindBinUtils.cmake +++ b/Modules/Compiler/GNU-FindBinUtils.cmake @@ -18,7 +18,7 @@ get_filename_component(__gcc_hints "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPIL find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x_y}" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x}" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_COMPILER_SUFFIX}" HINTS ${__gcc_hints} DOC "A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler" ) @@ -28,7 +28,7 @@ mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR) find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x_y}" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x}" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_COMPILER_SUFFIX}" HINTS ${__gcc_hints} DOC "A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler" ) diff --git a/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake index e5b9741..899e284 100644 --- a/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake +++ b/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake @@ -1,14 +1,6 @@ set(_compiler_id_version_compute " -# if defined(__ibmxl__) -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__ibmxl_version__) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__ibmxl_release__) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__ibmxl_modification__) -# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__ibmxl_ptf_fix_level__) -# else - /* __IBMC__ = VRP */ -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__IBMC__/100) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__IBMC__/10 % 10) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__IBMC__ % 10) -# endif -") + /* __IBMC__ = VRP */ +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__IBMC__/100) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__IBMC__/10 % 10) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__IBMC__ % 10)") diff --git a/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake index 63c3e32..73aa2b4 100644 --- a/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake +++ b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake @@ -1,14 +1,6 @@ set(_compiler_id_version_compute " -# if defined(__ibmxl__) -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__ibmxl_version__) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__ibmxl_release__) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__ibmxl_modification__) -# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__ibmxl_ptf_fix_level__) -# else - /* __IBMCPP__ = VRP */ -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__IBMCPP__/100) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__IBMCPP__/10 % 10) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__IBMCPP__ % 10) -# endif -") + /* __IBMCPP__ = VRP */ +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__IBMCPP__/100) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__IBMCPP__/10 % 10) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__IBMCPP__ % 10)") diff --git a/Modules/Compiler/MIPSpro-C.cmake b/Modules/Compiler/MIPSpro-C.cmake deleted file mode 100644 index 675560c..0000000 --- a/Modules/Compiler/MIPSpro-C.cmake +++ /dev/null @@ -1 +0,0 @@ -set(CMAKE_C_VERBOSE_FLAG "-v") diff --git a/Modules/Compiler/MIPSpro-CXX.cmake b/Modules/Compiler/MIPSpro-CXX.cmake deleted file mode 100644 index 9fb191c..0000000 --- a/Modules/Compiler/MIPSpro-CXX.cmake +++ /dev/null @@ -1 +0,0 @@ -set(CMAKE_CXX_VERBOSE_FLAG "-v") diff --git a/Modules/Compiler/MIPSpro-DetermineCompiler.cmake b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake deleted file mode 100644 index 9e48553..0000000 --- a/Modules/Compiler/MIPSpro-DetermineCompiler.cmake +++ /dev/null @@ -1,15 +0,0 @@ - -set(_compiler_id_pp_test "defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)") - -set(_compiler_id_version_compute " -# if defined(_SGI_COMPILER_VERSION) - /* _SGI_COMPILER_VERSION = VRP */ -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(_SGI_COMPILER_VERSION/100) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(_SGI_COMPILER_VERSION/10 % 10) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(_SGI_COMPILER_VERSION % 10) -# else - /* _COMPILER_VERSION = VRP */ -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(_COMPILER_VERSION/100) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(_COMPILER_VERSION/10 % 10) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(_COMPILER_VERSION % 10) -# endif") diff --git a/Modules/Compiler/MIPSpro-Fortran.cmake b/Modules/Compiler/MIPSpro-Fortran.cmake deleted file mode 100644 index ffceea8..0000000 --- a/Modules/Compiler/MIPSpro-Fortran.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_Fortran_VERBOSE_FLAG "-v") -set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixedform") -set(CMAKE_Fortran_FORMAT_FREE_FLAG "-freeform") diff --git a/Modules/Compiler/QCC-ASM.cmake b/Modules/Compiler/QCC-ASM.cmake new file mode 100644 index 0000000..9a9935b --- /dev/null +++ b/Modules/Compiler/QCC-ASM.cmake @@ -0,0 +1,2 @@ +include(Compiler/QCC) +__compiler_qcc(ASM) diff --git a/Modules/Compiler/XL-C-DetermineCompiler.cmake b/Modules/Compiler/XL-C-DetermineCompiler.cmake index 484811e..3f4e05c 100644 --- a/Modules/Compiler/XL-C-DetermineCompiler.cmake +++ b/Modules/Compiler/XL-C-DetermineCompiler.cmake @@ -1,4 +1,4 @@ -set(_compiler_id_pp_test "defined(__ibmxl__) || (defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800)") +set(_compiler_id_pp_test "defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800") include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake") diff --git a/Modules/Compiler/XL-C.cmake b/Modules/Compiler/XL-C.cmake index 5dc8bc1..6fc9728 100644 --- a/Modules/Compiler/XL-C.cmake +++ b/Modules/Compiler/XL-C.cmake @@ -6,36 +6,15 @@ string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG") # -qthreaded = Ensures that all optimizations will be thread-safe string(APPEND CMAKE_C_FLAGS_INIT " -qthreaded") -# XL v13.1.1 for Linux ppc64 little-endian switched to using a clang based -# front end and accepts the -std= option while only reserving -qlanglevel= for -# compatibility. All other versions (previous versions on Linux ppc64 -# little-endian, all versions on Linux ppc64 big-endian, all versions on AIX -# and BGQ, etc) are derived from the UNIX compiler and only accept the -# -qlanglvl option. if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1) - if (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND - CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) - set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89") - set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu89") - set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99") - set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99") - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2) - set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") - set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11") - else () - set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x") - set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x") - endif () - else () - set(CMAKE_C90_STANDARD_COMPILE_OPTION "-qlanglvl=stdc89") - set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-qlanglvl=extc89") - set(CMAKE_C99_STANDARD_COMPILE_OPTION "-qlanglvl=stdc99") - set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-qlanglvl=extc99") - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1) - set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x") - set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x") - endif () + set(CMAKE_C90_STANDARD_COMPILE_OPTION "-qlanglvl=stdc89") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-qlanglvl=extc89") + set(CMAKE_C99_STANDARD_COMPILE_OPTION "-qlanglvl=stdc99") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-qlanglvl=extc99") + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1) + set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x") endif () endif() -__compiler_check_default_language_standard(C 10.1 90) +__compiler_check_default_language_standard(C 10.1 90 11.1 99) diff --git a/Modules/Compiler/XL-CXX-DetermineCompiler.cmake b/Modules/Compiler/XL-CXX-DetermineCompiler.cmake index 2bf1ec6..dffa4bc 100644 --- a/Modules/Compiler/XL-CXX-DetermineCompiler.cmake +++ b/Modules/Compiler/XL-CXX-DetermineCompiler.cmake @@ -1,4 +1,4 @@ -set(_compiler_id_pp_test "defined(__ibmxl__) || (defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800)") +set(_compiler_id_pp_test "defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800") include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake") diff --git a/Modules/Compiler/XL-CXX.cmake b/Modules/Compiler/XL-CXX.cmake index b87e923..0026b4a 100644 --- a/Modules/Compiler/XL-CXX.cmake +++ b/Modules/Compiler/XL-CXX.cmake @@ -6,41 +6,16 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG") # -qthreaded = Ensures that all optimizations will be thread-safe string(APPEND CMAKE_CXX_FLAGS_INIT " -qthreaded") -# XL v13.1.1 for Linux ppc64 little-endian switched to using a clang based -# front end and accepts the -std= option while only reserving -qlanglevel= for -# compatibility. All other versions (previous versions on Linux ppc64 -# little-endian, all versions on Linux ppc64 big-endian, all versions on AIX -# and BGQ, etc) are derived from the UNIX compiler and only accept the -# -qlanglvl option. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1) - if (CMAKE_SYSTEM MATCHES "Linux.*ppc64") - if (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND - CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-qlanglvl=extended1y") - else () - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") - endif () - else () - # The non-clang based Linux ppc64 compiler, both big-endian and - # little-endian lacks, the non-extension language level flags - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-qlanglvl=extended") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-qlanglvl=extended") - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") - endif () - else () + if(CMAKE_SYSTEM MATCHES "Linux") + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") + else() set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-qlanglvl=strict98") set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-qlanglvl=extended") - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") - endif () + endif() + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") endif () __compiler_check_default_language_standard(CXX 10.1 98) diff --git a/Modules/Compiler/XL.cmake b/Modules/Compiler/XL.cmake index 68dc28a..a9cec11 100644 --- a/Modules/Compiler/XL.cmake +++ b/Modules/Compiler/XL.cmake @@ -10,12 +10,6 @@ set(__COMPILER_XL 1) include(Compiler/CMakeCommonCompilerMacros) -# Find the CreateExportList program that comes with this toolchain. -find_program(CMAKE_XL_CreateExportList - NAMES CreateExportList - DOC "IBM XL CreateExportList tool" - ) - macro(__compiler_xl lang) # Feature flags. set(CMAKE_${lang}_VERBOSE_FLAG "-V") @@ -35,20 +29,4 @@ macro(__compiler_xl lang) set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>") set(CMAKE_DEPFILE_FLAGS_${lang} "-MF <DEPFILE> -qmakedep=gcc") - - # CMAKE_XL_CreateExportList is part of the AIX XL compilers but not the linux ones. - # If we found the tool, we'll use it to create exports, otherwise stick with the regular - # create shared library compile line. - if (CMAKE_XL_CreateExportList) - # The compiler front-end passes all object files, archive files, and shared - # library files named on the command line to CreateExportList to create a - # list of all symbols to be exported from the shared library. This causes - # all archive members to be copied into the shared library whether they are - # needed or not. Instead we run the tool ourselves to pass only the object - # files so that we export only the symbols actually provided by the sources. - set(CMAKE_${lang}_CREATE_SHARED_LIBRARY - "${CMAKE_XL_CreateExportList} <OBJECT_DIR>/objects.exp <OBJECTS>" - "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" - ) - endif() endmacro() diff --git a/Modules/Compiler/XLClang-C-DetermineCompiler.cmake b/Modules/Compiler/XLClang-C-DetermineCompiler.cmake new file mode 100644 index 0000000..4d89921 --- /dev/null +++ b/Modules/Compiler/XLClang-C-DetermineCompiler.cmake @@ -0,0 +1,8 @@ +set(_compiler_id_pp_test "defined(__ibmxl__) && defined(__clang__)") + +set(_compiler_id_version_compute " +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__ibmxl_version__) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__ibmxl_release__) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__ibmxl_modification__) +# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__ibmxl_ptf_fix_level__) +") diff --git a/Modules/Compiler/XLClang-C.cmake b/Modules/Compiler/XLClang-C.cmake new file mode 100644 index 0000000..8e8fcf2 --- /dev/null +++ b/Modules/Compiler/XLClang-C.cmake @@ -0,0 +1,17 @@ +include(Compiler/XLClang) +__compiler_xlclang(C) + +if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) + set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu89") + set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99") + set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x") + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2) + set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11") + endif () +endif() + +__compiler_check_default_language_standard(C 13.1.1 99) diff --git a/Modules/Compiler/XLClang-CXX-DetermineCompiler.cmake b/Modules/Compiler/XLClang-CXX-DetermineCompiler.cmake new file mode 100644 index 0000000..4d89921 --- /dev/null +++ b/Modules/Compiler/XLClang-CXX-DetermineCompiler.cmake @@ -0,0 +1,8 @@ +set(_compiler_id_pp_test "defined(__ibmxl__) && defined(__clang__)") + +set(_compiler_id_version_compute " +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__ibmxl_version__) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__ibmxl_release__) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__ibmxl_modification__) +# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__ibmxl_ptf_fix_level__) +") diff --git a/Modules/Compiler/XLClang-CXX.cmake b/Modules/Compiler/XLClang-CXX.cmake new file mode 100644 index 0000000..f535ebc --- /dev/null +++ b/Modules/Compiler/XLClang-CXX.cmake @@ -0,0 +1,20 @@ +include(Compiler/XLClang) +__compiler_xlclang(CXX) + +if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") + endif () +endif() + +__compiler_check_default_language_standard(CXX 13.1.1 98) + +set(CMAKE_CXX_COMPILE_OBJECT + "<CMAKE_CXX_COMPILER> -x c++ <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") diff --git a/Modules/Compiler/XLClang.cmake b/Modules/Compiler/XLClang.cmake new file mode 100644 index 0000000..cdf0fdc --- /dev/null +++ b/Modules/Compiler/XLClang.cmake @@ -0,0 +1,22 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +# This module is shared by multiple languages; use include blocker. +if(__COMPILER_XLCLANG) + return() +endif() +set(__COMPILER_XLCLANG 1) + +include(Compiler/XL) + +macro(__compiler_xlclang lang) + __compiler_xl(${lang}) + + # Feature flags. + set(CMAKE_${lang}_VERBOSE_FLAG "-V") + set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") + set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIC") + set(CMAKE_${lang}_RESPONSE_FILE_FLAG "@") + set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@") +endmacro() diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index c5d6b45..e097894 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -550,7 +550,8 @@ External Project Definition When enabled, the output of the test step is logged to files. ``LOG_MERGED_STDOUTERR <bool>`` - When enabled, the output the step is not split by stdout and stderr. + When enabled, stdout and stderr will be merged for any step whose + output is being logged to files. ``LOG_OUTPUT_ON_FAILURE <bool>`` This option only has an effect if at least one of the other ``LOG_<step>`` diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 8c112d4..7882c4b 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -1807,10 +1807,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} ) endforeach() list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} ) @@ -1819,10 +1821,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) endforeach() list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) endif() endforeach() @@ -1860,10 +1864,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} ) endforeach() list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} ) @@ -1872,10 +1878,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) endforeach() list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) endif() endforeach() diff --git a/Modules/FindCups.cmake b/Modules/FindCups.cmake index 10ce229..27105b9 100644 --- a/Modules/FindCups.cmake +++ b/Modules/FindCups.cmake @@ -5,18 +5,38 @@ FindCups -------- -Try to find the Cups printing system +Find the CUPS printing system. -Once done this will define +Set CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE to TRUE if you need a version which +features this function (i.e. at least 1.1.19) -:: +Imported targets +^^^^^^^^^^^^^^^^ - CUPS_FOUND - system has Cups - CUPS_INCLUDE_DIR - the Cups include directory - CUPS_LIBRARIES - Libraries needed to use Cups - CUPS_VERSION_STRING - version of Cups found (since CMake 2.8.8) - Set CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE to TRUE if you need a version which - features this function (i.e. at least 1.1.19) +This module defines :prop_tgt:`IMPORTED` target ``Cups::Cups``, if Cups has +been found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``CUPS_FOUND`` + true if CUPS headers and libraries were found +``CUPS_INCLUDE_DIRS`` + the directory containing the Cups headers +``CUPS_LIBRARIES`` + the libraries to link against to use CUPS. +``CUPS_VERSION_STRING`` + the version of CUPS found (since CMake 2.8.8) + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``CUPS_INCLUDE_DIR`` + the directory containing the Cups headers #]=======================================================================] find_path(CUPS_INCLUDE_DIR cups/cups.h ) @@ -66,3 +86,13 @@ else () endif () mark_as_advanced(CUPS_INCLUDE_DIR CUPS_LIBRARIES) + +if (CUPS_FOUND) + set(CUPS_INCLUDE_DIRS "${CUPS_INCLUDE_DIR}") + if (NOT TARGET Cups::Cups) + add_library(Cups::Cups INTERFACE IMPORTED) + set_target_properties(Cups::Cups PROPERTIES + INTERFACE_LINK_LIBRARIES "${CUPS_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${CUPS_INCLUDE_DIR}") + endif () +endif () diff --git a/Modules/FindOctave.cmake b/Modules/FindOctave.cmake deleted file mode 100644 index 8110ff1..0000000 --- a/Modules/FindOctave.cmake +++ /dev/null @@ -1,179 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindOctave ----------- - -Finds GNU Octave interpreter, libraries and compilers. - -Imported targets -^^^^^^^^^^^^^^^^ - -This module defines the following :prop_tgt:`IMPORTED` targets: - -``Octave::Interpreter`` - Octave interpreter (the main program) -``Octave::Octave`` - include directories and the octave library -``Octave::Octinterp`` - include directories and the octinterp library including the dependency on - Octave::Octave - -If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed. - -Result Variables -^^^^^^^^^^^^^^^^ - -``Octave_FOUND`` - Octave interpreter and/or libraries were found -``Octave_<component>_FOUND`` - Octave <component> specified was found - -``Octave_EXECUTABLE`` - Octave interpreter -``Octave_INCLUDE_DIRS`` - include path for mex.h -``Octave_LIBRARIES`` - octinterp, octave libraries - - -Cache variables -^^^^^^^^^^^^^^^ - -The following cache variables may also be set: - -``Octave_INTERP_LIBRARY`` - path to the library octinterp -``Octave_OCTAVE_LIBRARY`` - path to the liboctave library - -#]=======================================================================] - -cmake_policy(VERSION 3.3) - -unset(Octave_REQUIRED_VARS) -unset(Octave_Development_FOUND) -unset(Octave_Interpreter_FOUND) -set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Interpreter) - -if(Development IN_LIST Octave_FIND_COMPONENTS) - find_program(Octave_CONFIG_EXECUTABLE - NAMES octave-config) - - if(Octave_CONFIG_EXECUTABLE) - - execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p BINDIR - OUTPUT_VARIABLE Octave_BINARY_DIR - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR - OUTPUT_VARIABLE Octave_INCLUDE_DIR - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - list(APPEND Octave_REQUIRED_VARS ${Octave_INCLUDE_DIR}) - - execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p OCTLIBDIR - OUTPUT_VARIABLE Octave_LIB1 - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p LIBDIR - OUTPUT_VARIABLE Octave_LIB2 - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - find_library(Octave_INTERP_LIBRARY - NAMES octinterp - PATHS ${Octave_LIB1} ${Octave_LIB2} - NO_DEFAULT_PATH - ) - find_library(Octave_OCTAVE_LIBRARY - NAMES octave - PATHS ${Octave_LIB1} ${Octave_LIB2} - NO_DEFAULT_PATH - ) - list(APPEND Octave_REQUIRED_VARS ${Octave_OCTAVE_LIBRARY} ${Octave_INTERP_LIBRARY}) - - if(Octave_REQUIRED_VARS) - set(Octave_Development_FOUND true) - endif() - endif(Octave_CONFIG_EXECUTABLE) -endif() - -if(Interpreter IN_LIST Octave_FIND_COMPONENTS) - - find_program(Octave_EXECUTABLE - NAMES octave) - - list(APPEND Octave_REQUIRED_VARS ${Octave_EXECUTABLE}) - -endif() - -if(Octave_EXECUTABLE) - execute_process(COMMAND ${Octave_EXECUTABLE} -v - OUTPUT_VARIABLE Octave_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - - string(REGEX REPLACE "GNU Octave, version ([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" Octave_VERSION_MAJOR ${Octave_VERSION}) - string(REGEX REPLACE "GNU Octave, version [0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" Octave_VERSION_MINOR ${Octave_VERSION}) - string(REGEX REPLACE "GNU Octave, version [0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Octave_VERSION_PATCH ${Octave_VERSION}) - - set(Octave_VERSION ${Octave_VERSION_MAJOR}.${Octave_VERSION_MINOR}.${Octave_VERSION_PATCH}) - - set(Octave_Interpreter_FOUND true) - -endif(Octave_EXECUTABLE) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Octave - REQUIRED_VARS Octave_REQUIRED_VARS - VERSION_VAR Octave_VERSION - HANDLE_COMPONENTS) - - -if(Octave_Development_FOUND) - set(Octave_LIBRARIES ${Octave_INTERP_LIBRARY} ${Octave_OCTAVE_LIBRARY}) - set(Octave_INCLUDE_DIRS ${Octave_INCLUDE_DIR}) - - if(NOT TARGET Octave::Octave) - add_library(Octave::Octave UNKNOWN IMPORTED) - set_target_properties(Octave::Octave PROPERTIES - IMPORTED_LOCATION ${Octave_OCTAVE_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${Octave_INCLUDE_DIR} - ) - endif() - - if(NOT TARGET Octave::Octinterp) - add_library(Octave::Octinterp UNKNOWN IMPORTED) - set_target_properties(Octave::Octinterp PROPERTIES - IMPORTED_LOCATION ${Octave_INTERP_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${Octave_INCLUDE_DIR}) - target_link_libraries(Octave::Octinterp INTERFACE - Octave::Octave) - endif() - -endif() - - -if(Octave_Interpreter_FOUND) - if(NOT TARGET Octave::Interpreter) - add_executable(Octave::Interpreter IMPORTED) - set_target_properties(Octave::Interpreter PROPERTIES - IMPORTED_LOCATION ${Octave_EXECUTABLE} - VERSION ${Octave_VERSION}) - endif() -endif() - -mark_as_advanced( - Octave_CONFIG_EXECUTABLE - Octave_INTERP_LIBRARY - Octave_OCTAVE_LIBRARY - Octave_INCLUDE_DIR - Octave_VERSION_MAJOR - Octave_VERSION_MINOR - Octave_VERSION_PATCH -) diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 7e37212..5a34b9e 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -96,7 +96,6 @@ function(_OPENMP_FLAG_CANDIDATES LANG) else() set(OMP_FLAG_Intel "-qopenmp") endif() - set(OMP_FLAG_MIPSpro "-mp") set(OMP_FLAG_MSVC "-openmp") set(OMP_FLAG_PathScale "-openmp") set(OMP_FLAG_NAG "-openmp") diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index 5d894c8..919392a 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -118,16 +118,8 @@ if(CMAKE_HAVE_PTHREAD_H) set(CMAKE_HAVE_THREADS_LIBRARY) if(NOT THREADS_HAVE_PTHREAD_ARG) # Check if pthread functions are in normal C library. - # If the pthread functions already exist in C library, we could just use - # them instead of linking to the additional pthread library. We could - # try to check any pthread symbol name, but here is an exception. If we - # use clang asan build, we will find the pthread_create() symbol in the - # libc(libasan). However, it doesn't have the full pthread implementation. - # So, we can't assume that we have the pthread implementation in libc - # using the pthread_create() checking here. Then, we turn to check the - # pthread_kill() symbol instead. - CHECK_SYMBOL_EXISTS(pthread_kill pthread.h CMAKE_HAVE_LIBC_PTHREAD_KILL) - if(CMAKE_HAVE_LIBC_PTHREAD_KILL) + CHECK_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE) + if(CMAKE_HAVE_LIBC_CREATE) set(CMAKE_THREAD_LIBS_INIT "") set(CMAKE_HAVE_THREADS_LIBRARY 1) set(Threads_FOUND TRUE) @@ -152,7 +144,7 @@ if(CMAKE_HAVE_PTHREAD_H) _check_pthreads_flag() endif() -if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_PTHREAD_KILL) +if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE) set(CMAKE_USE_PTHREADS_INIT 1) set(Threads_FOUND TRUE) endif() diff --git a/Modules/FortranCInterface/CMakeLists.txt b/Modules/FortranCInterface/CMakeLists.txt index e3b81d7..381080b 100644 --- a/Modules/FortranCInterface/CMakeLists.txt +++ b/Modules/FortranCInterface/CMakeLists.txt @@ -15,11 +15,11 @@ int main() { return 0; } # List manglings of global symbol names to try. set(global_symbols my_sub # VisualAge - my_sub_ # GNU, Intel, HP, SunPro, MIPSpro, PGI + my_sub_ # GNU, Intel, HP, SunPro, PGI my_sub__ # GNU g77 MY_SUB # Intel on Windows mysub # VisualAge - mysub_ # GNU, Intel, HP, SunPro, MIPSpro, PGI + mysub_ # GNU, Intel, HP, SunPro, PGI MYSUB # Intel on Windows ${FortranCInterface_GLOBAL_SYMBOLS} ) @@ -48,7 +48,6 @@ set(module_symbols list(REMOVE_DUPLICATES module_symbols) # Note that some compiler manglings cannot be invoked from C: -# MIPSpro uses "MY_SUB.in.MY_MODULE" # SunPro uses "my_module.my_sub_" # PathScale uses "MY_SUB.in.MY_MODULE" diff --git a/Modules/Internal/CPack/CPackRPM.cmake b/Modules/Internal/CPack/CPackRPM.cmake index 2de71ee..26b2517 100644 --- a/Modules/Internal/CPack/CPackRPM.cmake +++ b/Modules/Internal/CPack/CPackRPM.cmake @@ -63,6 +63,11 @@ function(get_unix_permissions_octal_notation PERMISSIONS_VAR RETURN_VAR) set(${RETURN_VAR} "${OWNER_PERMISSIONS}${GROUP_PERMISSIONS}${WORLD_PERMISSIONS}" PARENT_SCOPE) endfunction() +function(cpack_rpm_exact_regex regex_var string) + string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" regex "${string}") + set("${regex_var}" "${regex}" PARENT_SCOPE) +endfunction() + function(cpack_rpm_prepare_relocation_paths) # set appropriate prefix, remove possible trailing slash and convert backslashes to slashes if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX) @@ -482,7 +487,9 @@ function(cpack_rpm_prepare_install_files INSTALL_FILES_LIST WDIR PACKAGE_PREFIXE # recalculate path length after conversion to canonical form string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_) - if(SYMLINK_POINT_ MATCHES "${WDIR}/.*") + cpack_rpm_exact_regex(IN_SYMLINK_POINT_REGEX "${WDIR}") + string(APPEND IN_SYMLINK_POINT_REGEX "/.*") + if(SYMLINK_POINT_ MATCHES "${IN_SYMLINK_POINT_REGEX}") # only symlinks that are pointing inside the packaging structure should be checked for relocation string(SUBSTRING "${SYMLINK_POINT_}" ${WDR_LEN_} -1 SYMLINK_POINT_WD_) cpack_rpm_symlink_get_relocation_prefixes("${F}" "${PACKAGE_PREFIXES}" "SYMLINK_RELOCATIONS") diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake index b3078ff..06a806b 100644 --- a/Modules/Platform/AIX-XL.cmake +++ b/Modules/Platform/AIX-XL.cmake @@ -25,4 +25,26 @@ macro(__aix_compiler_xl lang) set(CMAKE_SHARED_MODULE_${lang}_FLAGS " ") set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath") + + # Find the CreateExportList program that comes with this toolchain. + find_program(CMAKE_XL_CreateExportList + NAMES CreateExportList + DOC "IBM XL CreateExportList tool" + ) + + # CMAKE_XL_CreateExportList is part of the AIX XL compilers but not the linux ones. + # If we found the tool, we'll use it to create exports, otherwise stick with the regular + # create shared library compile line. + if (CMAKE_XL_CreateExportList) + # The compiler front-end passes all object files, archive files, and shared + # library files named on the command line to CreateExportList to create a + # list of all symbols to be exported from the shared library. This causes + # all archive members to be copied into the shared library whether they are + # needed or not. Instead we run the tool ourselves to pass only the object + # files so that we export only the symbols actually provided by the sources. + set(CMAKE_${lang}_CREATE_SHARED_LIBRARY + "${CMAKE_XL_CreateExportList} <OBJECT_DIR>/objects.exp <OBJECTS>" + "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> -Wl,-bE:<OBJECT_DIR>/objects.exp <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" + ) + endif() endmacro() diff --git a/Modules/Platform/AIX-XLClang-C.cmake b/Modules/Platform/AIX-XLClang-C.cmake new file mode 100644 index 0000000..f0bedc5 --- /dev/null +++ b/Modules/Platform/AIX-XLClang-C.cmake @@ -0,0 +1,2 @@ +include(Platform/AIX-XLClang) +__aix_compiler_xlclang(C) diff --git a/Modules/Platform/AIX-XLClang-CXX.cmake b/Modules/Platform/AIX-XLClang-CXX.cmake new file mode 100644 index 0000000..cceb576 --- /dev/null +++ b/Modules/Platform/AIX-XLClang-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/AIX-XLClang) +__aix_compiler_xlclang(CXX) diff --git a/Modules/Platform/AIX-XLClang.cmake b/Modules/Platform/AIX-XLClang.cmake new file mode 100644 index 0000000..c932095 --- /dev/null +++ b/Modules/Platform/AIX-XLClang.cmake @@ -0,0 +1,15 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +# This module is shared by multiple languages; use include blocker. +if(__AIX_COMPILER_XLCLANG) + return() +endif() +set(__AIX_COMPILER_XLCLANG 1) + +include(Platform/AIX-XL) + +macro(__aix_compiler_xlclang lang) + __aix_compiler_xl(${lang}) +endmacro() diff --git a/Modules/Platform/CrayLinuxEnvironment.cmake b/Modules/Platform/CrayLinuxEnvironment.cmake index a1a3d3f..f2aaf3f 100644 --- a/Modules/Platform/CrayLinuxEnvironment.cmake +++ b/Modules/Platform/CrayLinuxEnvironment.cmake @@ -1,6 +1,5 @@ -# Compute Node Linux doesn't quite work the same as native Linux so all of this -# needs to be custom. We use the variables defined through Cray's environment -# modules to set up the right paths for things. +# CrayLinuxEnvironment: loaded by users cross-compiling on a Cray front-end +# node by specifying "-DCMAKE_SYSTEM_NAME=CrayLinuxEnvironment" to cmake set(UNIX 1) @@ -30,13 +29,6 @@ endif() # Note: this may need to change in the future with 64-bit ARM set(CMAKE_SYSTEM_PROCESSOR "x86_64") -set(CMAKE_SHARED_LIBRARY_PREFIX "lib") -set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") -set(CMAKE_STATIC_LIBRARY_PREFIX "lib") -set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") - -set(CMAKE_FIND_LIBRARY_PREFIXES "lib") - # Don't override shared lib support if it's already been set and possibly # overridden elsewhere by the CrayPrgEnv module if(NOT CMAKE_FIND_LIBRARY_SUFFIXES) @@ -44,12 +36,9 @@ if(NOT CMAKE_FIND_LIBRARY_SUFFIXES) set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) endif() -set(CMAKE_DL_LIBS dl) +# The rest of this file is based on UnixPaths.cmake, adjusted for Cray -# Note: Much of this is pulled from UnixPaths.cmake but adjusted to the Cray -# environment accordingly - -# Get the install directory of the running cmake to the search directories +# add the install directory of the running cmake to the search directories # CMAKE_ROOT is CMAKE_INSTALL_PREFIX/share/cmake, so we need to go two levels up get_filename_component(__cmake_install_dir "${CMAKE_ROOT}" PATH) get_filename_component(__cmake_install_dir "${__cmake_install_dir}" PATH) @@ -81,7 +70,6 @@ if (NOT CMAKE_FIND_NO_INSTALL_PREFIX) endif() list(APPEND CMAKE_SYSTEM_INCLUDE_PATH - $ENV{SYSROOT_DIR}/usr/include $ENV{SYSROOT_DIR}/usr/include/X11 ) list(APPEND CMAKE_SYSTEM_LIBRARY_PATH @@ -95,57 +83,5 @@ list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES $ENV{SYSROOT_DIR}/lib64 ) -# Compute the intersection of several lists -function(__cray_list_intersect OUTPUT INPUT0) - if(ARGC EQUAL 2) - list(APPEND ${OUTPUT} ${${INPUT0}}) - else() - foreach(I IN LISTS ${INPUT0}) - set(__is_common 1) - foreach(L IN LISTS ARGN) - list(FIND ${L} "${I}" __idx) - if(__idx EQUAL -1) - set(__is_common 0) - break() - endif() - endforeach() - if(__is_common) - list(APPEND ${OUTPUT} "${I}") - endif() - endforeach() - endif() - set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE) -endfunction() - -macro(__list_clean_dupes var) - if(${var}) - list(REMOVE_DUPLICATES ${var}) - endif() -endmacro() - -get_property(__langs GLOBAL PROPERTY ENABLED_LANGUAGES) -set(__cray_inc_path_vars) -set(__cray_lib_path_vars) -foreach(__lang IN LISTS __langs) - list(APPEND __cray_inc_path_vars CMAKE_${__lang}_IMPLICIT_INCLUDE_DIRECTORIES) - list(APPEND __cray_lib_path_vars CMAKE_${__lang}_IMPLICIT_LINK_DIRECTORIES) -endforeach() -if(__cray_inc_path_vars) - __cray_list_intersect(__cray_implicit_include_dirs ${__cray_inc_path_vars}) - if(__cray_implicit_include_dirs) - list(INSERT CMAKE_SYSTEM_INCLUDE_PATH 0 ${__cray_implicit_include_dirs}) - endif() -endif() -if(__cray_lib_path_vars) - __cray_list_intersect(__cray_implicit_library_dirs ${__cray_lib_path_vars}) - if(__cray_implicit_library_dirs) - list(INSERT CMAKE_SYSTEM_LIBRARY_PATH 0 ${__cray_implicit_library_dirs}) - endif() -endif() -__list_clean_dupes(CMAKE_SYSTEM_PREFIX_PATH) -__list_clean_dupes(CMAKE_SYSTEM_INCLUDE_PATH) -__list_clean_dupes(CMAKE_SYSTEM_LIBRARY_PATH) -__list_clean_dupes(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES) - # Enable use of lib64 search path variants by default. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) diff --git a/Modules/Platform/UnixPaths.cmake b/Modules/Platform/UnixPaths.cmake index 46c24bb..97f744d 100644 --- a/Modules/Platform/UnixPaths.cmake +++ b/Modules/Platform/UnixPaths.cmake @@ -63,21 +63,29 @@ list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES /lib /lib32 /lib64 /usr/lib /usr/lib32 /usr/lib64 ) +if(CMAKE_SYSROOT_COMPILE) + set(_cmake_sysroot_compile "${CMAKE_SYSROOT_COMPILE}") +else() + set(_cmake_sysroot_compile "${CMAKE_SYSROOT}") +endif() + # Default per-language values. These may be later replaced after # parsing the implicit directory information from compiler output. set(_CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES_INIT ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES} - /usr/include + "${_cmake_sysroot_compile}/usr/include" ) set(_CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES_INIT ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} - /usr/include + "${_cmake_sysroot_compile}/usr/include" ) set(_CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES_INIT ${CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES} - /usr/include + "${_cmake_sysroot_compile}/usr/include" ) +unset(_cmake_sysroot_compile) + # Enable use of lib32 and lib64 search path variants by default. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) diff --git a/Modules/ProcessorCount.cmake b/Modules/ProcessorCount.cmake index e4b4e53..8c25256 100644 --- a/Modules/ProcessorCount.cmake +++ b/Modules/ProcessorCount.cmake @@ -70,6 +70,20 @@ function(ProcessorCount var) endif() if(NOT count) + # Linux (systems with nproc): + # Prefer nproc to getconf if available as getconf may return the host CPU count in Linux containers + find_program(ProcessorCount_cmd_nproc nproc) + mark_as_advanced(ProcessorCount_cmd_nproc) + if(ProcessorCount_cmd_nproc) + execute_process(COMMAND ${ProcessorCount_cmd_nproc} + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE count) + #message("ProcessorCount: trying nproc '${ProcessorCount_cmd_nproc}'") + endif() + endif() + + if(NOT count) # Linux (systems with getconf): find_program(ProcessorCount_cmd_getconf getconf) mark_as_advanced(ProcessorCount_cmd_getconf) @@ -57,21 +57,39 @@ You need to have a C++ compiler (supporting C++11) and a ``make`` installed. Run the ``bootstrap`` script you find in the source directory of CMake. You can use the ``--help`` option to see the supported options. You may use the ``--prefix=<install_prefix>`` option to specify a custom -installation directory for CMake. You can run the ``bootstrap`` script from -within the CMake source directory or any other build directory of your -choice. Once this has finished successfully, run ``make`` and -``make install``. In summary:: +installation directory for CMake. Once this has finished successfully, +run ``make`` and ``make install``. - $ ./bootstrap && make && sudo make install +For example, if you simply want to build and install CMake from source, +you can build directly in the source tree:: + + $ ./bootstrap && make && sudo make install + +Or, if you plan to develop CMake or otherwise run the test suite, create +a separate build tree:: + + $ mkdir cmake-build && cd cmake-build + $ ../cmake-source/bootstrap && make Windows ^^^^^^^ -You need to download and install a binary release of CMake in order to build -CMake. You can get these releases from the `CMake Download Page`_. Then -proceed with the instructions below. +There are two ways for building CMake under Windows: + +1. Compile with MSVC from VS 2015 or later. + You need to download and install a binary release of CMake. You can get + these releases from the `CMake Download Page`_. Then proceed with the + instructions below for `Building CMake with CMake`_. + +2. Bootstrap with MinGW under MSYS2. + Download and install `MSYS2`_. Then install the required build tools:: + + $ pacman -S --needed git base-devel mingw-w64-x86_64-gcc + + and bootstrap as above. .. _`CMake Download Page`: https://cmake.org/cmake/resources/software.html +.. _`MSYS2`: https://www.msys2.org/ Building CMake with CMake ------------------------- diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 1c06052..2db276d 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -92,7 +92,6 @@ include_directories( ${CMAKE_ZLIB_INCLUDES} ${CMAKE_EXPAT_INCLUDES} ${CMAKE_TAR_INCLUDES} - ${CMAKE_COMPRESS_INCLUDES} ${CMake_HAIKU_INCLUDE_DIRS} ) @@ -801,7 +800,7 @@ endforeach() add_library(CMakeLib ${SRCS}) target_link_libraries(CMakeLib cmsys ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES} - ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES} + ${CMAKE_TAR_LIBRARIES} ${CMAKE_CURL_LIBRARIES} ${CMAKE_JSONCPP_LIBRARIES} ${CMAKE_LIBUV_LIBRARIES} @@ -1060,9 +1059,6 @@ if(CPACK_ENABLE_FREEBSD_PKG AND FREEBSD_PKG_INCLUDE_DIRS AND FREEBSD_PKG_LIBRARI endif() if(APPLE) - add_executable(cmakexbuild cmakexbuild.cxx) - list(APPEND _tools cmakexbuild) - target_link_libraries(cmakexbuild CMakeLib) add_executable(OSXScriptLauncher CPack/OSXScriptLauncher.cxx) target_link_libraries(OSXScriptLauncher cmsys) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 88a4fa8..d9b54f1 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 14) -set(CMake_VERSION_PATCH 0) -set(CMake_VERSION_RC 2) +set(CMake_VERSION_PATCH 20190301) +#set(CMake_VERSION_RC 1) diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index 9102e3e..c1b6eea 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -85,8 +85,8 @@ int cmCPackIFWGenerator::PackageFiles() int retVal = 1; cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl); bool res = cmSystemTools::RunSingleCommand( - ifwCmd.c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (!res || retVal) { cmGeneratedFileStream ofs(ifwTmpFile); ofs << "# Run command: " << ifwCmd << std::endl @@ -198,8 +198,8 @@ int cmCPackIFWGenerator::PackageFiles() int retVal = 1; cmCPackIFWLogger(OUTPUT, "- Generate package" << std::endl); bool res = cmSystemTools::RunSingleCommand( - ifwCmd.c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (!res || retVal) { cmGeneratedFileStream ofs(ifwTmpFile); ofs << "# Run command: " << ifwCmd << std::endl diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx index 4966d09..00d272c 100644 --- a/Source/CPack/OSXScriptLauncher.cxx +++ b/Source/CPack/OSXScriptLauncher.cxx @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) args.push_back(nullptr); cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*args.begin()); + cmsysProcess_SetCommand(cp, args.data()); cmsysProcess_SetWorkingDirectory(cp, scriptDirectory.c_str()); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); cmsysProcess_SetTimeout(cp, 0); diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index 398ebd3..045d93d 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -61,9 +61,8 @@ bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command) std::string output; int returnValue = 0; - bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output, - &output, &returnValue, 0, - cmSystemTools::OUTPUT_NONE); + bool status = cmSystemTools::RunSingleCommand( + command, &output, &output, &returnValue, 0, cmSystemTools::OUTPUT_NONE); cmsys::ofstream logFile(logFileName.c_str(), std::ios::app); logFile << command << std::endl; @@ -619,7 +618,7 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs"; - if (!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath.c_str())) { + if (!ConfigureFile(wixTemplate, mainSourceFilePath)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed creating '" << mainSourceFilePath << "'' from template." << std::endl); diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx index 2119f78..49a9f15 100644 --- a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx +++ b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx @@ -44,10 +44,9 @@ int cmCPackCygwinBinaryGenerator::PackageFiles() // to create the file before the super class is called { cmGeneratedFileStream ofs(manifestFile.c_str()); - for (std::vector<std::string>::const_iterator i = files.begin(); - i != files.end(); ++i) { + for (std::string const& file : files) { // remove the temp dir and replace with /usr - ofs << (*i).substr(tempdir.size()) << "\n"; + ofs << file.substr(tempdir.size()) << "\n"; } ofs << manifest << "\n"; } diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 013ad81..7a3742b 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -244,8 +244,8 @@ bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command, int exit_code = 1; bool result = cmSystemTools::RunSingleCommand( - command.str().c_str(), output, output, &exit_code, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + command.str(), output, output, &exit_code, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (!result || exit_code) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 57c0545..127bcf9 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -43,7 +43,8 @@ cmCPackGenerator::~cmCPackGenerator() this->MakefileMap = nullptr; } -void cmCPackGenerator::DisplayVerboseOutput(const char* msg, float progress) +void cmCPackGenerator::DisplayVerboseOutput(const std::string& msg, + float progress) { (void)progress; cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl); @@ -278,7 +279,7 @@ int cmCPackGenerator::InstallProjectViaInstallCommands( std::string output; int retVal = 1; bool resB = cmSystemTools::RunSingleCommand( - ic.c_str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose, + ic, &output, &output, &retVal, nullptr, this->GeneratorVerbose, cmDuration::zero()); if (!resB || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); @@ -387,8 +388,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } /* If it is not a symlink then do a plain copy */ else if (!(cmSystemTools::CopyFileIfDifferent(inFile, filePath) && - cmSystemTools::CopyFileTime(inFile.c_str(), - filePath.c_str()))) { + cmSystemTools::CopyFileTime(inFile, filePath))) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: " << inFile << " -> " << filePath << std::endl); @@ -647,8 +647,8 @@ int cmCPackGenerator::RunPreinstallTarget( std::string output; int retVal = 1; bool resB = cmSystemTools::RunSingleCommand( - buildCommand.c_str(), &output, &output, &retVal, - installDirectory.c_str(), this->GeneratorVerbose, cmDuration::zero()); + buildCommand, &output, &output, &retVal, installDirectory.c_str(), + this->GeneratorVerbose, cmDuration::zero()); if (!resB || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/PreinstallOutput.log"; @@ -689,7 +689,7 @@ int cmCPackGenerator::InstallCMakeProject( cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cm.AddCMakePaths(); - cm.SetProgressCallback([this](const char* msg, float prog) { + cm.SetProgressCallback([this](const std::string& msg, float prog) { this->DisplayVerboseOutput(msg, prog); }); cm.SetTrace(this->Trace); @@ -1245,7 +1245,8 @@ bool cmCPackGenerator::ConfigureString(const std::string& inString, return true; } -bool cmCPackGenerator::ConfigureFile(const char* inName, const char* outName, +bool cmCPackGenerator::ConfigureFile(const std::string& inName, + const std::string& outName, bool copyOnly /* = false */) { return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true, @@ -1254,9 +1255,8 @@ bool cmCPackGenerator::ConfigureFile(const char* inName, const char* outName, int cmCPackGenerator::CleanTemporaryDirectory() { - std::string tempInstallDirectoryWithPostfix = + std::string tempInstallDirectory = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); - const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str(); if (cmsys::SystemTools::FileExists(tempInstallDirectory)) { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Clean temporary : " << tempInstallDirectory << std::endl); diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h index 4755f94..3c06d41 100644 --- a/Source/CPack/cmCPackGenerator.h +++ b/Source/CPack/cmCPackGenerator.h @@ -96,7 +96,7 @@ public: void SetLogger(cmCPackLog* log) { this->Logger = log; } //! Display verbose information via logger - void DisplayVerboseOutput(const char* msg, float progress); + void DisplayVerboseOutput(const std::string& msg, float progress); bool ReadListFile(const char* moduleName); @@ -169,7 +169,8 @@ protected: virtual const char* GetPackagingInstallPrefix(); virtual std::string FindTemplate(const char* name); - virtual bool ConfigureFile(const char* inName, const char* outName, + virtual bool ConfigureFile(const std::string& inName, + const std::string& outName, bool copyOnly = false); virtual bool ConfigureString(const std::string& input, std::string& output); virtual int InitializeInternal(); diff --git a/Source/CPack/cmCPackGeneratorFactory.h b/Source/CPack/cmCPackGeneratorFactory.h index 7f633e4..972f0f7 100644 --- a/Source/CPack/cmCPackGeneratorFactory.h +++ b/Source/CPack/cmCPackGeneratorFactory.h @@ -22,6 +22,9 @@ public: cmCPackGeneratorFactory(); ~cmCPackGeneratorFactory(); + cmCPackGeneratorFactory(const cmCPackGeneratorFactory&) = delete; + cmCPackGeneratorFactory& operator=(const cmCPackGeneratorFactory&) = delete; + //! Get the generator cmCPackGenerator* NewGenerator(const std::string& name); void DeleteGenerator(cmCPackGenerator* gen); diff --git a/Source/CPack/cmCPackLog.h b/Source/CPack/cmCPackLog.h index 8e99221..65281e3 100644 --- a/Source/CPack/cmCPackLog.h +++ b/Source/CPack/cmCPackLog.h @@ -26,6 +26,9 @@ public: cmCPackLog(); ~cmCPackLog(); + cmCPackLog(const cmCPackLog&) = delete; + cmCPackLog& operator=(const cmCPackLog&) = delete; + enum __log_tags { NOTAG = 0, diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 37ea66e..6afd7d5 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -292,9 +292,8 @@ int cmCPackNSISGenerator::PackageFiles() this->SetOption("CPACK_NSIS_DEFINES", defines.c_str()); } - this->ConfigureFile(nsisInInstallOptions.c_str(), - nsisInstallOptions.c_str()); - this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str()); + this->ConfigureFile(nsisInInstallOptions, nsisInstallOptions); + this->ConfigureFile(nsisInFileName, nsisFileName); std::string nsisCmd = "\""; nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM"); nsisCmd += "\" \"" + nsisFileName + "\""; @@ -302,8 +301,8 @@ int cmCPackNSISGenerator::PackageFiles() std::string output; int retVal = 1; bool res = cmSystemTools::RunSingleCommand( - nsisCmd.c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + nsisCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile); ofs << "# Run command: " << nsisCmd << std::endl @@ -407,8 +406,8 @@ int cmCPackNSISGenerator::InitializeInternal() std::string output; int retVal = 1; bool resS = cmSystemTools::RunSingleCommand( - nsisCmd.c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + nsisCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)"); cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs"); if (!resS || retVal || @@ -749,7 +748,7 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( std::string output; int retVal = -1; int res = cmSystemTools::RunSingleCommand( - cmd.c_str(), &output, &output, &retVal, dirName.c_str(), + cmd, &output, &output, &retVal, dirName.c_str(), cmSystemTools::OUTPUT_NONE, cmDuration::zero()); if (!res || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx index 486633c..90e0afe 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -83,7 +83,7 @@ int cmCPackOSXX11Generator::PackageFiles() return 0; } std::string destFileName = resourcesDirectory + "/" + iconFileName; - this->ConfigureFile(iconFile, destFileName.c_str(), true); + this->ConfigureFile(iconFile, destFileName, true); this->SetOptionIfNotSet("CPACK_APPLE_GUI_ICON", iconFileName.c_str()); } @@ -155,8 +155,8 @@ int cmCPackOSXX11Generator::PackageFiles() bool res = false; while (numTries > 0) { res = cmSystemTools::RunSingleCommand( - dmgCmd.str().c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + dmgCmd.str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (res && !retVal) { numTries = -1; break; @@ -236,7 +236,7 @@ bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name) cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << (inFileName ? inFileName : "(NULL)") << " to " << destFileName << std::endl); - this->ConfigureFile(inFileName, destFileName.c_str()); + this->ConfigureFile(inFileName, destFileName); return true; } */ @@ -266,7 +266,7 @@ bool cmCPackOSXX11Generator::CopyResourcePlistFile( cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName << " to " << destFileName << std::endl); - this->ConfigureFile(inFileName.c_str(), destFileName.c_str(), copyOnly); + this->ConfigureFile(inFileName, destFileName, copyOnly); return true; } diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx index ae227aa..8c22c65 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -66,21 +66,17 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) xout.StartElement("choices-outline"); // Emit the outline for the groups - std::map<std::string, cmCPackComponentGroup>::iterator groupIt; - for (groupIt = this->ComponentGroups.begin(); - groupIt != this->ComponentGroups.end(); ++groupIt) { - if (groupIt->second.ParentGroup == nullptr) { - CreateChoiceOutline(groupIt->second, xout); + for (auto const& group : this->ComponentGroups) { + if (group.second.ParentGroup == nullptr) { + CreateChoiceOutline(group.second, xout); } } // Emit the outline for the non-grouped components - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { - if (!compIt->second.Group) { + for (auto const& comp : this->Components) { + if (!comp.second.Group) { xout.StartElement("line"); - xout.Attribute("choice", compIt->first + "Choice"); + xout.Attribute("choice", comp.first + "Choice"); xout.Content(""); // Avoid self-closing tag. xout.EndElement(); } @@ -94,13 +90,11 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) xout.EndElement(); // choices-outline> // Create the actual choices - for (groupIt = this->ComponentGroups.begin(); - groupIt != this->ComponentGroups.end(); ++groupIt) { - CreateChoice(groupIt->second, xout); + for (auto const& group : this->ComponentGroups) { + CreateChoice(group.second, xout); } - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { - CreateChoice(compIt->second, xout); + for (auto const& comp : this->Components) { + CreateChoice(comp.second, xout); } if (!this->PostFlightComponent.Name.empty()) { @@ -111,7 +105,7 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) // Create the distribution.dist file in the metapackage to turn it // into a distribution package. - this->ConfigureFile(distributionTemplate.c_str(), distributionFile.c_str()); + this->ConfigureFile(distributionTemplate, distributionFile); } void cmCPackPKGGenerator::CreateChoiceOutline( @@ -119,17 +113,13 @@ void cmCPackPKGGenerator::CreateChoiceOutline( { xout.StartElement("line"); xout.Attribute("choice", group.Name + "Choice"); - std::vector<cmCPackComponentGroup*>::const_iterator groupIt; - for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end(); - ++groupIt) { - CreateChoiceOutline(**groupIt, xout); + for (cmCPackComponentGroup* subgroup : group.Subgroups) { + CreateChoiceOutline(*subgroup, xout); } - std::vector<cmCPackComponent*>::const_iterator compIt; - for (compIt = group.Components.begin(); compIt != group.Components.end(); - ++compIt) { + for (cmCPackComponent* comp : group.Components) { xout.StartElement("line"); - xout.Attribute("choice", (*compIt)->Name + "Choice"); + xout.Attribute("choice", comp->Name + "Choice"); xout.Content(""); // Avoid self-closing tag. xout.EndElement(); } @@ -238,11 +228,9 @@ void cmCPackPKGGenerator::AddDependencyAttributes( } visited.insert(&component); - std::vector<cmCPackComponent*>::const_iterator dependIt; - for (dependIt = component.Dependencies.begin(); - dependIt != component.Dependencies.end(); ++dependIt) { - out << " && choices['" << (*dependIt)->Name << "Choice'].selected"; - AddDependencyAttributes(**dependIt, visited, out); + for (cmCPackComponent* depend : component.Dependencies) { + out << " && choices['" << depend->Name << "Choice'].selected"; + AddDependencyAttributes(*depend, visited, out); } } @@ -255,11 +243,9 @@ void cmCPackPKGGenerator::AddReverseDependencyAttributes( } visited.insert(&component); - std::vector<cmCPackComponent*>::const_iterator dependIt; - for (dependIt = component.ReverseDependencies.begin(); - dependIt != component.ReverseDependencies.end(); ++dependIt) { - out << " || choices['" << (*dependIt)->Name << "Choice'].selected"; - AddReverseDependencyAttributes(**dependIt, visited, out); + for (cmCPackComponent* depend : component.ReverseDependencies) { + out << " || choices['" << depend->Name << "Choice'].selected"; + AddReverseDependencyAttributes(*depend, visited, out); } } @@ -308,7 +294,7 @@ bool cmCPackPKGGenerator::CopyCreateResourceFile(const std::string& name, cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << (inFileName ? inFileName : "(NULL)") << " to " << destFileName << std::endl); - this->ConfigureFile(inFileName, destFileName.c_str()); + this->ConfigureFile(inFileName, destFileName); return true; } @@ -336,7 +322,7 @@ bool cmCPackPKGGenerator::CopyResourcePlistFile(const std::string& name, cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName << " to " << destFileName << std::endl); - this->ConfigureFile(inFileName.c_str(), destFileName.c_str()); + this->ConfigureFile(inFileName, destFileName); return true; } diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 246178d..3d93c48 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -295,8 +295,8 @@ int cmCPackPackageMakerGenerator::PackageFiles() bool res = false; while (numTries > 0) { res = cmSystemTools::RunSingleCommand( - dmgCmd.str().c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + dmgCmd.str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (res && !retVal) { numTries = -1; break; diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx index a556e0c..94b5b5f 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.cxx +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -145,8 +145,8 @@ bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command) std::string output; int retVal = 1; bool res = cmSystemTools::RunSingleCommand( - command.c_str(), &output, &output, &retVal, nullptr, - this->GeneratorVerbose, cmDuration::zero()); + command, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" << std::endl); if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile); diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 0413422..da9575b 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -90,7 +90,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue, return 1; } -static void cpackProgressCallback(const char* message, float /*unused*/) +static void cpackProgressCallback(const std::string& message, float /*unused*/) { std::cout << "-- " << message << std::endl; } diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index b154caf..83aeb64 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -365,7 +365,7 @@ bool cmCTestBZR::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions"); } - std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); // TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY) diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 2fd4c7a..b2c88df 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -118,7 +118,7 @@ public: : CM(cm) { cmSystemTools::SetMessageCallback( - [&s](const char* msg, const char* /*unused*/) { + [&s](const std::string& msg, const char* /*unused*/) { s += msg; s += "\n"; }); @@ -126,10 +126,11 @@ public: cmSystemTools::SetStdoutCallback([&s](std::string const& m) { s += m; }); cmSystemTools::SetStderrCallback([&s](std::string const& m) { s += m; }); - this->CM.SetProgressCallback([&s](const char* msg, float /*unused*/) { - s += msg; - s += "\n"; - }); + this->CM.SetProgressCallback( + [&s](const std::string& msg, float /*unused*/) { + s += msg; + s += "\n"; + }); } ~cmCTestBuildAndTestCaptureRAII() @@ -139,6 +140,11 @@ public: cmSystemTools::SetStdoutCallback(nullptr); cmSystemTools::SetMessageCallback(nullptr); } + + cmCTestBuildAndTestCaptureRAII(const cmCTestBuildAndTestCaptureRAII&) = + delete; + cmCTestBuildAndTestCaptureRAII& operator=( + const cmCTestBuildAndTestCaptureRAII&) = delete; }; int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index d934c00..07bc7e7 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -418,8 +418,8 @@ int cmCTestBuildHandler::ProcessHandler() int retVal = 0; int res = cmsysProcess_State_Exited; if (!this->CTest->GetShowOnly()) { - res = this->RunMakeCommand(makeCommand.c_str(), &retVal, - buildDirectory.c_str(), 0, ofs); + res = this->RunMakeCommand(makeCommand, &retVal, buildDirectory.c_str(), 0, + ofs); } else { cmCTestOptionalLog(this->CTest, DEBUG, "Build with command: " << makeCommand << std::endl, @@ -680,6 +680,8 @@ class cmCTestBuildHandler::LaunchHelper public: LaunchHelper(cmCTestBuildHandler* handler); ~LaunchHelper(); + LaunchHelper(const LaunchHelper&) = delete; + LaunchHelper& operator=(const LaunchHelper&) = delete; private: cmCTestBuildHandler* Handler; @@ -764,9 +766,10 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers( } } -int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, - const char* dir, int timeout, - std::ostream& ofs, Encoding encoding) +int cmCTestBuildHandler::RunMakeCommand(const std::string& command, + int* retVal, const char* dir, + int timeout, std::ostream& ofs, + Encoding encoding) { // First generate the command and arguments std::vector<std::string> args = cmSystemTools::ParseArguments(command); @@ -800,7 +803,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, // Now create process object cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_SetCommand(cp, argv.data()); cmsysProcess_SetWorkingDirectory(cp, dir); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); cmsysProcess_SetTimeout(cp, timeout); @@ -978,7 +981,7 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length, this->CurrentProcessingLine.insert(this->CurrentProcessingLine.end(), queue->begin(), it); this->CurrentProcessingLine.push_back(0); - const char* line = &*this->CurrentProcessingLine.begin(); + const char* line = this->CurrentProcessingLine.data(); // Process the line int lineType = this->ProcessSingleLine(line); diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h index a9b121b..722c590 100644 --- a/Source/CTest/cmCTestBuildHandler.h +++ b/Source/CTest/cmCTestBuildHandler.h @@ -52,7 +52,7 @@ private: //! Run command specialized for make and configure. Returns process status // and retVal is return value or exception. - int RunMakeCommand(const char* command, int* retVal, const char* dir, + int RunMakeCommand(const std::string& command, int* retVal, const char* dir, int timeout, std::ostream& ofs, Encoding encoding = cmProcessOutput::Auto); diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index 6e8f73f..9c03839 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -78,7 +78,7 @@ bool cmCTestCVS::UpdateImpl() opts = "-dP"; } } - std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); // Specify the start time for nightly testing. if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) { diff --git a/Source/CTest/cmCTestConfigureHandler.cxx b/Source/CTest/cmCTestConfigureHandler.cxx index 6b7601b..7e93189 100644 --- a/Source/CTest/cmCTestConfigureHandler.cxx +++ b/Source/CTest/cmCTestConfigureHandler.cxx @@ -61,7 +61,7 @@ int cmCTestConfigureHandler::ProcessHandler() cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: " << cCommand << std::endl, this->Quiet); - res = this->CTest->RunMakeCommand(cCommand.c_str(), output, &retVal, + res = this->CTest->RunMakeCommand(cCommand, output, &retVal, buildDirectory.c_str(), cmDuration::zero(), ofs); diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 225383c..d76bd2a 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -52,6 +52,8 @@ public: } cmsysProcess_Delete(this->Process); } + cmCTestRunProcess(const cmCTestRunProcess&) = delete; + cmCTestRunProcess& operator=(const cmCTestRunProcess&) = delete; void SetCommand(const char* command) { this->CommandLineStrings.clear(); @@ -72,7 +74,7 @@ public: args.push_back(cl.c_str()); } args.push_back(nullptr); // null terminate - cmsysProcess_SetCommand(this->Process, &*args.begin()); + cmsysProcess_SetCommand(this->Process, args.data()); if (!this->WorkingDirectory.empty()) { cmsysProcess_SetWorkingDirectory(this->Process, this->WorkingDirectory.c_str()); @@ -223,7 +225,7 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file, checkDir = fBinDir; } std::string ndc = cmSystemTools::FileExistsInParentDirectories( - ".NoDartCoverage", fFile.c_str(), checkDir.c_str()); + ".NoDartCoverage", fFile, checkDir); if (!ndc.empty()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc << " so skip coverage of " << file @@ -254,8 +256,8 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file, return true; } - ndc = cmSystemTools::FileExistsInParentDirectories( - ".NoDartCoverage", fFile.c_str(), checkDir.c_str()); + ndc = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage", fFile, + checkDir); if (!ndc.empty()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found: " << ndc << " so skip coverage of: " << file @@ -786,6 +788,9 @@ struct cmCTestCoverageHandlerLocale cmSystemTools::UnsetEnv("LC_ALL"); } } + cmCTestCoverageHandlerLocale(const cmCTestCoverageHandlerLocale&) = delete; + cmCTestCoverageHandlerLocale& operator=( + const cmCTestCoverageHandlerLocale&) = delete; std::string lc_all; }; @@ -999,7 +1004,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( static_cast<void>(locale_C); std::vector<std::string> basecovargs = - cmSystemTools::ParseArguments(gcovExtraFlags.c_str()); + cmSystemTools::ParseArguments(gcovExtraFlags); basecovargs.insert(basecovargs.begin(), gcovCommand); basecovargs.emplace_back("-o"); @@ -1058,8 +1063,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( this->Quiet); std::vector<std::string> lines; - - cmSystemTools::Split(output.c_str(), lines); + cmsys::SystemTools::Split(output, lines); for (std::string const& line : lines) { std::string sourceFile; @@ -1373,7 +1377,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( static_cast<void>(locale_C); std::vector<std::string> covargs = - cmSystemTools::ParseArguments(lcovExtraFlags.c_str()); + cmSystemTools::ParseArguments(lcovExtraFlags); covargs.insert(covargs.begin(), lcovCommand); const std::string command = joinCommandLine(covargs); @@ -1435,8 +1439,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( this->Quiet); std::vector<std::string> lines; - - cmSystemTools::Split(output.c_str(), lines); + cmsys::SystemTools::Split(output, lines); for (std::string const& line : lines) { std::string sourceFile; diff --git a/Source/CTest/cmCTestCurl.h b/Source/CTest/cmCTestCurl.h index 86d9489..6186af8 100644 --- a/Source/CTest/cmCTestCurl.h +++ b/Source/CTest/cmCTestCurl.h @@ -16,6 +16,8 @@ class cmCTestCurl public: cmCTestCurl(cmCTest*); ~cmCTestCurl(); + cmCTestCurl(const cmCTestCurl&) = delete; + cmCTestCurl& operator=(const cmCTestCurl&) = delete; bool UploadFile(std::string const& local_file, std::string const& url, std::string const& fields, std::string& response); bool HttpRequest(std::string const& url, std::string const& fields, diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 210abe5..11cd005 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -162,7 +162,7 @@ bool cmCTestGIT::UpdateByFetchAndReset() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("GITUpdateOptions"); } - std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); for (std::string const& arg : args) { git_fetch.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx index 6fb99d8..727c59c 100644 --- a/Source/CTest/cmCTestHG.cxx +++ b/Source/CTest/cmCTestHG.cxx @@ -144,7 +144,7 @@ bool cmCTestHG::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("HGUpdateOptions"); } - std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); for (std::string const& arg : args) { hg_update.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index 57a14ef..adf9553 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -76,6 +76,8 @@ public: } } } + SaveRestoreErrorState(const SaveRestoreErrorState&) = delete; + SaveRestoreErrorState& operator=(const SaveRestoreErrorState&) = delete; private: bool InitialErrorState; diff --git a/Source/CTest/cmCTestLaunch.h b/Source/CTest/cmCTestLaunch.h index debbe59..107fd61 100644 --- a/Source/CTest/cmCTestLaunch.h +++ b/Source/CTest/cmCTestLaunch.h @@ -28,6 +28,9 @@ private: cmCTestLaunch(int argc, const char* const* argv); ~cmCTestLaunch(); + cmCTestLaunch(const cmCTestLaunch&) = delete; + cmCTestLaunch& operator=(const cmCTestLaunch&) = delete; + // Run the real command. int Run(); void RunChild(); diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 8ba59d3..22c8469 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -520,7 +520,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() this->CTest->GetCTestConfiguration("ValgrindCommandOptions"); } this->MemoryTesterOptions = - cmSystemTools::ParseArguments(memoryTesterOptions.c_str()); + cmSystemTools::ParseArguments(memoryTesterOptions); this->MemoryTesterOutputFile = this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log"; @@ -725,7 +725,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput( cmsys::RegularExpression leakWarning("(Direct|Indirect) leak of .*"); int defects = 0; std::vector<std::string> lines; - cmSystemTools::Split(str.c_str(), lines); + cmsys::SystemTools::Split(str, lines); std::ostringstream ostr; log.clear(); for (std::string const& l : lines) { @@ -755,7 +755,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( const std::string& str, std::string& log, std::vector<int>& results) { std::vector<std::string> lines; - cmSystemTools::Split(str.c_str(), lines); + cmsys::SystemTools::Split(str, lines); std::ostringstream ostr; log.clear(); @@ -798,7 +798,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( const std::string& str, std::string& log, std::vector<int>& results) { std::vector<std::string> lines; - cmSystemTools::Split(str.c_str(), lines); + cmsys::SystemTools::Split(str, lines); bool unlimitedOutput = false; if (str.find("CTEST_FULL_OUTPUT") != std::string::npos || this->CustomMaximumFailedTestOutputSize == 0) { @@ -937,7 +937,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( log.clear(); auto sttime = std::chrono::steady_clock::now(); std::vector<std::string> lines; - cmSystemTools::Split(str.c_str(), lines); + cmsys::SystemTools::Split(str, lines); cmCTestOptionalLog(this->CTest, DEBUG, "Start test: " << lines.size() << std::endl, this->Quiet); std::vector<std::string>::size_type cc; diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 756ac6c..477161a 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -8,6 +8,7 @@ #include "cmCTestTestHandler.h" #include "cmDuration.h" #include "cmListFileCache.h" +#include "cmRange.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" @@ -108,8 +109,8 @@ void cmCTestMultiProcessHandler::SetTestLoad(unsigned long load) fake_load_value)) { if (!cmSystemTools::StringToULong(fake_load_value.c_str(), &this->FakeLoadForTesting)) { - cmSystemTools::Error("Failed to parse fake load value: ", - fake_load_value.c_str()); + cmSystemTools::Error("Failed to parse fake load value: " + + fake_load_value); } } } @@ -651,9 +652,7 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList() // Reverse iterate over the different dependency levels (deepest first). // Sort tests within each level by COST and append them to the cost list. - for (std::list<TestSet>::reverse_iterator i = priorityStack.rbegin(); - i != priorityStack.rend(); ++i) { - TestSet const& currentSet = *i; + for (TestSet const& currentSet : cmReverseRange(priorityStack)) { TestComparator comp(this); TestList sortedCopy; diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index 435be97..7adf640 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -5,6 +5,7 @@ #include "cmCTest.h" #include "cmCTestVC.h" #include "cmProcessTools.h" +#include "cmRange.h" #include "cmSystemTools.h" #include "cmsys/RegularExpression.hxx" @@ -323,8 +324,7 @@ void cmCTestP4::SetP4Options(std::vector<char const*>& CommandOptions) // The CTEST_P4_OPTIONS variable adds additional Perforce command line // options before the main command std::string opts = this->CTest->GetCTestConfiguration("P4Options"); - std::vector<std::string> args = - cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); P4Options.insert(P4Options.end(), args.begin(), args.end()); } @@ -425,12 +425,11 @@ bool cmCTestP4::LoadRevisions() // p4 describe -s ...@1111111,2222222 std::vector<char const*> p4_describe; - for (std::vector<std::string>::reverse_iterator i = ChangeLists.rbegin(); - i != ChangeLists.rend(); ++i) { + for (std::string const& i : cmReverseRange(ChangeLists)) { SetP4Options(p4_describe); p4_describe.push_back("describe"); p4_describe.push_back("-s"); - p4_describe.push_back(i->c_str()); + p4_describe.push_back(i.c_str()); p4_describe.push_back(nullptr); DescribeParser outDescribe(this, "p4_describe-out> "); @@ -501,7 +500,7 @@ bool cmCTestP4::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("P4UpdateOptions"); } - std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); for (std::string const& arg : args) { p4_sync.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 7f081ef..41d02c5 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -9,11 +9,10 @@ #include "cmSystemTools.h" #include "cmWorkingDirectory.h" -#include "cm_zlib.h" -#include "cmsys/Base64.h" #include "cmsys/RegularExpression.hxx" #include <chrono> #include <cmAlgorithms.h> +#include <cstdint> #include <cstring> #include <iomanip> #include <ratio> @@ -31,9 +30,6 @@ cmCTestRunTest::cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler) this->TestResult.Status = cmCTestTestHandler::NOT_RUN; this->TestResult.TestCount = 0; this->TestResult.Properties = nullptr; - this->ProcessOutput.clear(); - this->CompressedOutput.clear(); - this->CompressionRatio = 2; this->NumberOfRunsLeft = 1; // default to 1 run of the test this->RunUntilFail = false; // default to run the test once this->RunAgain = false; // default to not having to run again @@ -68,73 +64,8 @@ void cmCTestRunTest::CheckOutput(std::string const& line) } } -// Streamed compression of test output. The compressed data -// is appended to this->CompressedOutput -void cmCTestRunTest::CompressOutput() -{ - int ret; - z_stream strm; - - unsigned char* in = reinterpret_cast<unsigned char*>( - const_cast<char*>(this->ProcessOutput.c_str())); - // zlib makes the guarantee that this is the maximum output size - int outSize = static_cast<int>( - static_cast<double>(this->ProcessOutput.size()) * 1.001 + 13.0); - unsigned char* out = new unsigned char[outSize]; - - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = deflateInit(&strm, -1); // default compression level - if (ret != Z_OK) { - delete[] out; - return; - } - - strm.avail_in = static_cast<uInt>(this->ProcessOutput.size()); - strm.next_in = in; - strm.avail_out = outSize; - strm.next_out = out; - ret = deflate(&strm, Z_FINISH); - - if (ret != Z_STREAM_END) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error during output compression. Sending uncompressed output." - << std::endl); - delete[] out; - return; - } - - (void)deflateEnd(&strm); - - unsigned char* encoded_buffer = - new unsigned char[static_cast<int>(outSize * 1.5)]; - - size_t rlen = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1); - - this->CompressedOutput.clear(); - for (size_t i = 0; i < rlen; i++) { - this->CompressedOutput += encoded_buffer[i]; - } - - if (strm.total_in) { - this->CompressionRatio = - static_cast<double>(strm.total_out) / static_cast<double>(strm.total_in); - } - - delete[] encoded_buffer; - delete[] out; -} - bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) { - if ((!this->TestHandler->MemCheck && - this->CTest->ShouldCompressTestOutput()) || - (this->TestHandler->MemCheck && - this->CTest->ShouldCompressTestOutput())) { - this->CompressOutput(); - } - this->WriteLogOutputTop(completed, total); std::string reason; bool passed = true; @@ -143,7 +74,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) if (res != cmProcess::State::Expired) { this->TimeoutIsForStopTime = false; } - int retVal = this->TestProcess->GetExitValue(); + std::int64_t retVal = this->TestProcess->GetExitValue(); bool forceFail = false; bool skipped = false; bool outputTestErrorsToConsole = false; @@ -335,10 +266,18 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) // if the test actually started and ran // record the results in TestResult if (started) { - bool compress = !this->TestHandler->MemCheck && - this->CompressionRatio < 1 && this->CTest->ShouldCompressTestOutput(); + std::string compressedOutput; + if (!this->TestHandler->MemCheck && + this->CTest->ShouldCompressTestOutput()) { + std::string str = this->ProcessOutput; + if (this->CTest->CompressString(str)) { + compressedOutput = std::move(str); + } + } + bool compress = !compressedOutput.empty() && + compressedOutput.length() < this->ProcessOutput.length(); this->TestResult.Output = - compress ? this->CompressedOutput : this->ProcessOutput; + compress ? compressedOutput : this->ProcessOutput; this->TestResult.CompressOutput = compress; this->TestResult.ReturnValue = this->TestProcess->GetExitValue(); if (!skipped) { diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 918d5fa..38cc417 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -58,9 +58,6 @@ public: // Read and store output. Returns true if it must be called again. void CheckOutput(std::string const& line); - // Compresses the output, writing to CompressedOutput - void CompressOutput(); - // launch the test process, return whether it started correctly bool StartTest(size_t completed, size_t total); // capture and report the test results @@ -105,8 +102,6 @@ private: cmCTest* CTest; std::unique_ptr<cmProcess> TestProcess; std::string ProcessOutput; - std::string CompressedOutput; - double CompressionRatio; // The test results cmCTestTestHandler::cmCTestTestResult TestResult; cmCTestMultiProcessHandler& MultiTestHandler; diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index 3bf66ca..b7a4e4c 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -242,7 +242,7 @@ bool cmCTestSVN::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions"); } - std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector<std::string> args = cmSystemTools::ParseArguments(opts); // Specify the start time for nightly testing. if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) { @@ -277,7 +277,7 @@ bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters, std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions"); std::vector<std::string> parsedUserOptions = - cmSystemTools::ParseArguments(userOptions.c_str()); + cmSystemTools::ParseArguments(userOptions); for (std::string const& opt : parsedUserOptions) { args.push_back(opt.c_str()); } diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 33b8b4a..43cfe16 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -199,7 +199,7 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg) // Now create process object cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_SetCommand(cp, argv.data()); // cmsysProcess_SetWorkingDirectory(cp, dir); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); // cmsysProcess_SetTimeout(cp, timeout); @@ -288,11 +288,12 @@ void cmCTestScriptHandler::CreateCMake() this->ParentMakefile->GetRecursionDepth()); } - this->CMake->SetProgressCallback([this](const char* m, float /*unused*/) { - if (m && *m) { - cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl); - } - }); + this->CMake->SetProgressCallback( + [this](const std::string& m, float /*unused*/) { + if (!m.empty()) { + cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl); + } + }); this->AddCTestCommand("ctest_build", new cmCTestBuildCommand); this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand); @@ -330,7 +331,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) } // make sure the file exists if (!cmSystemTools::FileExists(script)) { - cmSystemTools::Error("Cannot find file: ", script.c_str()); + cmSystemTools::Error("Cannot find file: " + script); return 1; } @@ -470,8 +471,8 @@ int cmCTestScriptHandler::ExtractVariables() msg += "\nCTEST_COMMAND = "; msg += (!this->CTestCmd.empty()) ? this->CTestCmd.c_str() : "(Null)"; cmSystemTools::Error( - "Some required settings in the configuration file were missing:\n", - msg.c_str()); + "Some required settings in the configuration file were missing:\n" + + msg); return 4; } @@ -607,12 +608,10 @@ int cmCTestScriptHandler::CheckOutSourceDir() cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run cvs: " << this->CVSCheckOut << std::endl); res = cmSystemTools::RunSingleCommand( - this->CVSCheckOut.c_str(), &output, &output, &retVal, - this->CTestRoot.c_str(), this->HandlerVerbose, - cmDuration::zero() /*this->TimeOut*/); + this->CVSCheckOut, &output, &output, &retVal, this->CTestRoot.c_str(), + this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/); if (!res || retVal != 0) { - cmSystemTools::Error("Unable to perform cvs checkout:\n", - output.c_str()); + cmSystemTools::Error("Unable to perform cvs checkout:\n" + output); return 6; } } @@ -675,11 +674,11 @@ int cmCTestScriptHandler::PerformExtraUpdates() cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run Update: " << fullCommand << std::endl); res = cmSystemTools::RunSingleCommand( - fullCommand.c_str(), &output, &output, &retVal, cvsArgs[0].c_str(), + fullCommand, &output, &output, &retVal, cvsArgs[0].c_str(), this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/); if (!res || retVal != 0) { - cmSystemTools::Error("Unable to perform extra updates:\n", eu.c_str(), - "\nWith output:\n", output.c_str()); + cmSystemTools::Error("Unable to perform extra updates:\n" + eu + + "\nWith output:\n" + output); return 0; } } @@ -721,8 +720,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard() if (!cmSystemTools::FileExists(this->BinaryDir) && this->SourceDir != this->BinaryDir) { if (!cmSystemTools::MakeDirectory(this->BinaryDir)) { - cmSystemTools::Error("Unable to create the binary directory:\n", - this->BinaryDir.c_str()); + cmSystemTools::Error("Unable to create the binary directory:\n" + + this->BinaryDir); this->RestoreBackupDirectories(); return 7; } @@ -779,7 +778,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard() cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run cmake command: " << command << std::endl); res = cmSystemTools::RunSingleCommand( - command.c_str(), &output, &output, &retVal, this->BinaryDir.c_str(), + command, &output, &output, &retVal, this->BinaryDir.c_str(), this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/); if (!this->CMOutFile.empty()) { @@ -818,7 +817,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard() cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run ctest command: " << command << std::endl); res = cmSystemTools::RunSingleCommand( - command.c_str(), &output, &output, &retVal, this->BinaryDir.c_str(), + command, &output, &output, &retVal, this->BinaryDir.c_str(), this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/); // did something critical fail in ctest diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 87112da..1539635 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -343,7 +343,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( if (!chunk.empty()) { cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: [" - << cmCTestLogWrite(&*chunk.begin(), chunk.size()) + << cmCTestLogWrite(chunk.data(), chunk.size()) << "]" << std::endl, this->Quiet); this->ParseResponse(chunk); @@ -352,7 +352,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( cmCTestOptionalLog( this->CTest, DEBUG, "CURL debug output: [" - << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]" + << cmCTestLogWrite(chunkDebug.data(), chunkDebug.size()) << "]" << std::endl, this->Quiet); } @@ -404,12 +404,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( res = ::curl_easy_perform(curl); if (!chunk.empty()) { - cmCTestOptionalLog( - this->CTest, DEBUG, - "CURL output: [" - << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, + "CURL output: [" + << cmCTestLogWrite(chunk.data(), chunk.size()) + << "]" << std::endl, + this->Quiet); this->ParseResponse(chunk); } @@ -433,11 +432,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( // avoid deref of begin for zero size array if (!chunk.empty()) { *this->LogFile << " Curl output was: " - << cmCTestLogWrite(&*chunk.begin(), chunk.size()) + << cmCTestLogWrite(chunk.data(), chunk.size()) << std::endl; cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: [" - << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]" + << cmCTestLogWrite(chunk.data(), chunk.size()) << "]" << std::endl); } ::curl_easy_cleanup(curl); @@ -486,7 +485,7 @@ void cmCTestSubmitHandler::ParseResponse( if (this->HasWarnings || this->HasErrors) { cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n" - << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n"); + << cmCTestLogWrite(chunk.data(), chunk.size()) << "\n"); } } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index cf2652a..c9783e4 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1486,7 +1486,7 @@ int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec) int retVal = 0; cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << it << std::endl, this->Quiet); - if (!cmSystemTools::RunSingleCommand(it.c_str(), nullptr, nullptr, &retVal, + if (!cmSystemTools::RunSingleCommand(it, nullptr, nullptr, &retVal, nullptr, cmSystemTools::OUTPUT_MERGE /*this->Verbose*/) || retVal != 0) { diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 0b557db..17d5f3f 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -11,6 +11,7 @@ #include "cmsys/RegularExpression.hxx" #include <chrono> +#include <cstdint> #include <iosfwd> #include <map> #include <set> @@ -153,7 +154,7 @@ public: std::string Reason; std::string FullCommandLine; cmDuration ExecutionTime; - int ReturnValue; + std::int64_t ReturnValue; int Status; std::string ExceptionStatus; bool CompressOutput; diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index 70ef8df..cd2e2f7 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -11,7 +11,9 @@ #include <iostream> #include <signal.h> #include <string> -#if !defined(_WIN32) +#if defined(_WIN32) +# include "cm_kwiml.h" +#else # include <unistd.h> #endif #include <utility> @@ -199,7 +201,7 @@ bool cmProcess::Buffer::GetLine(std::string& line) for (size_type sz = this->size(); this->Last != sz; ++this->Last) { if ((*this)[this->Last] == '\n' || (*this)[this->Last] == '\0') { // Extract the range first..last as a line. - const char* text = &*this->begin() + this->First; + const char* text = this->data() + this->First; size_type length = this->Last - this->First; while (length && text[length - 1] == '\r') { length--; @@ -229,7 +231,7 @@ bool cmProcess::Buffer::GetLast(std::string& line) { // Return the partial last line, if any. if (!this->empty()) { - line.assign(&*this->begin(), this->size()); + line.assign(this->data(), this->size()); this->First = this->Last = 0; this->clear(); return true; @@ -353,7 +355,7 @@ void cmProcess::OnExit(int64_t exit_status, int term_signal) } // Record exit information. - this->ExitValue = static_cast<int>(exit_status); + this->ExitValue = exit_status; this->Signal = term_signal; this->TotalTime = std::chrono::steady_clock::now() - this->StartTime; // Because of a processor clock scew the runtime may become slightly @@ -539,7 +541,8 @@ std::string cmProcess::GetExitExceptionString() case STATUS_NO_MEMORY: default: char buf[1024]; - _snprintf(buf, 1024, "Exit code 0x%x\n", this->ExitValue); + const char* fmt = "Exit code 0x%" KWIML_INT_PRIx64 "\n"; + _snprintf(buf, 1024, fmt, this->ExitValue); exception_str.assign(buf); } #else diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index b2d87fa..e5ca17f 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -53,7 +53,7 @@ public: State GetProcessStatus(); int GetId() { return this->Id; } void SetId(int id) { this->Id = id; } - int GetExitValue() { return this->ExitValue; } + int64_t GetExitValue() { return this->ExitValue; } cmDuration GetTotalTime() { return this->TotalTime; } enum class Exception @@ -122,7 +122,7 @@ private: std::vector<std::string> Arguments; std::vector<const char*> ProcessArgs; int Id; - int ExitValue; + int64_t ExitValue; }; #endif diff --git a/Source/Checks/cm_cxx14_check.cpp b/Source/Checks/cm_cxx14_check.cpp index 9369ba2..fff36c9 100644 --- a/Source/Checks/cm_cxx14_check.cpp +++ b/Source/Checks/cm_cxx14_check.cpp @@ -1,8 +1,15 @@ #include <cstdio> +#include <iterator> #include <memory> int main() { + int a[] = { 0, 1, 2 }; + auto ai = std::cbegin(a); + + int b[] = { 2, 1, 0 }; + auto bi = std::cend(b); + std::unique_ptr<int> u(new int(0)); - return *u; + return *u + *ai + *(bi - 1); } diff --git a/Source/Checks/cm_cxx17_check.cpp b/Source/Checks/cm_cxx17_check.cpp index 4e89184..593d9b2 100644 --- a/Source/Checks/cm_cxx17_check.cpp +++ b/Source/Checks/cm_cxx17_check.cpp @@ -1,9 +1,31 @@ #include <cstdio> +#include <iterator> #include <memory> #include <unordered_map> +#ifdef _MSC_VER +# include <comdef.h> +#endif + int main() { + int a[] = { 0, 1, 2 }; + auto ai = std::cbegin(a); + + int b[] = { 2, 1, 0 }; + auto bi = std::cend(b); + + auto ci = std::size(a); + std::unique_ptr<int> u(new int(0)); - return *u; + +#ifdef _MSC_VER + // clang-cl has problems instantiating this constructor in C++17 mode + // error: indirection requires pointer operand ('const _GUID' invalid) + // return *_IID; + IUnknownPtr ptr{}; + IDispatchPtr disp(ptr); +#endif + + return *u + *ai + *(bi - 1) + (3 - static_cast<int>(ci)); } diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index f2982a6..745c6bb 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -150,7 +150,7 @@ int main(int argc, char const* const* argv) } cmSystemTools::SetMessageCallback( - [myform](const char* message, const char* title) { + [myform](const std::string& message, const char* title) { myform->AddError(message, title); }); diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h index ddb67de..7842905 100644 --- a/Source/CursesDialog/cmCursesForm.h +++ b/Source/CursesDialog/cmCursesForm.h @@ -9,6 +9,8 @@ #include "cmsys/FStream.hxx" +#include <string> + class cmCursesForm { public: @@ -34,7 +36,7 @@ public: // Description: // During a CMake run, an error handle should add errors // to be displayed afterwards. - virtual void AddError(const char*, const char*) {} + virtual void AddError(const std::string&, const char*) {} // Description: // Turn debugging on. This will create ccmakelog.txt. diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx index a41d051..4e887d6 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -19,9 +19,8 @@ cmCursesLongMessageForm::cmCursesLongMessageForm( std::vector<std::string> const& messages, const char* title) { // Append all messages into on big string - std::vector<std::string>::const_iterator it; - for (it = messages.begin(); it != messages.end(); it++) { - this->Messages += (*it); + for (std::string const& message : messages) { + this->Messages += message; // Add one blank line after each message this->Messages += "\n\n"; } diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 8ca7802..906dd02 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -79,18 +79,11 @@ cmCursesMainForm::~cmCursesMainForm() // See if a cache entry is in the list of entries in the ui. bool cmCursesMainForm::LookForCacheEntry(const std::string& key) { - if (!this->Entries) { - return false; - } - - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - if (key == (*it)->Key) { - return true; - } - } - - return false; + return this->Entries && + std::any_of(this->Entries->begin(), this->Entries->end(), + [&key](cmCursesCacheEntryComposite* entry) { + return key == entry->Key; + }); } // Create new cmCursesCacheEntryComposite entries from the cache @@ -107,10 +100,9 @@ void cmCursesMainForm::InitializeUI() // Count non-internal and non-static entries int count = 0; - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { + for (std::string const& key : cacheKeys) { cmStateEnums::CacheEntryType t = - this->CMakeInstance->GetState()->GetCacheEntryType(*it); + this->CMakeInstance->GetState()->GetCacheEntryType(key); if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC && t != cmStateEnums::UNINITIALIZED) { ++count; @@ -130,11 +122,9 @@ void cmCursesMainForm::InitializeUI() // Create the composites. // First add entries which are new - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { - std::string key = *it; + for (std::string const& key : cacheKeys) { cmStateEnums::CacheEntryType t = - this->CMakeInstance->GetState()->GetCacheEntryType(*it); + this->CMakeInstance->GetState()->GetCacheEntryType(key); if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC || t == cmStateEnums::UNINITIALIZED) { continue; @@ -148,11 +138,9 @@ void cmCursesMainForm::InitializeUI() } // then add entries which are old - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { - std::string key = *it; + for (std::string const& key : cacheKeys) { cmStateEnums::CacheEntryType t = - this->CMakeInstance->GetState()->GetCacheEntryType(*it); + this->CMakeInstance->GetState()->GetCacheEntryType(key); if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC || t == cmStateEnums::UNINITIALIZED) { continue; @@ -190,13 +178,12 @@ void cmCursesMainForm::RePost() } else { // If normal mode, count only non-advanced entries this->NumberOfVisibleEntries = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -217,27 +204,26 @@ void cmCursesMainForm::RePost() // Assign fields int j = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } - this->Fields[3 * j] = (*it)->Label->Field; - this->Fields[3 * j + 1] = (*it)->IsNewLabel->Field; - this->Fields[3 * j + 2] = (*it)->Entry->Field; + this->Fields[3 * j] = entry->Label->Field; + this->Fields[3 * j + 1] = entry->IsNewLabel->Field; + this->Fields[3 * j + 2] = entry->Entry->Field; j++; } // if no cache entries there should still be one dummy field if (j == 0) { - it = this->Entries->begin(); - this->Fields[0] = (*it)->Label->Field; - this->Fields[1] = (*it)->IsNewLabel->Field; - this->Fields[2] = (*it)->Entry->Field; + const auto& front = *this->Entries->front(); + this->Fields[0] = front.Label->Field; + this->Fields[1] = front.IsNewLabel->Field; + this->Fields[2] = front.Entry->Field; this->NumberOfVisibleEntries = 1; } // Has to be null terminated. @@ -278,13 +264,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) } else { // If normal, display only non-advanced entries this->NumberOfVisibleEntries = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -297,13 +282,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) if (height > 0) { bool isNewPage; int i = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite* entry : *this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry->GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -314,10 +298,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) if (isNewPage) { this->NumberOfPages++; } - (*it)->Label->Move(left, top + row - 1, isNewPage); - (*it)->IsNewLabel->Move(left + 32, top + row - 1, false); - (*it)->Entry->Move(left + 33, top + row - 1, false); - (*it)->Entry->SetPage(this->NumberOfPages); + entry->Label->Move(left, top + row - 1, isNewPage); + entry->IsNewLabel->Move(left + 32, top + row - 1, false); + entry->Entry->Move(left + 33, top + row - 1, false); + entry->Entry->SetPage(this->NumberOfPages); i++; } } @@ -506,14 +490,14 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) pos_form_cursor(this->Form); } -void cmCursesMainForm::UpdateProgress(const char* msg, float prog) +void cmCursesMainForm::UpdateProgress(const std::string& msg, float prog) { char tmp[1024]; const char* cmsg = tmp; if (prog >= 0) { - sprintf(tmp, "%s %i%%", msg, static_cast<int>(100 * prog)); + sprintf(tmp, "%s %i%%", msg.c_str(), static_cast<int>(100 * prog)); } else { - cmsg = msg; + cmsg = msg.c_str(); } this->UpdateStatusBar(cmsg); this->PrintKeys(1); @@ -533,7 +517,9 @@ int cmCursesMainForm::Configure(int noconfigure) touchwin(stdscr); refresh(); this->CMakeInstance->SetProgressCallback( - [this](const char* msg, float prog) { this->UpdateProgress(msg, prog); }); + [this](const std::string& msg, float prog) { + this->UpdateProgress(msg, prog); + }); // always save the current gui values to disk this->FillCacheManagerFromUI(); @@ -603,7 +589,9 @@ int cmCursesMainForm::Generate() touchwin(stdscr); refresh(); this->CMakeInstance->SetProgressCallback( - [this](const char* msg, float prog) { this->UpdateProgress(msg, prog); }); + [this](const std::string& msg, float prog) { + this->UpdateProgress(msg, prog); + }); // Get rid of previous errors this->Errors = std::vector<std::string>(); @@ -647,7 +635,8 @@ int cmCursesMainForm::Generate() return 0; } -void cmCursesMainForm::AddError(const char* message, const char* /*unused*/) +void cmCursesMainForm::AddError(const std::string& message, + const char* /*unused*/) { this->Errors.emplace_back(message); } @@ -658,28 +647,29 @@ void cmCursesMainForm::RemoveEntry(const char* value) return; } - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* val = (*it)->GetValue(); - if (val && !strcmp(value, val)) { - this->CMakeInstance->UnwatchUnusedCli(value); - this->Entries->erase(it); - break; - } + auto removeIt = + std::find_if(this->Entries->begin(), this->Entries->end(), + [value](cmCursesCacheEntryComposite* entry) -> bool { + const char* val = entry->GetValue(); + return val != nullptr && !strcmp(value, val); + }); + + if (removeIt != this->Entries->end()) { + this->CMakeInstance->UnwatchUnusedCli(value); + this->Entries->erase(removeIt); } } // copy from the list box to the cache manager void cmCursesMainForm::FillCacheManagerFromUI() { - size_t size = this->Entries->size(); - for (size_t i = 0; i < size; i++) { - std::string cacheKey = (*this->Entries)[i]->Key; + for (cmCursesCacheEntryComposite* entry : *this->Entries) { + const std::string& cacheKey = entry->Key; const char* existingValue = this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey); if (existingValue) { std::string oldValue = existingValue; - std::string newValue = (*this->Entries)[i]->Entry->GetValue(); + std::string newValue = entry->GetValue(); std::string fixedOldValue; std::string fixedNewValue; cmStateEnums::CacheEntryType t = @@ -975,17 +965,14 @@ void cmCursesMainForm::HandleInput() if (nextCur) { // make the next or prev. current field after deletion - nextCur = nullptr; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); - ++it) { - if (nextVal == (*it)->Key) { - nextCur = (*it)->Entry->Field; - } - } - - if (nextCur) { - set_current_field(this->Form, nextCur); + auto nextEntryIt = + std::find_if(this->Entries->begin(), this->Entries->end(), + [&nextVal](cmCursesCacheEntryComposite* entry) { + return nextVal == entry->Key; + }); + + if (nextEntryIt != this->Entries->end()) { + set_current_field(this->Form, (*nextEntryIt)->Entry->Field); } } } diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index cc6482f..d379975 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -81,7 +81,7 @@ public: * During a CMake run, an error handle should add errors * to be displayed afterwards. */ - void AddError(const char* message, const char* title) override; + void AddError(const std::string& message, const char* title) override; /** * Used to do a configure. If argument is specified, it does only the check @@ -102,7 +102,7 @@ public: /** * Progress callback */ - void UpdateProgress(const char* msg, float prog); + void UpdateProgress(const std::string& msg, float prog); protected: // Copy the cache values from the user interface to the actual diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx index f28e1a8..364a378 100644 --- a/Source/QtDialog/FirstConfigure.cxx +++ b/Source/QtDialog/FirstConfigure.cxx @@ -95,33 +95,32 @@ void StartCompilerSetup::setGenerators( QStringList generator_list; - std::vector<cmake::GeneratorInfo>::const_iterator it; - for (it = gens.begin(); it != gens.end(); ++it) { - generator_list.append(QString::fromLocal8Bit(it->name.c_str())); + for (cmake::GeneratorInfo const& gen : gens) { + generator_list.append(QString::fromLocal8Bit(gen.name.c_str())); - if (it->supportsPlatform) { + if (gen.supportsPlatform) { this->GeneratorsSupportingPlatform.append( - QString::fromLocal8Bit(it->name.c_str())); + QString::fromLocal8Bit(gen.name.c_str())); this - ->GeneratorDefaultPlatform[QString::fromLocal8Bit(it->name.c_str())] = - QString::fromLocal8Bit(it->defaultPlatform.c_str()); + ->GeneratorDefaultPlatform[QString::fromLocal8Bit(gen.name.c_str())] = + QString::fromLocal8Bit(gen.defaultPlatform.c_str()); std::vector<std::string>::const_iterator platformIt = - it->supportedPlatforms.cbegin(); - while (platformIt != it->supportedPlatforms.cend()) { + gen.supportedPlatforms.cbegin(); + while (platformIt != gen.supportedPlatforms.cend()) { this->GeneratorSupportedPlatforms.insert( - QString::fromLocal8Bit(it->name.c_str()), + QString::fromLocal8Bit(gen.name.c_str()), QString::fromLocal8Bit((*platformIt).c_str())); platformIt++; } } - if (it->supportsToolset) { + if (gen.supportsToolset) { this->GeneratorsSupportingToolset.append( - QString::fromLocal8Bit(it->name.c_str())); + QString::fromLocal8Bit(gen.name.c_str())); } } diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index a073c30..f357f90 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -25,7 +25,7 @@ QCMake::QCMake(QObject* p) cmSystemTools::SetRunCommandHideConsole(true); cmSystemTools::SetMessageCallback( - [this](const char* msg, const char* title) { + [this](std::string const& msg, const char* title) { this->messageCallback(msg, title); }); cmSystemTools::SetStdoutCallback( @@ -37,7 +37,7 @@ QCMake::QCMake(QObject* p) this->CMakeInstance->SetCMakeEditCommand( cmSystemTools::GetCMakeGUICommand()); this->CMakeInstance->SetProgressCallback( - [this](const char* msg, float percent) { + [this](const std::string& msg, float percent) { this->progressCallback(msg, percent); }); @@ -48,9 +48,8 @@ QCMake::QCMake(QObject* p) this->CMakeInstance->GetRegisteredGenerators( generators, /*includeNamesWithPlatform=*/false); - std::vector<cmake::GeneratorInfo>::const_iterator it; - for (it = generators.begin(); it != generators.end(); ++it) { - this->AvailableGenerators.push_back(*it); + for (cmake::GeneratorInfo const& gen : generators) { + this->AvailableGenerators.push_back(gen); } } @@ -234,24 +233,23 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) // set the value of properties cmState* state = this->CMakeInstance->GetState(); std::vector<std::string> cacheKeys = state->GetCacheEntryKeys(); - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { - cmStateEnums::CacheEntryType t = state->GetCacheEntryType(*it); + for (std::string const& key : cacheKeys) { + cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key); if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC) { continue; } QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(it->c_str()); + prop.Key = QString::fromLocal8Bit(key.c_str()); int idx = props.indexOf(prop); if (idx == -1) { - toremove.append(QString::fromLocal8Bit(it->c_str())); + toremove.append(QString::fromLocal8Bit(key.c_str())); } else { prop = props[idx]; if (prop.Value.type() == QVariant::Bool) { - state->SetCacheEntryValue(*it, prop.Value.toBool() ? "ON" : "OFF"); + state->SetCacheEntryValue(key, prop.Value.toBool() ? "ON" : "OFF"); } else { - state->SetCacheEntryValue(*it, + state->SetCacheEntryValue(key, prop.Value.toString().toLocal8Bit().data()); } props.removeAt(idx); @@ -297,22 +295,21 @@ QCMakePropertyList QCMake::properties() const cmState* state = this->CMakeInstance->GetState(); std::vector<std::string> cacheKeys = state->GetCacheEntryKeys(); - for (std::vector<std::string>::const_iterator i = cacheKeys.begin(); - i != cacheKeys.end(); ++i) { - cmStateEnums::CacheEntryType t = state->GetCacheEntryType(*i); + for (std::string const& key : cacheKeys) { + cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key); if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC || t == cmStateEnums::UNINITIALIZED) { continue; } - const char* cachedValue = state->GetCacheEntryValue(*i); + const char* cachedValue = state->GetCacheEntryValue(key); QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(i->c_str()); + prop.Key = QString::fromLocal8Bit(key.c_str()); prop.Help = - QString::fromLocal8Bit(state->GetCacheEntryProperty(*i, "HELPSTRING")); + QString::fromLocal8Bit(state->GetCacheEntryProperty(key, "HELPSTRING")); prop.Value = QString::fromLocal8Bit(cachedValue); - prop.Advanced = state->GetCacheEntryPropertyAsBool(*i, "ADVANCED"); + prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED"); if (t == cmStateEnums::BOOL) { prop.Type = QCMakeProperty::BOOL; prop.Value = cmSystemTools::IsOn(cachedValue); @@ -323,7 +320,7 @@ QCMakePropertyList QCMake::properties() const } else if (t == cmStateEnums::STRING) { prop.Type = QCMakeProperty::STRING; const char* stringsProperty = - state->GetCacheEntryProperty(*i, "STRINGS"); + state->GetCacheEntryProperty(key, "STRINGS"); if (stringsProperty) { prop.Strings = QString::fromLocal8Bit(stringsProperty).split(";"); } @@ -349,19 +346,19 @@ bool QCMake::interruptCallback() #endif } -void QCMake::progressCallback(const char* msg, float percent) +void QCMake::progressCallback(const std::string& msg, float percent) { if (percent >= 0) { - emit this->progressChanged(QString::fromLocal8Bit(msg), percent); + emit this->progressChanged(QString::fromStdString(msg), percent); } else { - emit this->outputMessage(QString::fromLocal8Bit(msg)); + emit this->outputMessage(QString::fromStdString(msg)); } QCoreApplication::processEvents(); } -void QCMake::messageCallback(const char* msg, const char* /*title*/) +void QCMake::messageCallback(std::string const& msg, const char* /*title*/) { - emit this->errorMessage(QString::fromLocal8Bit(msg)); + emit this->errorMessage(QString::fromStdString(msg)); QCoreApplication::processEvents(); } diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index ef4d2a1..f2fd6d9 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -168,8 +168,8 @@ protected: cmake* CMakeInstance; bool interruptCallback(); - void progressCallback(const char* msg, float percent); - void messageCallback(const char* msg, const char* title); + void progressCallback(std::string const& msg, float percent); + void messageCallback(std::string const& msg, const char* title); void stdoutCallback(std::string const& msg); void stderrCallback(std::string const& msg); diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx index 021bd29..4956a47 100644 --- a/Source/cmAddDependenciesCommand.cxx +++ b/Source/cmAddDependenciesCommand.cxx @@ -6,6 +6,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmRange.h" #include "cmTarget.h" class cmExecutionStatus; @@ -27,10 +28,10 @@ bool cmAddDependenciesCommand::InitialPass( this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } if (cmTarget* target = this->Makefile->FindTargetToUse(target_name)) { - std::vector<std::string>::const_iterator s = args.begin(); - ++s; // skip over target_name - for (; s != args.end(); ++s) { - target->AddUtility(*s, this->Makefile); + + // skip over target_name + for (std::string const& arg : cmMakeRange(args).advance(1)) { + target->AddUtility(arg, this->Makefile); } } else { std::ostringstream e; diff --git a/Source/cmAddSubDirectoryCommand.cxx b/Source/cmAddSubDirectoryCommand.cxx index 75e5aa4..7947188 100644 --- a/Source/cmAddSubDirectoryCommand.cxx +++ b/Source/cmAddSubDirectoryCommand.cxx @@ -6,6 +6,7 @@ #include <string.h> #include "cmMakefile.h" +#include "cmRange.h" #include "cmSystemTools.h" class cmExecutionStatus; @@ -26,15 +27,13 @@ bool cmAddSubDirectoryCommand::InitialPass( bool excludeFromAll = false; // process the rest of the arguments looking for optional args - std::vector<std::string>::const_iterator i = args.begin(); - ++i; - for (; i != args.end(); ++i) { - if (*i == "EXCLUDE_FROM_ALL") { + for (std::string const& arg : cmMakeRange(args).advance(1)) { + if (arg == "EXCLUDE_FROM_ALL") { excludeFromAll = true; continue; } if (binArg.empty()) { - binArg = *i; + binArg = arg; } else { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index d38b0d1..2ff1ed0 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -5,6 +5,8 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include "cmRange.h" + #include "cm_kwiml.h" #include <algorithm> #include <functional> @@ -156,57 +158,12 @@ private: }; } -template <typename const_iterator_> -struct cmRange -{ - typedef const_iterator_ const_iterator; - typedef typename std::iterator_traits<const_iterator>::value_type value_type; - typedef typename std::iterator_traits<const_iterator>::difference_type - difference_type; - cmRange(const_iterator begin_, const_iterator end_) - : Begin(begin_) - , End(end_) - { - } - const_iterator begin() const { return Begin; } - const_iterator end() const { return End; } - bool empty() const { return std::distance(Begin, End) == 0; } - difference_type size() const { return std::distance(Begin, End); } - cmRange& advance(KWIML_INT_intptr_t amount) - { - std::advance(Begin, amount); - return *this; - } - - cmRange& retreat(KWIML_INT_intptr_t amount) - { - std::advance(End, -amount); - return *this; - } - -private: - const_iterator Begin; - const_iterator End; -}; - typedef cmRange<std::vector<std::string>::const_iterator> cmStringRange; class cmListFileBacktrace; typedef cmRange<std::vector<cmListFileBacktrace>::const_iterator> cmBacktraceRange; -template <typename Iter1, typename Iter2> -cmRange<Iter1> cmMakeRange(Iter1 begin, Iter2 end) -{ - return cmRange<Iter1>(begin, end); -} - -template <typename Range> -cmRange<typename Range::const_iterator> cmMakeRange(Range const& range) -{ - return cmRange<typename Range::const_iterator>(range.begin(), range.end()); -} - template <typename Range> void cmDeleteAll(Range const& r) { @@ -322,14 +279,6 @@ typename Range::const_iterator cmFindNot(Range const& r, T const& t) return std::find_if(r.begin(), r.end(), [&t](T const& i) { return i != t; }); } -template <typename Range> -cmRange<typename Range::const_reverse_iterator> cmReverseRange( - Range const& range) -{ - return cmRange<typename Range::const_reverse_iterator>(range.rbegin(), - range.rend()); -} - template <class Iter> std::reverse_iterator<Iter> cmMakeReverseIterator(Iter it) { diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 6e5109a..23be603 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -54,6 +54,8 @@ public: { } ~Entry() { archive_entry_free(this->Object); } + Entry(const Entry&) = delete; + Entry& operator=(const Entry&) = delete; operator struct archive_entry*() { return this->Object; } }; diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h index 6ecdd63..1f23dae 100644 --- a/Source/cmArchiveWrite.h +++ b/Source/cmArchiveWrite.h @@ -58,6 +58,9 @@ public: ~cmArchiveWrite(); + cmArchiveWrite(const cmArchiveWrite&) = delete; + cmArchiveWrite& operator=(const cmArchiveWrite&) = delete; + /** * Add a path (file or directory) to the archive. Directories are * added recursively. The "path" must be readable on disk, either diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index c0088ac..5efc784 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -491,12 +491,16 @@ public: typedef std::map<cmSourceFile*, cmCPluginAPISourceFile*> derived; typedef derived::iterator iterator; typedef derived::value_type value_type; + cmCPluginAPISourceFileMap() = default; ~cmCPluginAPISourceFileMap() { for (auto const& i : *this) { delete i.second; } } + cmCPluginAPISourceFileMap(const cmCPluginAPISourceFileMap&) = delete; + cmCPluginAPISourceFileMap& operator=(const cmCPluginAPISourceFileMap&) = + delete; }; cmCPluginAPISourceFileMap cmCPluginAPISourceFiles; @@ -683,26 +687,24 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir, } // Next, try the various source extensions - for (std::vector<std::string>::const_iterator ext = sourceExts.begin(); - ext != sourceExts.end(); ++ext) { + for (std::string const& ext : sourceExts) { hname = pathname; hname += "."; - hname += *ext; + hname += ext; if (cmSystemTools::FileExists(hname)) { - sf->SourceExtension = *ext; + sf->SourceExtension = ext; sf->FullPath = hname; return; } } // Finally, try the various header extensions - for (std::vector<std::string>::const_iterator ext = headerExts.begin(); - ext != headerExts.end(); ++ext) { + for (std::string const& ext : headerExts) { hname = pathname; hname += "."; - hname += *ext; + hname += ext; if (cmSystemTools::FileExists(hname)) { - sf->SourceExtension = *ext; + sf->SourceExtension = ext; sf->FullPath = hname; return; } @@ -711,13 +713,11 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir, std::ostringstream e; e << "Cannot find source file \"" << pathname << "\""; e << "\n\nTried extensions"; - for (std::vector<std::string>::const_iterator ext = sourceExts.begin(); - ext != sourceExts.end(); ++ext) { - e << " ." << *ext; + for (std::string const& ext : sourceExts) { + e << " ." << ext; } - for (std::vector<std::string>::const_iterator ext = headerExts.begin(); - ext != headerExts.end(); ++ext) { - e << " ." << *ext; + for (std::string const& ext : headerExts) { + e << " ." << ext; } cmSystemTools::Error(e.str()); } diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 989c7ee..c77bb97 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1009,7 +1009,7 @@ int cmCTest::GetTestModelFromString(const char* str) //###################################################################### //###################################################################### -int cmCTest::RunMakeCommand(const char* command, std::string& output, +int cmCTest::RunMakeCommand(const std::string& command, std::string& output, int* retVal, const char* dir, cmDuration timeout, std::ostream& ofs, Encoding encoding) { @@ -1039,7 +1039,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, // Now create process object cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_SetCommand(cp, argv.data()); cmsysProcess_SetWorkingDirectory(cp, dir); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); cmsysProcess_SetTimeout(cp, timeout.count()); @@ -1222,7 +1222,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, } cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_SetCommand(cp, argv.data()); cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl); if (cmSystemTools::GetRunCommandHideConsole()) { cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); @@ -1258,7 +1258,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, cmsysProcess_WaitForExit(cp, nullptr); processOutput.DecodeText(tempOutput, tempOutput); if (output && tempOutput.begin() != tempOutput.end()) { - output->append(&*tempOutput.begin(), tempOutput.size()); + output->append(tempOutput.data(), tempOutput.size()); } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed" << std::endl); @@ -2776,7 +2776,7 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args, stdErr->clear(); cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_SetCommand(cp, argv.data()); cmsysProcess_SetWorkingDirectory(cp, dir); if (cmSystemTools::GetRunCommandHideConsole()) { cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); @@ -2820,11 +2820,11 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args, cmsysProcess_WaitForExit(cp, nullptr); if (!tempOutput.empty()) { processOutput.DecodeText(tempOutput, tempOutput); - stdOut->append(&*tempOutput.begin(), tempOutput.size()); + stdOut->append(tempOutput.data(), tempOutput.size()); } if (!tempError.empty()) { processOutput.DecodeText(tempError, tempError); - stdErr->append(&*tempError.begin(), tempError.size()); + stdErr->append(tempError.data(), tempError.size()); } bool result = true; @@ -3048,7 +3048,7 @@ void cmCTest::OutputTestErrors(std::vector<char> const& process_output) { std::string test_outputs("\n*** Test Failed:\n"); if (!process_output.empty()) { - test_outputs.append(&*process_output.begin(), process_output.size()); + test_outputs.append(process_output.data(), process_output.size()); } cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush); } diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 92a02c3..a765fed 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -182,6 +182,9 @@ public: cmCTest(); ~cmCTest(); + cmCTest(const cmCTest&) = delete; + cmCTest& operator=(const cmCTest&) = delete; + /** Set the notes files to be created. */ void SetNotesFiles(const char* notes); @@ -277,8 +280,9 @@ public: * Run command specialized for make and configure. Returns process status * and retVal is return value or exception. */ - int RunMakeCommand(const char* command, std::string& output, int* retVal, - const char* dir, cmDuration timeout, std::ostream& ofs, + int RunMakeCommand(const std::string& command, std::string& output, + int* retVal, const char* dir, cmDuration timeout, + std::ostream& ofs, Encoding encoding = cmProcessOutput::Auto); /** Return the current tag */ diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 2728f0f..6116de0 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -239,8 +239,7 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) cmGeneratedFileStream fout(cacheFile); fout.SetCopyIfDifferent(true); if (!fout) { - cmSystemTools::Error("Unable to open cache file for save. ", - cacheFile.c_str()); + cmSystemTools::Error("Unable to open cache file for save. " + cacheFile); cmSystemTools::ReportLastSystemError(""); return false; } @@ -364,8 +363,8 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) checkCacheFile += "/cmake.check_cache"; cmsys::ofstream checkCache(checkCacheFile.c_str()); if (!checkCache) { - cmSystemTools::Error("Unable to open check cache file for write. ", - checkCacheFile.c_str()); + cmSystemTools::Error("Unable to open check cache file for write. " + + checkCacheFile); return false; } checkCache << "# This file is generated by cmake for dependency checking " diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 4717cf6..186deb6 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -9,6 +9,7 @@ #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -256,11 +257,7 @@ cmComputeLinkDepends::Compute() // Iterate in reverse order so we can keep only the last occurrence // of a shared library. std::set<int> emmitted; - for (std::vector<int>::const_reverse_iterator - li = this->FinalLinkOrder.rbegin(), - le = this->FinalLinkOrder.rend(); - li != le; ++li) { - int i = *li; + for (int i : cmReverseRange(this->FinalLinkOrder)) { LinkEntry const& e = this->EntryList[i]; cmGeneratorTarget const* t = e.Target; // Entries that we know the linker will re-use do not need to be repeated. @@ -586,11 +583,10 @@ void cmComputeLinkDepends::InferDependencies() } // Intersect the sets for this item. - DependSetList::const_iterator i = sets->begin(); - DependSet common = *i; - for (++i; i != sets->end(); ++i) { + DependSet common = sets->front(); + for (DependSet const& i : cmMakeRange(*sets).advance(1)) { DependSet intersection; - std::set_intersection(common.begin(), common.end(), i->begin(), i->end(), + std::set_intersection(common.begin(), common.end(), i.begin(), i.end(), std::inserter(intersection, intersection.begin())); common = intersection; } @@ -708,9 +704,8 @@ void cmComputeLinkDepends::VisitComponent(unsigned int c) // Run in reverse order so the topological order will preserve the // original order where there are no constraints. EdgeList const& nl = this->CCG->GetComponentGraphEdges(c); - for (EdgeList::const_reverse_iterator ni = nl.rbegin(); ni != nl.rend(); - ++ni) { - this->VisitComponent(*ni); + for (cmGraphEdge const& edge : cmReverseRange(nl)) { + this->VisitComponent(edge); } // Assign an ordering id to this component. diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 252f874..dfaaf8b 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -31,6 +31,9 @@ public: const std::string& config); ~cmComputeLinkDepends(); + cmComputeLinkDepends(const cmComputeLinkDepends&) = delete; + cmComputeLinkDepends& operator=(const cmComputeLinkDepends&) = delete; + // Basic information about each link item. struct LinkEntry { diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 3d61665..44d8615 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -457,8 +457,8 @@ bool cmComputeLinkInformation::Compute() // We require a link language for the target. if (this->LinkLanguage.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - this->Target->GetName().c_str()); + "CMake can not determine linker language for target: " + + this->Target->GetName()); return false; } @@ -1266,7 +1266,7 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item) void cmComputeLinkInformation::AddDirectoryItem(std::string const& item) { if (this->Makefile->IsOn("APPLE") && - cmSystemTools::IsPathToFramework(item.c_str())) { + cmSystemTools::IsPathToFramework(item)) { this->AddFrameworkItem(item); } else { this->DropDirectoryItem(item); diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 9b7b02f..01d4c07 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -11,6 +11,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateTypes.h" @@ -549,10 +550,9 @@ bool cmComputeTargetDepends::ComputeFinalDepends( int head = -1; std::set<int> emitted; NodeList const& nl = components[c]; - for (NodeList::const_reverse_iterator ni = nl.rbegin(); ni != nl.rend(); - ++ni) { + for (int ni : cmReverseRange(nl)) { std::set<int> visited; - if (!this->IntraComponent(cmap, c, *ni, &head, emitted, visited)) { + if (!this->IntraComponent(cmap, c, ni, &head, emitted, visited)) { // Cycle in add_dependencies within component! this->ComplainAboutBadComponent(ccg, c, true); return false; diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 94ea529..303b147 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -130,8 +130,8 @@ bool cmConditionEvaluator::IsTrue( return false; } - return this->GetBooleanValueWithAutoDereference(*(newArgs.begin()), - errorString, status, true); + return this->GetBooleanValueWithAutoDereference(newArgs.front(), errorString, + status, true); } //========================================================================= diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index 8224a0f..0917d11 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -102,7 +102,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args, int cmConfigureFileCommand::ConfigureFile() { - return this->Makefile->ConfigureFile( - this->InputFile.c_str(), this->OutputFile.c_str(), this->CopyOnly, - this->AtOnly, this->EscapeQuotes, this->NewLineStyle); + return this->Makefile->ConfigureFile(this->InputFile, this->OutputFile, + this->CopyOnly, this->AtOnly, + this->EscapeQuotes, this->NewLineStyle); } diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index eb52895..69d4374 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -950,8 +950,8 @@ void cmCoreTryCompile::CleanupFiles(std::string const& binDir) if (binDir.find("CMakeTmp") == std::string::npos) { cmSystemTools::Error( "TRY_COMPILE attempt to remove -rf directory that does not contain " - "CMakeTmp:", - binDir.c_str()); + "CMakeTmp:" + + binDir); return; } diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx index 69532e6..b78493f 100644 --- a/Source/cmCreateTestSourceList.cxx +++ b/Source/cmCreateTestSourceList.cxx @@ -136,8 +136,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", functionMapCode.c_str()); bool res = true; - if (!this->Makefile->ConfigureFile(configFile.c_str(), driver.c_str(), false, - true, false)) { + if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) { res = false; } diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index 9684cff..7fd60c0 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -32,6 +32,9 @@ public: cmCustomCommandGenerator(cmCustomCommand const& cc, std::string config, cmLocalGenerator* lg); ~cmCustomCommandGenerator(); + cmCustomCommandGenerator(const cmCustomCommandGenerator&) = delete; + cmCustomCommandGenerator& operator=(const cmCustomCommandGenerator&) = + delete; cmCustomCommand const& GetCC() const { return this->CC; } unsigned int GetNumberOfCommands() const; std::string GetCommand(unsigned int c) const; diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index b1630f9..f5c106c 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -173,8 +173,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, // regex. if (fullName.empty() && this->IncludeRegexComplain.find(current.FileName)) { - cmSystemTools::Error("Cannot find file \"", current.FileName.c_str(), - "\"."); + cmSystemTools::Error("Cannot find file \"" + current.FileName + "\"."); return false; } diff --git a/Source/cmDependsJavaParserHelper.h b/Source/cmDependsJavaParserHelper.h index 0b445d9..a673b5b 100644 --- a/Source/cmDependsJavaParserHelper.h +++ b/Source/cmDependsJavaParserHelper.h @@ -24,6 +24,10 @@ public: cmDependsJavaParserHelper(); ~cmDependsJavaParserHelper(); + cmDependsJavaParserHelper(const cmDependsJavaParserHelper&) = delete; + cmDependsJavaParserHelper& operator=(const cmDependsJavaParserHelper&) = + delete; + int ParseString(const char* str, int verb); int ParseFile(const char* file); diff --git a/Source/cmELF.h b/Source/cmELF.h index c8a91e4..987f0c3 100644 --- a/Source/cmELF.h +++ b/Source/cmELF.h @@ -28,6 +28,9 @@ public: /** Destruct. */ ~cmELF(); + cmELF(const cmELF&) = delete; + cmELF& operator=(const cmELF&) = delete; + /** Get the error message if any. */ std::string const& GetErrorMessage() const { return this->ErrorMessage; } diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index 75a7786..36651af 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -67,7 +67,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args, std::string command; if (!arguments.empty()) { - command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str()); + command = cmSystemTools::ConvertToRunCommandPath(args[0]); command += " "; command += arguments; } else { @@ -152,7 +152,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, if (!cmSystemTools::FileExists(cmd)) { shortCmd = cmd; } else if (!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd)) { - cmSystemTools::Error("GetShortPath failed for ", cmd.c_str()); + cmSystemTools::Error("GetShortPath failed for " + cmd); return false; } shortCmd += " "; diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 8c67cdb..03eac5b 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -193,7 +193,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, // Set the command sequence. for (auto const& cmd : cmds) { - cmsysProcess_AddCommand(cp, &*cmd.begin()); + cmsysProcess_AddCommand(cp, cmd.data()); } // Set the process working directory. @@ -286,10 +286,10 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, // Store the output obtained. if (!output_variable.empty() && !tempOutput.empty()) { - this->Makefile->AddDefinition(output_variable, &*tempOutput.begin()); + this->Makefile->AddDefinition(output_variable, tempOutput.data()); } if (!merge_output && !error_variable.empty() && !tempError.empty()) { - this->Makefile->AddDefinition(error_variable, &*tempError.begin()); + this->Makefile->AddDefinition(error_variable, tempError.data()); } // Store the result of running the process. diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index c8f743a..a12e0c4 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -70,8 +70,9 @@ bool cmExportFileGenerator::GenerateImportFile() std::unique_ptr<cmsys::ofstream> foutPtr; if (this->AppendMode) { // Open for append. + auto openmodeApp = std::ios::app; foutPtr = cm::make_unique<cmsys::ofstream>(this->MainImportFile.c_str(), - std::ios::app); + openmodeApp); } else { // Generate atomically and with copy-if-different. std::unique_ptr<cmGeneratedFileStream> ap( diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx index b4b2962..0a0646c 100644 --- a/Source/cmExportLibraryDependenciesCommand.cxx +++ b/Source/cmExportLibraryDependenciesCommand.cxx @@ -50,8 +50,9 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const // Use copy-if-different if not appending. std::unique_ptr<cmsys::ofstream> foutPtr; if (this->Append) { + const auto openmodeApp = std::ios::app; foutPtr = - cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), std::ios::app); + cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), openmodeApp); } else { std::unique_ptr<cmGeneratedFileStream> ap( new cmGeneratedFileStream(this->Filename, true)); @@ -61,7 +62,7 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const std::ostream& fout = *foutPtr; if (!fout) { - cmSystemTools::Error("Error Writing ", this->Filename.c_str()); + cmSystemTools::Error("Error Writing " + this->Filename); cmSystemTools::ReportLastSystemError(""); return; } diff --git a/Source/cmExportSet.h b/Source/cmExportSet.h index 0ef306f..d654c12 100644 --- a/Source/cmExportSet.h +++ b/Source/cmExportSet.h @@ -25,6 +25,9 @@ public: /// Destructor ~cmExportSet(); + cmExportSet(const cmExportSet&) = delete; + cmExportSet& operator=(const cmExportSet&) = delete; + void Compute(cmLocalGenerator* lg); void AddTargetExport(cmTargetExport* tgt); diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx index 0740828..293e80c 100644 --- a/Source/cmExportSetMap.cxx +++ b/Source/cmExportSetMap.cxx @@ -23,6 +23,8 @@ void cmExportSetMap::clear() this->derived::clear(); } +cmExportSetMap::cmExportSetMap() = default; + cmExportSetMap::~cmExportSetMap() { this->clear(); diff --git a/Source/cmExportSetMap.h b/Source/cmExportSetMap.h index 0f71c79..3853732 100644 --- a/Source/cmExportSetMap.h +++ b/Source/cmExportSetMap.h @@ -25,8 +25,13 @@ public: void clear(); + cmExportSetMap(); + /// Overloaded destructor deletes all member export sets. ~cmExportSetMap(); + + cmExportSetMap(const cmExportSetMap&) = delete; + cmExportSetMap& operator=(const cmExportSetMap&) = delete; }; #endif diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index e408de3..93ff8f4 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -13,6 +13,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -247,8 +248,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // figure out the compiler std::string compiler = this->GetCBCompilerId(mf); - std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); - const std::string makeArgs = + const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& makeArgs = mf->GetSafeDefinition("CMAKE_CODEBLOCKS_MAKE_ARGUMENTS"); cmXMLWriter xml(fout); @@ -589,10 +590,9 @@ void cmExtraCodeBlocksGenerator::AppendTarget( std::vector<std::string>::const_iterator end = cmRemoveDuplicates(allIncludeDirs); - for (std::vector<std::string>::const_iterator i = allIncludeDirs.begin(); - i != end; ++i) { + for (std::string const& str : cmMakeRange(allIncludeDirs.cbegin(), end)) { xml.StartElement("Add"); - xml.Attribute("directory", *i); + xml.Attribute("directory", str); xml.EndElement(); } diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index 0773edc..6fe8c14 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -628,8 +628,8 @@ std::string cmExtraCodeLiteGenerator::GetConfigurationName( std::string cmExtraCodeLiteGenerator::GetBuildCommand( const cmMakefile* mf, const std::string& targetName) const { - std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR"); - std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& generator = mf->GetSafeDefinition("CMAKE_GENERATOR"); + const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::string buildCommand = make; // Default std::ostringstream ss; if (generator == "NMake Makefiles" || generator == "Ninja") { @@ -669,8 +669,8 @@ std::string cmExtraCodeLiteGenerator::GetSingleFileBuildCommand( const cmMakefile* mf) const { std::string buildCommand; - std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); - std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR"); + const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& generator = mf->GetSafeDefinition("CMAKE_GENERATOR"); if (generator == "Unix Makefiles" || generator == "MinGW Makefiles") { std::ostringstream ss; #if defined(_WIN32) diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 30067b7..a6ce8b7 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -878,8 +878,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const xml.Attribute("moduleId", "org.eclipse.cdt.make.core.buildtargets"); xml.StartElement("buildTargets"); emmited.clear(); - const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); - const std::string makeArgs = + const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& makeArgs = mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS"); cmGlobalGenerator* generator = @@ -1074,7 +1074,8 @@ void cmExtraEclipseCDT4Generator::AppendStorageScanners( cmXMLWriter& xml, const cmMakefile& makefile) { // we need the "make" and the C (or C++) compiler which are used, Alex - std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& make = + makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER"); std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1"); if (compiler.empty()) { diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 23ba6b7..76de75d 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -75,8 +75,8 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg, cmGeneratedFileStream& fout) const { cmMakefile const* mf = lg->GetMakefile(); - const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); - const std::string makeArgs = + const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& makeArgs = mf->GetSafeDefinition("CMAKE_KATE_MAKE_ARGUMENTS"); std::string const& homeOutputDir = lg->GetBinaryDirectory(); diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 739a177..59cfdca 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -168,7 +168,7 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( const std::vector<cmLocalGenerator*>& lgs, const cmMakefile* mf, cmGeneratedFileStream& fout, MapSourceFileFlags& sourceFileFlags) { - std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::string compiler; if (!lgs.empty()) { this->AppendTarget(fout, "all", lgs[0], nullptr, make.c_str(), mf, diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 4b14d26..89629c7 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -6,6 +6,7 @@ #include "cmCustomCommandLines.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmSystemTools.h" @@ -40,18 +41,17 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, this->Makefile->AddIncludeDirectories(outputDirectories); } - for (std::vector<std::string>::const_iterator i = (args.begin() + 1); - i != args.end(); i++) { - cmSourceFile* curr = this->Makefile->GetSource(*i); + for (std::string const& arg : cmMakeRange(args).advance(1)) { + cmSourceFile* curr = this->Makefile->GetSource(arg); // if we should use the source GUI // to generate .cxx and .h files if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE")) { std::string outName = outputDirectory; outName += "/"; - outName += cmSystemTools::GetFilenameWithoutExtension(*i); + outName += cmSystemTools::GetFilenameWithoutExtension(arg); std::string hname = outName; hname += ".h"; - std::string origname = cdir + "/" + *i; + std::string origname = cdir + "/" + arg; // add starting depends std::vector<std::string> depends; depends.push_back(origname); diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 0f911c1..a2018c3 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -34,6 +34,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmSystemTools.h" #include "cmTimestamp.h" #include "cm_sys_stat.h" @@ -223,7 +224,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, bool writable = false; // Set permissions to writable - if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) { + if (cmSystemTools::GetPermissions(fileName, mode)) { #if defined(_MSC_VER) || defined(__MINGW32__) writable = (mode & S_IWRITE) != 0; mode_t newMode = mode | S_IWRITE; @@ -232,7 +233,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, mode_t newMode = mode | S_IWUSR | S_IWGRP; #endif if (!writable) { - cmSystemTools::SetPermissions(fileName.c_str(), newMode); + cmSystemTools::SetPermissions(fileName, newMode); } } // If GetPermissions fails, pretend like it is ok. File open will fail if @@ -259,7 +260,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, } file.close(); if (mode && !writable) { - cmSystemTools::SetPermissions(fileName.c_str(), mode); + cmSystemTools::SetPermissions(fileName, mode); } return true; } @@ -393,7 +394,7 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args) #else std::ostringstream e; e << args[0] << " not available during bootstrap"; - this->SetError(e.str().c_str()); + this->SetError(e.str()); return false; #endif } @@ -523,7 +524,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) maxlen = len; arg_mode = arg_none; } else if (arg_mode == arg_regex) { - if (!regex.compile(args[i].c_str())) { + if (!regex.compile(args[i])) { std::ostringstream e; e << "STRINGS option REGEX value \"" << args[i] << "\" could not be compiled."; @@ -947,16 +948,14 @@ bool cmFileCommand::HandleMakeDirectoryCommand( // File command has at least one argument assert(args.size() > 1); - std::vector<std::string>::const_iterator i = args.begin(); - - i++; // Get rid of subcommand - std::string expr; - for (; i != args.end(); ++i) { - const std::string* cdir = &(*i); - if (!cmsys::SystemTools::FileIsFullPath(*i)) { + for (std::string const& arg : + cmMakeRange(args).advance(1)) // Get rid of subcommand + { + const std::string* cdir = &arg; + if (!cmsys::SystemTools::FileIsFullPath(arg)) { expr = this->Makefile->GetCurrentSourceDirectory(); - expr += "/" + *i; + expr += "/" + arg; cdir = &expr; } if (!this->Makefile->CanIWriteThisFile(*cdir)) { @@ -981,15 +980,13 @@ bool cmFileCommand::HandleTouchCommand(std::vector<std::string> const& args, // File command has at least one argument assert(args.size() > 1); - std::vector<std::string>::const_iterator i = args.begin(); - - i++; // Get rid of subcommand - - for (; i != args.end(); ++i) { - std::string tfile = *i; + for (std::string const& arg : + cmMakeRange(args).advance(1)) // Get rid of subcommand + { + std::string tfile = arg; if (!cmsys::SystemTools::FileIsFullPath(tfile)) { tfile = this->Makefile->GetCurrentSourceDirectory(); - tfile += "/" + *i; + tfile += "/" + arg; } if (!this->Makefile->CanIWriteThisFile(tfile)) { std::string e = @@ -1109,7 +1106,7 @@ protected: MatchProperties Properties; std::string RegexString; MatchRule(std::string const& regex) - : Regex(regex.c_str()) + : Regex(regex) , RegexString(regex) { } @@ -1117,14 +1114,13 @@ protected: std::vector<MatchRule> MatchRules; // Get the properties from rules matching this input file. - MatchProperties CollectMatchProperties(const char* file) + MatchProperties CollectMatchProperties(const std::string& file) { // Match rules are case-insensitive on some platforms. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__) - std::string lower = cmSystemTools::LowerCase(file); - const char* file_to_match = lower.c_str(); + const std::string file_to_match = cmSystemTools::LowerCase(file); #else - const char* file_to_match = file; + const std::string& file_to_match = file; #endif // Collect properties from all matching rules. @@ -1143,14 +1139,13 @@ protected: return result; } - bool SetPermissions(const char* toFile, mode_t permissions) + bool SetPermissions(const std::string& toFile, mode_t permissions) { if (permissions) { #ifdef WIN32 if (Makefile->IsOn("CMAKE_CROSSCOMPILING")) { // Store the mode in an NTFS alternate stream. - std::string mode_t_adt_filename = - std::string(toFile) + ":cmake_mode_t"; + std::string mode_t_adt_filename = toFile + ":cmake_mode_t"; // Writing to an NTFS alternate stream changes the modification // time, so we need to save and restore its original value. @@ -1193,12 +1188,13 @@ protected: return true; } - bool InstallSymlink(const char* fromFile, const char* toFile); - bool InstallFile(const char* fromFile, const char* toFile, + bool InstallSymlink(const std::string& fromFile, const std::string& toFile); + bool InstallFile(const std::string& fromFile, const std::string& toFile, MatchProperties match_properties); - bool InstallDirectory(const char* source, const char* destination, + bool InstallDirectory(const std::string& source, + const std::string& destination, MatchProperties match_properties); - virtual bool Install(const char* fromFile, const char* toFile); + virtual bool Install(const std::string& fromFile, const std::string& toFile); virtual std::string const& ToName(std::string const& fromName) { return fromName; @@ -1210,8 +1206,8 @@ protected: TypeDir, TypeLink }; - virtual void ReportCopy(const char*, Type, bool) {} - virtual bool ReportMissing(const char* fromFile) + virtual void ReportCopy(const std::string&, Type, bool) {} + virtual bool ReportMissing(const std::string& fromFile) { // The input file does not exist and installation is not optional. std::ostringstream e; @@ -1555,16 +1551,17 @@ bool cmFileCopier::Run(std::vector<std::string> const& args) fromFile += fromName; } - if (!this->Install(fromFile.c_str(), toFile.c_str())) { + if (!this->Install(fromFile, toFile)) { return false; } } return true; } -bool cmFileCopier::Install(const char* fromFile, const char* toFile) +bool cmFileCopier::Install(const std::string& fromFile, + const std::string& toFile) { - if (!*fromFile) { + if (fromFile.empty()) { std::ostringstream e; e << "INSTALL encountered an empty string input file name."; this->FileCommand->SetError(e.str()); @@ -1594,7 +1591,8 @@ bool cmFileCopier::Install(const char* fromFile, const char* toFile) return this->ReportMissing(fromFile); } -bool cmFileCopier::InstallSymlink(const char* fromFile, const char* toFile) +bool cmFileCopier::InstallSymlink(const std::string& fromFile, + const std::string& toFile) { // Read the original symlink. std::string symlinkTarget; @@ -1641,7 +1639,8 @@ bool cmFileCopier::InstallSymlink(const char* fromFile, const char* toFile) return true; } -bool cmFileCopier::InstallFile(const char* fromFile, const char* toFile, +bool cmFileCopier::InstallFile(const std::string& fromFile, + const std::string& toFile, MatchProperties match_properties) { // Determine whether we will copy the file. @@ -1694,8 +1693,8 @@ bool cmFileCopier::InstallFile(const char* fromFile, const char* toFile, return this->SetPermissions(toFile, permissions); } -bool cmFileCopier::InstallDirectory(const char* source, - const char* destination, +bool cmFileCopier::InstallDirectory(const std::string& source, + const std::string& destination, MatchProperties match_properties) { // Inform the user about this directory installation. @@ -1752,7 +1751,7 @@ bool cmFileCopier::InstallDirectory(const char* source, // Load the directory contents to traverse it recursively. cmsys::Directory dir; - if (source && *source) { + if (!source.empty()) { dir.Load(source); } unsigned long numFiles = static_cast<unsigned long>(dir.GetNumberOfFiles()); @@ -1765,7 +1764,7 @@ bool cmFileCopier::InstallDirectory(const char* source, std::string toPath = destination; toPath += "/"; toPath += dir.GetFile(fileNum); - if (!this->Install(fromPath.c_str(), toPath.c_str())) { + if (!this->Install(fromPath, toPath)) { return false; } } @@ -1833,26 +1832,26 @@ protected: return this->Rename.empty() ? fromName : this->Rename; } - void ReportCopy(const char* toFile, Type type, bool copy) override + void ReportCopy(const std::string& toFile, Type type, bool copy) override { if (!this->MessageNever && (copy || !this->MessageLazy)) { std::string message = (copy ? "Installing: " : "Up-to-date: "); message += toFile; - this->Makefile->DisplayStatus(message.c_str(), -1); + this->Makefile->DisplayStatus(message, -1); } if (type != TypeDir) { // Add the file to the manifest. this->ManifestAppend(toFile); } } - bool ReportMissing(const char* fromFile) override + bool ReportMissing(const std::string& fromFile) override { return (this->Optional || this->cmFileCopier::ReportMissing(fromFile)); } - bool Install(const char* fromFile, const char* toFile) override + bool Install(const std::string& fromFile, const std::string& toFile) override { // Support installing from empty source to make a directory. - if (this->InstallType == cmInstallType_DIRECTORY && !*fromFile) { + if (this->InstallType == cmInstallType_DIRECTORY && fromFile.empty()) { return this->InstallDirectory(fromFile, toFile, MatchProperties()); } return this->cmFileCopier::Install(fromFile, toFile); @@ -2142,7 +2141,7 @@ bool cmFileCommand::HandleRPathChangeCommand( std::vector<std::string> const& args) { // Evaluate arguments. - const char* file = nullptr; + std::string file; const char* oldRPath = nullptr; const char* newRPath = nullptr; enum Doing @@ -2161,7 +2160,7 @@ bool cmFileCommand::HandleRPathChangeCommand( } else if (args[i] == "FILE") { doing = DoingFile; } else if (doing == DoingFile) { - file = args[i].c_str(); + file = args[i]; doing = DoingNone; } else if (doing == DoingOld) { oldRPath = args[i].c_str(); @@ -2176,7 +2175,7 @@ bool cmFileCommand::HandleRPathChangeCommand( return false; } } - if (!file) { + if (file.empty()) { this->SetError("RPATH_CHANGE not given FILE option."); return false; } @@ -2218,7 +2217,7 @@ bool cmFileCommand::HandleRPathChangeCommand( message += "\" to \""; message += newRPath; message += "\""; - this->Makefile->DisplayStatus(message.c_str(), -1); + this->Makefile->DisplayStatus(message, -1); } if (have_ft) { cmSystemTools::FileTimeSet(file, ft); @@ -2232,7 +2231,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( std::vector<std::string> const& args) { // Evaluate arguments. - const char* file = nullptr; + std::string file; enum Doing { DoingNone, @@ -2243,7 +2242,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( if (args[i] == "FILE") { doing = DoingFile; } else if (doing == DoingFile) { - file = args[i].c_str(); + file = args[i]; doing = DoingNone; } else { std::ostringstream e; @@ -2252,7 +2251,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( return false; } } - if (!file) { + if (file.empty()) { this->SetError("RPATH_REMOVE not given FILE option."); return false; } @@ -2282,7 +2281,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( std::string message = "Removed runtime path from \""; message += file; message += "\""; - this->Makefile->DisplayStatus(message.c_str(), -1); + this->Makefile->DisplayStatus(message, -1); } if (have_ft) { cmSystemTools::FileTimeSet(file, ft); @@ -2296,7 +2295,7 @@ bool cmFileCommand::HandleRPathCheckCommand( std::vector<std::string> const& args) { // Evaluate arguments. - const char* file = nullptr; + std::string file; const char* rpath = nullptr; enum Doing { @@ -2311,7 +2310,7 @@ bool cmFileCommand::HandleRPathCheckCommand( } else if (args[i] == "FILE") { doing = DoingFile; } else if (doing == DoingFile) { - file = args[i].c_str(); + file = args[i]; doing = DoingNone; } else if (doing == DoingRPath) { rpath = args[i].c_str(); @@ -2323,7 +2322,7 @@ bool cmFileCommand::HandleRPathCheckCommand( return false; } } - if (!file) { + if (file.empty()) { this->SetError("RPATH_CHECK not given FILE option."); return false; } @@ -2481,14 +2480,14 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args, { std::string message; - std::vector<std::string>::const_iterator i = args.begin(); - i++; // Get rid of subcommand - for (; i != args.end(); ++i) { - std::string fileName = *i; + for (std::string const& arg : + cmMakeRange(args).advance(1)) // Get rid of subcommand + { + std::string fileName = arg; if (!cmsys::SystemTools::FileIsFullPath(fileName)) { fileName = this->Makefile->GetCurrentSourceDirectory(); - fileName += "/" + *i; + fileName += "/" + arg; } if (cmSystemTools::FileIsDirectory(fileName) && @@ -2501,44 +2500,43 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args, return true; } +namespace { +std::string ToNativePath(const std::string& path) +{ + const auto& outPath = cmSystemTools::ConvertToOutputPath(path); + if (outPath.size() > 1 && outPath.front() == '\"' && + outPath.back() == '\"') { + return outPath.substr(1, outPath.size() - 2); + } + return outPath; +} + +std::string ToCMakePath(const std::string& path) +{ + auto temp = path; + cmSystemTools::ConvertToUnixSlashes(temp); + return temp; +} +} + bool cmFileCommand::HandleCMakePathCommand( std::vector<std::string> const& args, bool nativePath) { - std::vector<std::string>::const_iterator i = args.begin(); if (args.size() != 3) { this->SetError("FILE([TO_CMAKE_PATH|TO_NATIVE_PATH] path result) must be " "called with exactly three arguments."); return false; } - i++; // Get rid of subcommand #if defined(_WIN32) && !defined(__CYGWIN__) char pathSep = ';'; #else char pathSep = ':'; #endif - std::vector<std::string> path = cmSystemTools::SplitString(*i, pathSep); - i++; - const char* var = i->c_str(); - std::string value; - for (std::vector<std::string>::iterator j = path.begin(); j != path.end(); - ++j) { - if (j != path.begin()) { - value += ";"; - } - if (!nativePath) { - cmSystemTools::ConvertToUnixSlashes(*j); - } else { - *j = cmSystemTools::ConvertToOutputPath(*j); - // remove double quotes in the path - std::string& s = *j; + std::vector<std::string> path = cmSystemTools::SplitString(args[1], pathSep); - if (s.size() > 1 && s.front() == '\"' && s.back() == '\"') { - s = s.substr(1, s.size() - 2); - } - } - value += *j; - } - this->Makefile->AddDefinition(var, value.c_str()); + std::string value = cmJoin( + cmMakeRange(path).transform(nativePath ? ToNativePath : ToCMakePath), ";"); + this->Makefile->AddDefinition(args[2], value.c_str()); return true; } @@ -2651,7 +2649,7 @@ int cmFileDownloadProgressCallback(void* clientp, double dltotal, double dlnow, if (helper->UpdatePercentage(dlnow, dltotal, status)) { cmFileCommand* fc = helper->GetFileCommand(); cmMakefile* mf = fc->GetMakefile(); - mf->DisplayStatus(status.c_str(), -1); + mf->DisplayStatus(status, -1); } return 0; @@ -2669,7 +2667,7 @@ int cmFileUploadProgressCallback(void* clientp, double dltotal, double dlnow, if (helper->UpdatePercentage(ulnow, ultotal, status)) { cmFileCommand* fc = helper->GetFileCommand(); cmMakefile* mf = fc->GetMakefile(); - mf->DisplayStatus(status.c_str(), -1); + mf->DisplayStatus(status, -1); } return 0; @@ -2693,6 +2691,9 @@ public: } } + cURLEasyGuard(const cURLEasyGuard&) = delete; + cURLEasyGuard& operator=(const cURLEasyGuard&) = delete; + void release() { this->Easy = nullptr; } private: @@ -3067,7 +3068,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) if (!logVar.empty()) { chunkDebug.push_back(0); - this->Makefile->AddDefinition(logVar, &*chunkDebug.begin()); + this->Makefile->AddDefinition(logVar, chunkDebug.data()); } return true; @@ -3326,14 +3327,14 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) if (!chunkResponse.empty()) { chunkResponse.push_back(0); log += "Response:\n"; - log += &*chunkResponse.begin(); + log += chunkResponse.data(); log += "\n"; } if (!chunkDebug.empty()) { chunkDebug.push_back(0); log += "Debug:\n"; - log += &*chunkDebug.begin(); + log += chunkDebug.data(); log += "\n"; } @@ -3758,7 +3759,7 @@ bool cmFileCommand::HandleCreateLinkCommand( // Check if copy-on-error is enabled in the arguments. if (!completed && copyOnErrorArg.IsEnabled()) { - completed = cmSystemTools::cmCopyFile(fileName, newFileName); + completed = cmsys::SystemTools::CopyFileAlways(fileName, newFileName); if (!completed) { result = "Copy failed: " + cmSystemTools::GetLastSystemError(); } diff --git a/Source/cmFilePathChecksum.cxx b/Source/cmFilePathChecksum.cxx index 2cffa7c..47a223a 100644 --- a/Source/cmFilePathChecksum.cxx +++ b/Source/cmFilePathChecksum.cxx @@ -74,7 +74,7 @@ std::string cmFilePathChecksum::get(std::string const& filePath) const cmCryptoHash(cmCryptoHash::AlgoSHA256).ByteHashString(relSeed + relPath); // Convert binary checksum to string - return cmBase32Encoder().encodeString(&hashBytes.front(), hashBytes.size(), + return cmBase32Encoder().encodeString(hashBytes.data(), hashBytes.size(), false); } diff --git a/Source/cmFileTimeComparison.h b/Source/cmFileTimeComparison.h index 5f74e34..b4e4eb3 100644 --- a/Source/cmFileTimeComparison.h +++ b/Source/cmFileTimeComparison.h @@ -20,6 +20,9 @@ public: cmFileTimeComparison(); ~cmFileTimeComparison(); + cmFileTimeComparison(const cmFileTimeComparison&) = delete; + cmFileTimeComparison& operator=(const cmFileTimeComparison&) = delete; + /** * Compare file modification times. * Return true for successful comparison and false for error. diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 425546a..2e5e29c 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -4,12 +4,12 @@ #include <deque> #include <iostream> -#include <iterator> #include <map> #include <stddef.h> #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmSearchPath.h" #include "cmState.h" #include "cmStateTypes.h" @@ -205,11 +205,9 @@ void cmFindBase::FillPackageRootPath() cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot]; // Add the PACKAGE_ROOT_PATH from each enclosing find_package call. - for (std::deque<std::vector<std::string>>::const_reverse_iterator pkgPaths = - this->Makefile->FindPackageRootPathStack.rbegin(); - pkgPaths != this->Makefile->FindPackageRootPathStack.rend(); - ++pkgPaths) { - paths.AddPrefixPaths(*pkgPaths); + for (std::vector<std::string> const& pkgPaths : + cmReverseRange(this->Makefile->FindPackageRootPathStack)) { + paths.AddPrefixPaths(pkgPaths); } paths.AddSuffixes(this->SearchPathSuffixes); diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 78be64e..9aaa000 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -310,7 +310,7 @@ void cmFindCommon::AddPathSuffix(std::string const& arg) void AddTrailingSlash(std::string& s) { - if (!s.empty() && *s.rbegin() != '/') { + if (!s.empty() && s.back() != '/') { s += '/'; } } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index c2e0712..7ebd211 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -23,6 +23,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmSearchPath.h" #include "cmState.h" #include "cmStateTypes.h" @@ -466,7 +467,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, // Allocate a PACKAGE_ROOT_PATH for the current find_package call. this->Makefile->FindPackageRootPathStack.emplace_back(); std::vector<std::string>& rootPaths = - *this->Makefile->FindPackageRootPathStack.rbegin(); + this->Makefile->FindPackageRootPathStack.back(); // Add root paths from <PackageName>_ROOT CMake and environment variables, // subject to CMP0074. @@ -827,10 +828,10 @@ bool cmFindPackageCommand::HandlePackageMode() << " requested version \"" << this->Version << "\".\n" << "The following configuration files were considered but not " "accepted:\n"; - for (std::vector<ConfigFileInfo>::const_iterator i = - this->ConsideredConfigs.begin(); - i != duplicate_end; ++i) { - e << " " << i->filename << ", version: " << i->version << "\n"; + + for (ConfigFileInfo const& info : + cmMakeRange(this->ConsideredConfigs.cbegin(), duplicate_end)) { + e << " " << info.filename << ", version: " << info.version << "\n"; } } else { std::string requestedVersionString; @@ -911,7 +912,7 @@ bool cmFindPackageCommand::HandlePackageMode() std::ostringstream aw; aw << "Could NOT find " << this->Name << " (missing: " << this->Name << "_DIR)"; - this->Makefile->DisplayStatus(aw.str().c_str(), -1); + this->Makefile->DisplayStatus(aw.str(), -1); } } @@ -1372,6 +1373,9 @@ public: cmSystemTools::RemoveFile(this->File); } } + cmFindPackageCommandHoldFile(const cmFindPackageCommandHoldFile&) = delete; + cmFindPackageCommandHoldFile& operator=( + const cmFindPackageCommandHoldFile&) = delete; void Release() { this->File = nullptr; } }; diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx index e359def..08003eb 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -11,6 +11,7 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmRange.h" #include "cmSystemTools.h" cmForEachFunctionBlocker::cmForEachFunctionBlocker(cmMakefile* mf) @@ -48,12 +49,10 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, if (mf.GetDefinition(this->Args[0])) { oldDef = mf.GetDefinition(this->Args[0]); } - std::vector<std::string>::const_iterator j = this->Args.begin(); - ++j; - for (; j != this->Args.end(); ++j) { + for (std::string const& arg : cmMakeRange(this->Args).advance(1)) { // set the variable to the loop value - mf.AddDefinition(this->Args[0], j->c_str()); + mf.AddDefinition(this->Args[0], arg.c_str()); // Invoke all the functions that were collected in the block. cmExecutionStatus status; for (cmListFileFunction const& func : this->Functions) { diff --git a/Source/cmFortranParser.h b/Source/cmFortranParser.h index 0762340..6a33be5 100644 --- a/Source/cmFortranParser.h +++ b/Source/cmFortranParser.h @@ -141,6 +141,9 @@ struct cmFortranParser_s std::set<std::string> defines, cmFortranSourceInfo& info); ~cmFortranParser_s(); + cmFortranParser_s(const cmFortranParser_s&) = delete; + cmFortranParser_s& operator=(const cmFortranParser_s&) = delete; + bool FindIncludeFile(const char* dir, const char* includeName, std::string& fileName); diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 264a338..9d75b72 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -8,6 +8,7 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmState.h" // define the class for function commands diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 4fe1587..2f47788 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -29,8 +29,7 @@ cmGeneratedFileStream::cmGeneratedFileStream(std::string const& name, { // Check if the file opened. if (!*this && !quiet) { - cmSystemTools::Error("Cannot open file for write: ", - this->TempName.c_str()); + cmSystemTools::Error("Cannot open file for write: " + this->TempName); cmSystemTools::ReportLastSystemError(""); } #ifdef CMAKE_BUILD_WITH_CMAKE @@ -68,8 +67,7 @@ cmGeneratedFileStream& cmGeneratedFileStream::Open(std::string const& name, // Check if the file opened. if (!*this && !quiet) { - cmSystemTools::Error("Cannot open file for write: ", - this->TempName.c_str()); + cmSystemTools::Error("Cannot open file for write: " + this->TempName); cmSystemTools::ReportLastSystemError(""); } return *this; diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index f9a6d64..268de6f 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -34,20 +34,16 @@ std::string GeneratorExpressionContent::ProcessArbitraryContent( std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator pend = this->ParamChildren.end(); for (; pit != pend; ++pit) { - std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it = - pit->begin(); - const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end = - pit->end(); - for (; it != end; ++it) { + for (cmGeneratorExpressionEvaluator* pExprEval : *pit) { if (node->RequiresLiteralInput()) { - if ((*it)->GetType() != cmGeneratorExpressionEvaluator::Text) { + if (pExprEval->GetType() != cmGeneratorExpressionEvaluator::Text) { reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires literal input."); return std::string(); } } - result += (*it)->Evaluate(context, dagChecker); + result += pExprEval->Evaluate(context, dagChecker); if (context->HadError) { return std::string(); } @@ -70,12 +66,9 @@ std::string GeneratorExpressionContent::Evaluate( { std::string identifier; { - std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it = - this->IdentifierChildren.begin(); - const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end = - this->IdentifierChildren.end(); - for (; it != end; ++it) { - identifier += (*it)->Evaluate(context, dagChecker); + for (cmGeneratorExpressionEvaluator* pExprEval : + this->IdentifierChildren) { + identifier += pExprEval->Evaluate(context, dagChecker); if (context->HadError) { return std::string(); } @@ -138,12 +131,8 @@ std::string GeneratorExpressionContent::EvaluateParameters( return std::string(); } std::string parameter; - std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it = - pit->begin(); - const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end = - pit->end(); - for (; it != end; ++it) { - parameter += (*it)->Evaluate(context, dagChecker); + for (cmGeneratorExpressionEvaluator* pExprEval : *pit) { + parameter += pExprEval->Evaluate(context, dagChecker); if (context->HadError) { return std::string(); } diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 70c80c9..ce308cc 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -103,13 +103,11 @@ static const struct ZeroNode installInterfaceNode; const GeneratorExpressionContent* content, \ cmGeneratorExpressionDAGChecker*) const \ { \ - std::vector<std::string>::const_iterator it = parameters.begin(); \ - const std::vector<std::string>::const_iterator end = parameters.end(); \ - for (; it != end; ++it) { \ - if (*it == #FAILURE_VALUE) { \ + for (std::string const& param : parameters) { \ + if (param == #FAILURE_VALUE) { \ return #FAILURE_VALUE; \ } \ - if (*it != #SUCCESS_VALUE) { \ + if (param != #SUCCESS_VALUE) { \ reportError(context, content->GetOriginalExpression(), \ "Parameters to $<" #OP \ "> must resolve to either '0' or '1'."); \ @@ -135,13 +133,13 @@ static const struct NotNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { - if (*parameters.begin() != "0" && *parameters.begin() != "1") { + if (parameters.front() != "0" && parameters.front() != "1") { reportError( context, content->GetOriginalExpression(), "$<NOT> parameter must resolve to exactly one '0' or '1' value."); return std::string(); } - return *parameters.begin() == "0" ? "1" : "0"; + return parameters.front() == "0" ? "1" : "0"; } } notNode; @@ -157,7 +155,7 @@ static const struct BoolNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* /*content*/, cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { - return !cmSystemTools::IsOff(*parameters.begin()) ? "1" : "0"; + return !cmSystemTools::IsOff(parameters.front()) ? "1" : "0"; } } boolNode; @@ -194,7 +192,7 @@ static const struct StrEqualNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* /*content*/, cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { - return *parameters.begin() == parameters[1] ? "1" : "0"; + return parameters.front() == parameters[1] ? "1" : "0"; } } strEqualNode; @@ -613,7 +611,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode return compilerId; } static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$"); - if (!compilerIdValidator.find(*parameters.begin())) { + if (!compilerIdValidator.find(parameters.front())) { reportError(context, content->GetOriginalExpression(), "Expression syntax not recognized."); return std::string(); @@ -622,11 +620,11 @@ struct CompilerIdNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - if (strcmp(parameters.begin()->c_str(), compilerId.c_str()) == 0) { + if (strcmp(parameters.front().c_str(), compilerId.c_str()) == 0) { return "1"; } - if (cmsysString_strcasecmp(parameters.begin()->c_str(), + if (cmsysString_strcasecmp(parameters.front().c_str(), compilerId.c_str()) == 0) { switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) { case cmPolicies::WARN: { @@ -734,7 +732,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode } static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$"); - if (!compilerIdValidator.find(*parameters.begin())) { + if (!compilerIdValidator.find(parameters.front())) { reportError(context, content->GetOriginalExpression(), "Expression syntax not recognized."); return std::string(); @@ -744,7 +742,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode } return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL, - parameters.begin()->c_str(), + parameters.front().c_str(), compilerVersion.c_str()) ? "1" : "0"; @@ -839,7 +837,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - if (*parameters.begin() == platformId) { + if (parameters.front() == platformId) { return "1"; } return "0"; @@ -1001,7 +999,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode return configurationNode.Evaluate(parameters, context, content, nullptr); } static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$"); - if (!configValidator.find(*parameters.begin())) { + if (!configValidator.find(parameters.front())) { reportError(context, content->GetOriginalExpression(), "Expression syntax not recognized."); return std::string(); @@ -1011,7 +1009,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - if (cmsysString_strcasecmp(parameters.begin()->c_str(), + if (cmsysString_strcasecmp(parameters.front().c_str(), context->Config.c_str()) == 0) { return "1"; } @@ -1166,7 +1164,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$"); cmGeneratorTarget const* target = context->HeadTarget; - std::string propertyName = *parameters.begin(); + std::string propertyName = parameters.front(); if (parameters.size() == 1) { context->HadHeadSensitiveCondition = true; @@ -1182,14 +1180,14 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode } if (parameters.size() == 2) { - if (parameters.begin()->empty() && parameters[1].empty()) { + if (parameters.front().empty() && parameters[1].empty()) { reportError( context, content->GetOriginalExpression(), "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty " "target name and property name."); return std::string(); } - if (parameters.begin()->empty()) { + if (parameters.front().empty()) { reportError( context, content->GetOriginalExpression(), "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty " @@ -1964,7 +1962,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode cmGeneratorExpressionDAGChecker* dagChecker) const override { // Lookup the referenced target. - std::string name = *parameters.begin(); + std::string name = parameters.front(); if (!cmGeneratorExpression::IsValidTargetName(name)) { ::reportError(context, content->GetOriginalExpression(), @@ -2060,75 +2058,76 @@ static const struct ShellPathNode : public cmGeneratorExpressionNode const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( const std::string& identifier) { - typedef std::map<std::string, const cmGeneratorExpressionNode*> NodeMap; - static NodeMap nodeMap; - if (nodeMap.empty()) { - nodeMap["0"] = &zeroNode; - nodeMap["1"] = &oneNode; - nodeMap["AND"] = &andNode; - nodeMap["OR"] = &orNode; - nodeMap["NOT"] = ¬Node; - nodeMap["C_COMPILER_ID"] = &cCompilerIdNode; - nodeMap["CXX_COMPILER_ID"] = &cxxCompilerIdNode; - nodeMap["Fortran_COMPILER_ID"] = &fortranCompilerIdNode; - nodeMap["VERSION_GREATER"] = &versionGreaterNode; - nodeMap["VERSION_GREATER_EQUAL"] = &versionGreaterEqNode; - nodeMap["VERSION_LESS"] = &versionLessNode; - nodeMap["VERSION_LESS_EQUAL"] = &versionLessEqNode; - nodeMap["VERSION_EQUAL"] = &versionEqualNode; - nodeMap["C_COMPILER_VERSION"] = &cCompilerVersionNode; - nodeMap["CXX_COMPILER_VERSION"] = &cxxCompilerVersionNode; - nodeMap["Fortran_COMPILER_VERSION"] = &fortranCompilerVersionNode; - nodeMap["PLATFORM_ID"] = &platformIdNode; - nodeMap["COMPILE_FEATURES"] = &compileFeaturesNode; - nodeMap["CONFIGURATION"] = &configurationNode; - nodeMap["CONFIG"] = &configurationTestNode; - nodeMap["TARGET_FILE"] = &targetNodeGroup.File; - nodeMap["TARGET_LINKER_FILE"] = &targetLinkerNodeGroup.File; - nodeMap["TARGET_SONAME_FILE"] = &targetSoNameNodeGroup.File; - nodeMap["TARGET_PDB_FILE"] = &targetPdbNodeGroup.File; - nodeMap["TARGET_FILE_NAME"] = &targetNodeGroup.FileName; - nodeMap["TARGET_LINKER_FILE_NAME"] = &targetLinkerNodeGroup.FileName; - nodeMap["TARGET_SONAME_FILE_NAME"] = &targetSoNameNodeGroup.FileName; - nodeMap["TARGET_PDB_FILE_NAME"] = &targetPdbNodeGroup.FileName; - nodeMap["TARGET_FILE_DIR"] = &targetNodeGroup.FileDir; - nodeMap["TARGET_LINKER_FILE_DIR"] = &targetLinkerNodeGroup.FileDir; - nodeMap["TARGET_SONAME_FILE_DIR"] = &targetSoNameNodeGroup.FileDir; - nodeMap["TARGET_PDB_FILE_DIR"] = &targetPdbNodeGroup.FileDir; - nodeMap["TARGET_BUNDLE_DIR"] = &targetBundleDirNode; - nodeMap["TARGET_BUNDLE_CONTENT_DIR"] = &targetBundleContentDirNode; - nodeMap["STREQUAL"] = &strEqualNode; - nodeMap["EQUAL"] = &equalNode; - nodeMap["IN_LIST"] = &inListNode; - nodeMap["LOWER_CASE"] = &lowerCaseNode; - nodeMap["UPPER_CASE"] = &upperCaseNode; - nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode; - nodeMap["BOOL"] = &boolNode; - nodeMap["IF"] = &ifNode; - nodeMap["ANGLE-R"] = &angle_rNode; - nodeMap["COMMA"] = &commaNode; - nodeMap["SEMICOLON"] = &semicolonNode; - nodeMap["TARGET_PROPERTY"] = &targetPropertyNode; - nodeMap["TARGET_NAME"] = &targetNameNode; - nodeMap["TARGET_OBJECTS"] = &targetObjectsNode; - nodeMap["TARGET_POLICY"] = &targetPolicyNode; - nodeMap["TARGET_EXISTS"] = &targetExistsNode; - nodeMap["TARGET_NAME_IF_EXISTS"] = &targetNameIfExistsNode; - nodeMap["TARGET_GENEX_EVAL"] = &targetGenexEvalNode; - nodeMap["GENEX_EVAL"] = &genexEvalNode; - nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode; - nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode; - nodeMap["INSTALL_PREFIX"] = &installPrefixNode; - nodeMap["JOIN"] = &joinNode; - nodeMap["LINK_ONLY"] = &linkOnlyNode; - nodeMap["COMPILE_LANGUAGE"] = &languageNode; - nodeMap["SHELL_PATH"] = &shellPathNode; - } - NodeMap::const_iterator i = nodeMap.find(identifier); - if (i == nodeMap.end()) { - return nullptr; + static std::map<std::string, cmGeneratorExpressionNode const*> const nodeMap{ + { "0", &zeroNode }, + { "1", &oneNode }, + { "AND", &andNode }, + { "OR", &orNode }, + { "NOT", ¬Node }, + { "C_COMPILER_ID", &cCompilerIdNode }, + { "CXX_COMPILER_ID", &cxxCompilerIdNode }, + { "Fortran_COMPILER_ID", &fortranCompilerIdNode }, + { "VERSION_GREATER", &versionGreaterNode }, + { "VERSION_GREATER_EQUAL", &versionGreaterEqNode }, + { "VERSION_LESS", &versionLessNode }, + { "VERSION_LESS_EQUAL", &versionLessEqNode }, + { "VERSION_EQUAL", &versionEqualNode }, + { "C_COMPILER_VERSION", &cCompilerVersionNode }, + { "CXX_COMPILER_VERSION", &cxxCompilerVersionNode }, + { "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode }, + { "PLATFORM_ID", &platformIdNode }, + { "COMPILE_FEATURES", &compileFeaturesNode }, + { "CONFIGURATION", &configurationNode }, + { "CONFIG", &configurationTestNode }, + { "TARGET_FILE", &targetNodeGroup.File }, + { "TARGET_LINKER_FILE", &targetLinkerNodeGroup.File }, + { "TARGET_SONAME_FILE", &targetSoNameNodeGroup.File }, + { "TARGET_PDB_FILE", &targetPdbNodeGroup.File }, + { "TARGET_FILE_NAME", &targetNodeGroup.FileName }, + { "TARGET_LINKER_FILE_NAME", &targetLinkerNodeGroup.FileName }, + { "TARGET_SONAME_FILE_NAME", &targetSoNameNodeGroup.FileName }, + { "TARGET_PDB_FILE_NAME", &targetPdbNodeGroup.FileName }, + { "TARGET_FILE_DIR", &targetNodeGroup.FileDir }, + { "TARGET_LINKER_FILE_DIR", &targetLinkerNodeGroup.FileDir }, + { "TARGET_SONAME_FILE_DIR", &targetSoNameNodeGroup.FileDir }, + { "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir }, + { "TARGET_BUNDLE_DIR", &targetBundleDirNode }, + { "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode }, + { "STREQUAL", &strEqualNode }, + { "EQUAL", &equalNode }, + { "IN_LIST", &inListNode }, + { "LOWER_CASE", &lowerCaseNode }, + { "UPPER_CASE", &upperCaseNode }, + { "MAKE_C_IDENTIFIER", &makeCIdentifierNode }, + { "BOOL", &boolNode }, + { "IF", &ifNode }, + { "ANGLE-R", &angle_rNode }, + { "COMMA", &commaNode }, + { "SEMICOLON", &semicolonNode }, + { "TARGET_PROPERTY", &targetPropertyNode }, + { "TARGET_NAME", &targetNameNode }, + { "TARGET_OBJECTS", &targetObjectsNode }, + { "TARGET_POLICY", &targetPolicyNode }, + { "TARGET_EXISTS", &targetExistsNode }, + { "TARGET_NAME_IF_EXISTS", &targetNameIfExistsNode }, + { "TARGET_GENEX_EVAL", &targetGenexEvalNode }, + { "GENEX_EVAL", &genexEvalNode }, + { "BUILD_INTERFACE", &buildInterfaceNode }, + { "INSTALL_INTERFACE", &installInterfaceNode }, + { "INSTALL_PREFIX", &installPrefixNode }, + { "JOIN", &joinNode }, + { "LINK_ONLY", &linkOnlyNode }, + { "COMPILE_LANGUAGE", &languageNode }, + { "SHELL_PATH", &shellPathNode } + }; + + { + auto itr = nodeMap.find(identifier); + if (itr != nodeMap.end()) { + return itr->second; + } } - return i->second; + return nullptr; } void reportError(cmGeneratorExpressionContext* context, diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index 949a86d..7aa3314 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -47,11 +47,11 @@ static void extendResult( if (!result.empty() && (*(result.end() - 1))->GetType() == cmGeneratorExpressionEvaluator::Text && - (*contents.begin())->GetType() == cmGeneratorExpressionEvaluator::Text) { + contents.front()->GetType() == cmGeneratorExpressionEvaluator::Text) { TextContent* textContent = static_cast<TextContent*>(*(result.end() - 1)); textContent->Extend( - static_cast<TextContent*>(*contents.begin())->GetLength()); - delete *contents.begin(); + static_cast<TextContent*>(contents.front())->GetLength()); + delete contents.front(); result.insert(result.end(), contents.begin() + 1, contents.end()); } else { result.insert(result.end(), contents.begin(), contents.end()); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 78040c3..624333c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -28,6 +28,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPropertyMap.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmState.h" @@ -510,21 +511,10 @@ const char* cmGeneratorTarget::GetLinkPIEProperty( return nullptr; } - switch (this->GetPolicyStatusCMP0083()) { - case cmPolicies::WARN: { - std::ostringstream e; - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0083); - this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); - CM_FALLTHROUGH; - } - case cmPolicies::OLD: - return nullptr; - default: - // nothing to do - break; - } - - return PICValue.c_str(); + auto status = this->GetPolicyStatusCMP0083(); + return (status != cmPolicies::WARN && status != cmPolicies::OLD) + ? PICValue.c_str() + : nullptr; } bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang, @@ -1617,13 +1607,7 @@ std::string cmGeneratorTarget::GetSOName(const std::string& config) const return ""; } // Compute the soname that will be built. - std::string name; - std::string soName; - std::string realName; - std::string impName; - std::string pdbName; - this->GetLibraryNames(name, soName, realName, impName, pdbName, config); - return soName; + return this->GetLibraryNames(config).SharedObject; } static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level) @@ -2389,7 +2373,7 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) std::set<cmGeneratorTarget*> targets; for (cmCustomCommandLine const& cCmdLine : cc.GetCommandLines()) { - std::string const& command = *cCmdLine.begin(); + std::string const& command = cCmdLine.front(); // Check for a target with this name. if (cmGeneratorTarget* t = this->LocalGenerator->FindGeneratorTargetToUse(command)) { @@ -3394,17 +3378,13 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator(); // Get the names. - std::string name; - std::string soName; - std::string realName; - std::string impName; - std::string pdbName; + cmGeneratorTarget::Names targetNames; if (this->GetType() == cmStateEnums::EXECUTABLE) { - this->GetExecutableNames(name, realName, impName, pdbName, config); + targetNames = this->GetExecutableNames(config); } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY || this->GetType() == cmStateEnums::SHARED_LIBRARY || this->GetType() == cmStateEnums::MODULE_LIBRARY) { - this->GetLibraryNames(name, soName, realName, impName, pdbName, config); + targetNames = this->GetLibraryNames(config); } else { return; } @@ -3415,34 +3395,34 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const // Add each name. std::string f; - if (!name.empty()) { + if (!targetNames.Output.empty()) { f = dir; f += "/"; - f += name; + f += targetNames.Output; gg->AddToManifest(f); } - if (!soName.empty()) { + if (!targetNames.SharedObject.empty()) { f = dir; f += "/"; - f += soName; + f += targetNames.SharedObject; gg->AddToManifest(f); } - if (!realName.empty()) { + if (!targetNames.Real.empty()) { f = dir; f += "/"; - f += realName; + f += targetNames.Real; gg->AddToManifest(f); } - if (!pdbName.empty()) { + if (!targetNames.PDB.empty()) { f = dir; f += "/"; - f += pdbName; + f += targetNames.PDB; gg->AddToManifest(f); } - if (!impName.empty()) { + if (!targetNames.ImportLibrary.empty()) { f = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact); f += "/"; - f += impName; + f += targetNames.ImportLibrary; gg->AddToManifest(f); } } @@ -3520,29 +3500,17 @@ std::string cmGeneratorTarget::NormalGetRealName( if (this->GetType() == cmStateEnums::EXECUTABLE) { // Compute the real name that will be built. - std::string name; - std::string realName; - std::string impName; - std::string pdbName; - this->GetExecutableNames(name, realName, impName, pdbName, config); - return realName; + return this->GetExecutableNames(config).Real; } // Compute the real name that will be built. - std::string name; - std::string soName; - std::string realName; - std::string impName; - std::string pdbName; - this->GetLibraryNames(name, soName, realName, impName, pdbName, config); - return realName; -} - -void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName, - std::string& realName, - std::string& impName, - std::string& pdbName, - const std::string& config) const + return this->GetLibraryNames(config).Real; +} + +cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames( + const std::string& config) const { + cmGeneratorTarget::Names targetNames; + // This should not be called for imported targets. // TODO: Split cmTarget into a class hierarchy to get compile-time // enforcement of the limited imported target API. @@ -3550,7 +3518,6 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName, std::string msg = "GetLibraryNames called on imported target: "; msg += this->GetName(); this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); - return; } // Check for library version properties. @@ -3576,50 +3543,51 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName, // Get the components of the library name. std::string prefix; - std::string base; std::string suffix; this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact, - prefix, base, suffix); + prefix, targetNames.Base, suffix); // The library name. - name = prefix + base + suffix; + targetNames.Output = prefix + targetNames.Base + suffix; if (this->IsFrameworkOnApple()) { - realName = prefix; + targetNames.Real = prefix; if (!this->Makefile->PlatformIsAppleEmbedded()) { - realName += "Versions/"; - realName += this->GetFrameworkVersion(); - realName += "/"; + targetNames.Real += "Versions/"; + targetNames.Real += this->GetFrameworkVersion(); + targetNames.Real += "/"; } - realName += base; - soName = realName; + targetNames.Real += targetNames.Base; + targetNames.SharedObject = targetNames.Real; } else { // The library's soname. - this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion); + this->ComputeVersionedName(targetNames.SharedObject, prefix, + targetNames.Base, suffix, targetNames.Output, + soversion); // The library's real name on disk. - this->ComputeVersionedName(realName, prefix, base, suffix, name, version); + this->ComputeVersionedName(targetNames.Real, prefix, targetNames.Base, + suffix, targetNames.Output, version); } // The import library name. if (this->GetType() == cmStateEnums::SHARED_LIBRARY || this->GetType() == cmStateEnums::MODULE_LIBRARY) { - impName = + targetNames.ImportLibrary = this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact); - } else { - impName.clear(); } // The program database file name. - pdbName = this->GetPDBName(config); + targetNames.PDB = this->GetPDBName(config); + + return targetNames; } -void cmGeneratorTarget::GetExecutableNames(std::string& name, - std::string& realName, - std::string& impName, - std::string& pdbName, - const std::string& config) const +cmGeneratorTarget::Names cmGeneratorTarget::GetExecutableNames( + const std::string& config) const { + cmGeneratorTarget::Names targetNames; + // This should not be called for imported targets. // TODO: Split cmTarget into a class hierarchy to get compile-time // enforcement of the limited imported target API. @@ -3644,34 +3612,35 @@ void cmGeneratorTarget::GetExecutableNames(std::string& name, // Get the components of the executable name. std::string prefix; - std::string base; std::string suffix; this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact, - prefix, base, suffix); + prefix, targetNames.Base, suffix); // The executable name. - name = prefix + base + suffix; + targetNames.Output = prefix + targetNames.Base + suffix; // The executable's real name on disk. #if defined(__CYGWIN__) - realName = prefix + base; + targetNames.Real = prefix + targetNames.Base; #else - realName = name; + targetNames.Real = targetNames.Output; #endif if (version) { - realName += "-"; - realName += version; + targetNames.Real += "-"; + targetNames.Real += version; } #if defined(__CYGWIN__) - realName += suffix; + targetNames.Real += suffix; #endif // The import library name. - impName = + targetNames.ImportLibrary = this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact); // The program database file name. - pdbName = this->GetPDBName(config); + targetNames.PDB = this->GetPDBName(config); + + return targetNames; } std::string cmGeneratorTarget::GetFullNameInternal( diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 59d38af..bc966e1 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -568,19 +568,25 @@ public: void GetAutoUicOptions(std::vector<std::string>& result, const std::string& config) const; + struct Names + { + std::string Base; + std::string Output; + std::string Real; + std::string ImportLibrary; + std::string PDB; + std::string SharedObject; + }; + /** Get the names of the executable needed to generate a build rule that takes into account executable version numbers. This should be called only on an executable target. */ - void GetExecutableNames(std::string& name, std::string& realName, - std::string& impName, std::string& pdbName, - const std::string& config) const; + Names GetExecutableNames(const std::string& config) const; /** Get the names of the library needed to generate a build rule that takes into account shared library version numbers. This should be called only on a library target. */ - void GetLibraryNames(std::string& name, std::string& soName, - std::string& realName, std::string& impName, - std::string& pdbName, const std::string& config) const; + Names GetLibraryNames(const std::string& config) const; /** * Compute whether this target must be relinked before installing. diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 5fe350c..9f8f12b 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -40,12 +40,8 @@ void cmGhsMultiTargetGenerator::Generate() switch (this->GeneratorTarget->GetType()) { case cmStateEnums::EXECUTABLE: { // Get the name of the executable to generate. - std::string targetName; - std::string targetNameImport; - std::string targetNamePDB; - this->GeneratorTarget->GetExecutableNames( - targetName, this->TargetNameReal, targetNameImport, targetNamePDB, - this->ConfigName); + this->TargetNameReal = + this->GeneratorTarget->GetExecutableNames(this->ConfigName).Real; if (cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()) { this->TagType = GhsMultiGpj::INTERGRITY_APPLICATION; } else { @@ -54,13 +50,8 @@ void cmGhsMultiTargetGenerator::Generate() break; } case cmStateEnums::STATIC_LIBRARY: { - std::string targetName; - std::string targetNameSO; - std::string targetNameImport; - std::string targetNamePDB; - this->GeneratorTarget->GetLibraryNames( - targetName, targetNameSO, this->TargetNameReal, targetNameImport, - targetNamePDB, this->ConfigName); + this->TargetNameReal = + this->GeneratorTarget->GetLibraryNames(this->ConfigName).Real; this->TagType = GhsMultiGpj::LIBRARY; break; } @@ -71,13 +62,8 @@ void cmGhsMultiTargetGenerator::Generate() return; } case cmStateEnums::OBJECT_LIBRARY: { - std::string targetName; - std::string targetNameSO; - std::string targetNameImport; - std::string targetNamePDB; - this->GeneratorTarget->GetLibraryNames( - targetName, targetNameSO, this->TargetNameReal, targetNameImport, - targetNamePDB, this->ConfigName); + this->TargetNameReal = + this->GeneratorTarget->GetLibraryNames(this->ConfigName).Real; this->TagType = GhsMultiGpj::SUBPROJECT; break; } @@ -224,7 +210,7 @@ void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout, if (flagsByLangI != this->FlagsByLanguage.end()) { if (!flagsByLangI->second.empty()) { std::vector<std::string> ghsCompFlags = - cmSystemTools::ParseArguments(flagsByLangI->second.c_str()); + cmSystemTools::ParseArguments(flagsByLangI->second); for (auto& f : ghsCompFlags) { fout << " " << f << std::endl; } @@ -238,10 +224,8 @@ void cmGhsMultiTargetGenerator::WriteCompilerDefinitions( std::vector<std::string> compileDefinitions; this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, config, language); - for (std::vector<std::string>::const_iterator cdI = - compileDefinitions.begin(); - cdI != compileDefinitions.end(); ++cdI) { - fout << " -D" << (*cdI) << std::endl; + for (std::string const& compileDefinition : compileDefinitions) { + fout << " -D" << compileDefinition << std::endl; } } @@ -253,9 +237,8 @@ void cmGhsMultiTargetGenerator::WriteIncludes(std::ostream& fout, this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget, language, config); - for (std::vector<std::string>::const_iterator includes_i = includes.begin(); - includes_i != includes.end(); ++includes_i) { - fout << " -I\"" << *includes_i << "\"" << std::endl; + for (std::string const& include : includes) { + fout << " -I\"" << include << "\"" << std::endl; } } @@ -282,16 +265,14 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout, frameworkPath, linkPath, this->GeneratorTarget); // write out link options - std::vector<std::string> lopts = - cmSystemTools::ParseArguments(linkFlags.c_str()); + std::vector<std::string> lopts = cmSystemTools::ParseArguments(linkFlags); for (auto& l : lopts) { fout << " " << l << std::endl; } // write out link search paths // must be quoted for paths that contain spaces - std::vector<std::string> lpath = - cmSystemTools::ParseArguments(linkPath.c_str()); + std::vector<std::string> lpath = cmSystemTools::ParseArguments(linkPath); for (auto& l : lpath) { fout << " -L\"" << l << "\"" << std::endl; } @@ -301,7 +282,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout, std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory(); std::vector<std::string> llibs = - cmSystemTools::ParseArguments(linkLibraries.c_str()); + cmSystemTools::ParseArguments(linkLibraries); for (auto& l : llibs) { if (l.compare(0, 2, "-l") == 0) { fout << " \"" << l << "\"" << std::endl; @@ -324,12 +305,9 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper( std::ostream& fout, std::vector<cmCustomCommand> const& commandsSet, cmTarget::CustomCommandType const commandType) { - for (std::vector<cmCustomCommand>::const_iterator commandsSetI = - commandsSet.begin(); - commandsSetI != commandsSet.end(); ++commandsSetI) { - cmCustomCommandLines const& commands = commandsSetI->GetCommandLines(); - for (cmCustomCommandLines::const_iterator commandI = commands.begin(); - commandI != commands.end(); ++commandI) { + for (cmCustomCommand const& customCommand : commandsSet) { + cmCustomCommandLines const& commandLines = customCommand.GetCommandLines(); + for (cmCustomCommandLine const& command : commandLines) { switch (commandType) { case cmTarget::PRE_BUILD: fout << " :preexecShellSafe="; @@ -340,17 +318,16 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper( default: assert("Only pre and post are supported"); } - cmCustomCommandLine const& command = *commandI; - for (cmCustomCommandLine::const_iterator commandLineI = command.begin(); - commandLineI != command.end(); ++commandLineI) { + + bool firstIteration = true; + for (std::string const& commandLine : command) { std::string subCommandE = - this->LocalGenerator->EscapeForShell(*commandLineI, true); - if (!command.empty()) { - fout << (command.begin() == commandLineI ? "'" : " "); - // Need to double escape backslashes - cmSystemTools::ReplaceString(subCommandE, "\\", "\\\\"); - } + this->LocalGenerator->EscapeForShell(commandLine, true); + fout << (firstIteration ? "'" : " "); + // Need to double escape backslashes + cmSystemTools::ReplaceString(subCommandE, "\\", "\\\\"); fout << subCommandE; + firstIteration = false; } if (!command.empty()) { fout << "'" << std::endl; diff --git a/Source/cmGlobVerificationManager.cxx b/Source/cmGlobVerificationManager.cxx index 5fd890e..9fb4170 100644 --- a/Source/cmGlobVerificationManager.cxx +++ b/Source/cmGlobVerificationManager.cxx @@ -25,8 +25,8 @@ bool cmGlobVerificationManager::SaveVerificationScript(const std::string& path) cmGeneratedFileStream verifyScriptFile(scriptFile); verifyScriptFile.SetCopyIfDifferent(true); if (!verifyScriptFile) { - cmSystemTools::Error("Unable to open verification script file for save. ", - scriptFile.c_str()); + cmSystemTools::Error("Unable to open verification script file for save. " + + scriptFile); cmSystemTools::ReportLastSystemError(""); return false; } @@ -71,8 +71,8 @@ bool cmGlobVerificationManager::SaveVerificationScript(const std::string& path) cmsys::ofstream verifyStampFile(stampFile.c_str()); if (!verifyStampFile) { - cmSystemTools::Error("Unable to open verification stamp file for write. ", - stampFile.c_str()); + cmSystemTools::Error("Unable to open verification stamp file for write. " + + stampFile); return false; } verifyStampFile << "# This file is generated by CMake for checking of the " diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 386a3f7..c7b3591 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -7,6 +7,7 @@ #include <algorithm> #include <assert.h> #include <cstring> +#include <initializer_list> #include <iterator> #include <sstream> #include <stdio.h> @@ -34,6 +35,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateDirectory.h" @@ -211,7 +213,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, if (!mf->GetDefinition(langComp)) { if (!optional) { - cmSystemTools::Error(langComp.c_str(), " not set, after EnableLanguage"); + cmSystemTools::Error(langComp + " not set, after EnableLanguage"); } return; } @@ -314,9 +316,11 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const if (configs.empty()) { target->GetSourceFiles(srcs, ""); } else { - for (std::vector<std::string>::const_iterator ci = configs.begin(); - ci != configs.end() && srcs.empty(); ++ci) { - target->GetSourceFiles(srcs, *ci); + for (std::string const& config : configs) { + target->GetSourceFiles(srcs, config); + if (srcs.empty()) { + break; + } } } if (srcs.empty()) { @@ -635,8 +639,7 @@ void cmGlobalGenerator::EnableLanguage( // to avoid duplicate compiler tests. if (cmSystemTools::FileExists(fpath)) { if (!mf->ReadListFile(fpath)) { - cmSystemTools::Error("Could not find cmake module file: ", - fpath.c_str()); + cmSystemTools::Error("Could not find cmake module file: " + fpath); } // if this file was found then the language was already determined // to be working @@ -661,8 +664,8 @@ void cmGlobalGenerator::EnableLanguage( determineCompiler += "Compiler.cmake"; std::string determineFile = mf->GetModulesFile(determineCompiler); if (!mf->ReadListFile(determineFile)) { - cmSystemTools::Error("Could not find cmake module file: ", - determineCompiler.c_str()); + cmSystemTools::Error("Could not find cmake module file: " + + determineCompiler); } if (cmSystemTools::GetFatalErrorOccured()) { return; @@ -680,8 +683,9 @@ void cmGlobalGenerator::EnableLanguage( std::string compilerEnv = "CMAKE_"; compilerEnv += lang; compilerEnv += "_COMPILER_ENV_VAR"; - std::string envVar = mf->GetRequiredDefinition(compilerEnv); - std::string envVarValue = mf->GetRequiredDefinition(compilerName); + const std::string& envVar = mf->GetRequiredDefinition(compilerEnv); + const std::string& envVarValue = + mf->GetRequiredDefinition(compilerName); std::string env = envVar; env += "="; env += envVarValue; @@ -695,8 +699,7 @@ void cmGlobalGenerator::EnableLanguage( fpath += lang; fpath += "Compiler.cmake"; if (!mf->ReadListFile(fpath)) { - cmSystemTools::Error("Could not find cmake module file: ", - fpath.c_str()); + cmSystemTools::Error("Could not find cmake module file: " + fpath); } this->SetLanguageEnabledFlag(lang, mf); needSetLanguageEnabledMaps[lang] = true; @@ -788,11 +791,10 @@ void cmGlobalGenerator::EnableLanguage( fpath += "Information.cmake"; std::string informationFile = mf->GetModulesFile(fpath); if (informationFile.empty()) { - cmSystemTools::Error("Could not find cmake module file: ", - fpath.c_str()); + cmSystemTools::Error("Could not find cmake module file: " + fpath); } else if (!mf->ReadListFile(informationFile)) { - cmSystemTools::Error("Could not process cmake module file: ", - informationFile.c_str()); + cmSystemTools::Error("Could not process cmake module file: " + + informationFile); } } if (needSetLanguageEnabledMaps[lang]) { @@ -812,8 +814,8 @@ void cmGlobalGenerator::EnableLanguage( testLang += "Compiler.cmake"; std::string ifpath = mf->GetModulesFile(testLang); if (!mf->ReadListFile(ifpath)) { - cmSystemTools::Error("Could not find cmake module file: ", - testLang.c_str()); + cmSystemTools::Error("Could not find cmake module file: " + + testLang); } std::string compilerWorks = "CMAKE_"; compilerWorks += lang; @@ -954,6 +956,36 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( break; } } + + if (strcmp(compilerId, "XLClang") == 0) { + switch (mf->GetPolicyStatus(cmPolicies::CMP0089)) { + case cmPolicies::WARN: + if (!this->CMakeInstance->GetIsInTryCompile() && + mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0089")) { + std::ostringstream w; + /* clang-format off */ + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0089) << "\n" + "Converting " << lang << + " compiler id \"XLClang\" to \"XL\" for compatibility." + ; + /* clang-format on */ + mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + // OLD behavior is to convert XLClang to XL. + mf->AddDefinition(compilerIdVar, "XL"); + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0089)); + case cmPolicies::NEW: + // NEW behavior is to keep AppleClang. + break; + } + } } std::string cmGlobalGenerator::GetLanguageOutputExtension( @@ -1222,7 +1254,7 @@ void cmGlobalGenerator::Configure() } else { msg << "Configuring done"; } - this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1); + this->CMakeInstance->UpdateProgress(msg.str(), -1); } } @@ -1702,8 +1734,8 @@ void cmGlobalGenerator::CheckTargetProperties() cmSystemTools::Error("The following variables are used in this project, " "but they are set to NOTFOUND.\n" "Please set them or make sure they are set and " - "tested correctly in the CMake files:\n", - notFoundVars.c_str()); + "tested correctly in the CMake files:\n" + + notFoundVars); } } @@ -1847,8 +1879,8 @@ int cmGlobalGenerator::Build(int jobs, const std::string& /*unused*/, timeout)) { cmSystemTools::SetRunCommandHideConsole(hideconsole); cmSystemTools::Error( - "Generator: execution of make failed. Make command was: ", - makeCommandStr.c_str()); + "Generator: execution of make failed. Make command was: " + + makeCommandStr); output += *outputPtr; output += "\nGenerator: execution of make failed. Make command was: " + makeCommandStr + "\n"; @@ -1858,13 +1890,6 @@ int cmGlobalGenerator::Build(int jobs, const std::string& /*unused*/, output += *outputPtr; cmSystemTools::SetRunCommandHideConsole(hideconsole); - // The SGI MipsPro 7.3 compiler does not return an error code when - // the source has a #error in it! This is a work-around for such - // compilers. - if ((retVal == 0) && (output.find("#error") != std::string::npos)) { - retVal = 1; - } - // The OpenWatcom tools do not return an error code when a link // library is not found! if (this->CMakeInstance->GetState()->UseWatcomWMake() && retVal == 0 && @@ -2114,17 +2139,24 @@ void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt) } } +static char const hexDigits[] = "0123456789abcdef"; + std::string cmGlobalGenerator::IndexGeneratorTargetUniquely( cmGeneratorTarget const* gt) { // Use the pointer value to uniquely identify the target instance. - // Use a "T" prefix to indicate that this identifier is for a target. + // Use a ":" prefix to avoid conflict with project-defined targets. // We must satisfy cmGeneratorExpression::IsValidTargetName so use no // other special characters. - char buf[64]; - sprintf(buf, "::T%p", - static_cast<void const*>(gt)); // cast avoids format warning - std::string id = gt->GetName() + buf; + char buf[1 + sizeof(gt) * 2]; + char* b = buf; + *b++ = ':'; + for (size_t i = 0; i < sizeof(gt); ++i) { + unsigned char const c = reinterpret_cast<unsigned char const*>(>)[i]; + *b++ = hexDigits[(c & 0xf0) >> 4]; + *b++ = hexDigits[(c & 0x0f)]; + } + std::string id(buf, sizeof(buf)); // We internally index pointers to non-const generator targets // but our callers only have pointers to const generator targets. // They will give up non-const privileges when looking up anyway. @@ -2196,7 +2228,7 @@ cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTarget( bool cmGlobalGenerator::NameResolvesToFramework( const std::string& libname) const { - if (cmSystemTools::IsPathToFramework(libname.c_str())) { + if (cmSystemTools::IsPathToFramework(libname)) { return true; } @@ -2277,10 +2309,9 @@ void cmGlobalGenerator::AddGlobalTarget_Package( return; } - const char* reservedTargets[] = { "package", "PACKAGE" }; - for (const char* const* tn = cm::cbegin(reservedTargets); - tn != cm::cend(reservedTargets); ++tn) { - if (!this->CheckCMP0037(*tn, "when CPack packaging is enabled")) { + static const auto reservedTargets = { "package", "PACKAGE" }; + for (auto const& target : reservedTargets) { + if (!this->CheckCMP0037(target, "when CPack packaging is enabled")) { return; } } @@ -2327,10 +2358,10 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource( return; } - const char* reservedTargets[] = { "package_source" }; - for (const char* const* tn = cm::cbegin(reservedTargets); - tn != cm::cend(reservedTargets); ++tn) { - if (!this->CheckCMP0037(*tn, "when CPack source packaging is enabled")) { + static const auto reservedTargets = { "package_source" }; + for (auto const& target : reservedTargets) { + if (!this->CheckCMP0037(target, + "when CPack source packaging is enabled")) { return; } } @@ -2357,10 +2388,9 @@ void cmGlobalGenerator::AddGlobalTarget_Test( return; } - const char* reservedTargets[] = { "test", "RUN_TESTS" }; - for (const char* const* tn = cm::cbegin(reservedTargets); - tn != cm::cend(reservedTargets); ++tn) { - if (!this->CheckCMP0037(*tn, "when CTest testing is enabled")) { + static const auto reservedTargets = { "test", "RUN_TESTS" }; + for (auto const& target : reservedTargets) { + if (!this->CheckCMP0037(target, "when CTest testing is enabled")) { return; } } @@ -2983,10 +3013,8 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) } std::vector<cmSourceFile*>::const_iterator sourcesEnd = cmRemoveDuplicates(sources); - for (std::vector<cmSourceFile*>::const_iterator si = sources.begin(); - si != sourcesEnd; ++si) { + for (cmSourceFile* sf : cmMakeRange(sources.cbegin(), sourcesEnd)) { Json::Value& lj_source = lj_sources.append(Json::objectValue); - cmSourceFile* sf = *si; std::string const& sfp = sf->GetFullPath(); fout << sfp << "\n"; lj_source["file"] = sfp; diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 45fa052..746ddad 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -420,10 +420,8 @@ void cmGlobalGhsMultiGenerator::WriteMacros(std::ostream& fout) if (NULL != ghsGpjMacros) { std::vector<std::string> expandedList; cmSystemTools::ExpandListArgument(std::string(ghsGpjMacros), expandedList); - for (std::vector<std::string>::const_iterator expandedListI = - expandedList.begin(); - expandedListI != expandedList.end(); ++expandedListI) { - fout << "macro " << *expandedListI << std::endl; + for (std::string const& arg : expandedList) { + fout << "macro " << arg << std::endl; } } } diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index 3c24556..606febe 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -45,7 +45,8 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( std::vector<std::string> const& l, cmMakefile* mf, bool optional) { this->FindMakeProgram(mf); - std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& makeProgram = + mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::vector<std::string> locations; std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str()); locations.push_back(this->FindMinGW(makeloc)); diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx index c6d46e9..e218b4b 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.cxx +++ b/Source/cmGlobalMinGWMakefileGenerator.cxx @@ -23,7 +23,8 @@ void cmGlobalMinGWMakefileGenerator::EnableLanguage( std::vector<std::string> const& l, cmMakefile* mf, bool optional) { this->FindMakeProgram(mf); - std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); + const std::string& makeProgram = + mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::vector<std::string> locations; locations.push_back(cmSystemTools::GetProgramPath(makeProgram)); locations.push_back("/mingw/bin"); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 920f639..d21fd35 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -26,6 +26,7 @@ #include "cmMessageType.h" #include "cmNinjaLinkLineComputer.h" #include "cmOutputConverter.h" +#include "cmRange.h" #include "cmState.h" #include "cmStateDirectory.h" #include "cmStateSnapshot.h" @@ -136,16 +137,16 @@ void cmGlobalNinjaGenerator::WriteBuild( // Make sure there is a rule. if (rule.empty()) { cmSystemTools::Error("No rule for WriteBuildStatement! called " - "with comment: ", - comment.c_str()); + "with comment: " + + comment); return; } // Make sure there is at least one output file. if (outputs.empty()) { cmSystemTools::Error("No output files for WriteBuildStatement! called " - "with comment: ", - comment.c_str()); + "with comment: " + + comment); return; } @@ -334,16 +335,16 @@ void cmGlobalNinjaGenerator::WriteRule( // Make sure the rule has a name. if (name.empty()) { cmSystemTools::Error("No name given for WriteRuleStatement! called " - "with comment: ", - comment.c_str()); + "with comment: " + + comment); return; } // Make sure a command is given. if (command.empty()) { cmSystemTools::Error("No command given for WriteRuleStatement! called " - "with comment: ", - comment.c_str()); + "with comment: " + + comment); return; } @@ -376,7 +377,7 @@ void cmGlobalNinjaGenerator::WriteRule( if (!rspfile.empty()) { if (rspcontent.empty()) { - cmSystemTools::Error("No rspfile_content given!", comment.c_str()); + cmSystemTools::Error("No rspfile_content given!" + comment); return; } cmGlobalNinjaGenerator::Indent(os, 1); @@ -407,8 +408,8 @@ void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os, // Make sure we have a name. if (name.empty()) { cmSystemTools::Error("No name given for WriteVariable! called " - "with comment: ", - comment.c_str()); + "with comment: " + + comment); return; } @@ -1573,12 +1574,13 @@ Compilation of source files within a target is split into the following steps: command = gfortran -cpp $DEFINES $INCLUDES $FLAGS -E $in -o $out && cmake -E cmake_ninja_depends \ --tdi=FortranDependInfo.json --pp=$out --dep=$DEP_FILE \ - --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE + --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE \ + --lang=Fortran - build src.f90-pp.f90 | src.f90-pp.f90.ddi: Fortran_PREPROCESS src.f90 + build src.f90-pp.f90 | src.f90.o.ddi: Fortran_PREPROCESS src.f90 OBJ_FILE = src.f90.o - DEP_FILE = src.f90-pp.f90.d - DYNDEP_INTERMEDIATE_FILE = src.f90-pp.f90.ddi + DEP_FILE = src.f90.o.d + DYNDEP_INTERMEDIATE_FILE = src.f90.o.ddi The ``cmake -E cmake_ninja_depends`` tool reads the preprocessed output and generates the ninja depfile for preprocessor dependencies. It also @@ -1592,9 +1594,9 @@ Compilation of source files within a target is split into the following steps: rule Fortran_DYNDEP command = cmake -E cmake_ninja_dyndep \ - --tdi=FortranDependInfo.json --dd=$out $in + --tdi=FortranDependInfo.json --lang=Fortran --dd=$out $in - build Fortran.dd: Fortran_DYNDEP src1.f90-pp.f90.ddi src2.f90-pp.f90.ddi + build Fortran.dd: Fortran_DYNDEP src1.f90.o.ddi src2.f90.o.ddi The ``cmake -E cmake_ninja_dyndep`` tool reads the "ddi" files from all sources in the target and the ``FortranModules.json`` files from targets @@ -1632,6 +1634,19 @@ Compilation of source files within a target is split into the following steps: (because the latter consumes the module). */ +struct cmSourceInfo +{ + // Set of provided and required modules. + std::set<std::string> Provides; + std::set<std::string> Requires; + + // Set of files included in the translation unit. + std::set<std::string> Includes; +}; + +static std::unique_ptr<cmSourceInfo> cmcmd_cmake_ninja_depends_fortran( + std::string const& arg_tdi, std::string const& arg_pp); + int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, std::vector<std::string>::const_iterator argEnd) { @@ -1640,8 +1655,8 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, std::string arg_dep; std::string arg_obj; std::string arg_ddi; - for (std::vector<std::string>::const_iterator a = argBeg; a != argEnd; ++a) { - std::string const& arg = *a; + std::string arg_lang; + for (std::string const& arg : cmMakeRange(argBeg, argEnd)) { if (cmHasLiteralPrefix(arg, "--tdi=")) { arg_tdi = arg.substr(6); } else if (cmHasLiteralPrefix(arg, "--pp=")) { @@ -1652,9 +1667,10 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, arg_obj = arg.substr(6); } else if (cmHasLiteralPrefix(arg, "--ddi=")) { arg_ddi = arg.substr(6); + } else if (cmHasLiteralPrefix(arg, "--lang=")) { + arg_lang = arg.substr(7); } else { - cmSystemTools::Error("-E cmake_ninja_depends unknown argument: ", - arg.c_str()); + cmSystemTools::Error("-E cmake_ninja_depends unknown argument: " + arg); return 1; } } @@ -1678,7 +1694,61 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, cmSystemTools::Error("-E cmake_ninja_depends requires value for --ddi="); return 1; } + if (arg_lang.empty()) { + cmSystemTools::Error("-E cmake_ninja_depends requires value for --lang="); + return 1; + } + std::unique_ptr<cmSourceInfo> info; + if (arg_lang == "Fortran") { + info = cmcmd_cmake_ninja_depends_fortran(arg_tdi, arg_pp); + } else { + cmSystemTools::Error("-E cmake_ninja_depends does not understand the " + + arg_lang + " language"); + return 1; + } + + if (!info) { + // The error message is already expected to have been output. + return 1; + } + + { + cmGeneratedFileStream depfile(arg_dep); + depfile << cmSystemTools::ConvertToUnixOutputPath(arg_pp) << ":"; + for (std::string const& include : info->Includes) { + depfile << " \\\n " << cmSystemTools::ConvertToUnixOutputPath(include); + } + depfile << "\n"; + } + + Json::Value ddi(Json::objectValue); + ddi["object"] = arg_obj; + + Json::Value& ddi_provides = ddi["provides"] = Json::arrayValue; + for (std::string const& provide : info->Provides) { + ddi_provides.append(provide); + } + Json::Value& ddi_requires = ddi["requires"] = Json::arrayValue; + for (std::string const& r : info->Requires) { + // Require modules not provided in the same source. + if (!info->Provides.count(r)) { + ddi_requires.append(r); + } + } + + cmGeneratedFileStream ddif(arg_ddi); + ddif << ddi; + if (!ddif) { + cmSystemTools::Error("-E cmake_ninja_depends failed to write " + arg_ddi); + return 1; + } + return 0; +} + +std::unique_ptr<cmSourceInfo> cmcmd_cmake_ninja_depends_fortran( + std::string const& arg_tdi, std::string const& arg_pp) +{ cmFortranCompiler fc; std::vector<std::string> includes; { @@ -1688,10 +1758,9 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, cmsys::ifstream tdif(arg_tdi.c_str(), std::ios::in | std::ios::binary); Json::Reader reader; if (!reader.parse(tdif, tdio, false)) { - cmSystemTools::Error("-E cmake_ninja_depends failed to parse ", - arg_tdi.c_str(), - reader.getFormattedErrorMessages().c_str()); - return 1; + cmSystemTools::Error("-E cmake_ninja_depends failed to parse " + + arg_tdi + reader.getFormattedErrorMessages()); + return nullptr; } } @@ -1712,54 +1781,26 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, fc.SModExt = tdi_submodule_ext.asString(); } - cmFortranSourceInfo info; + cmFortranSourceInfo finfo; std::set<std::string> defines; - cmFortranParser parser(fc, includes, defines, info); + cmFortranParser parser(fc, includes, defines, finfo); if (!cmFortranParser_FilePush(&parser, arg_pp.c_str())) { - cmSystemTools::Error("-E cmake_ninja_depends failed to open ", - arg_pp.c_str()); - return 1; + cmSystemTools::Error("-E cmake_ninja_depends failed to open " + arg_pp); + return nullptr; } if (cmFortran_yyparse(parser.Scanner) != 0) { // Failed to parse the file. - return 1; - } - - { - cmGeneratedFileStream depfile(arg_dep); - depfile << cmSystemTools::ConvertToUnixOutputPath(arg_pp) << ":"; - for (std::string const& include : info.Includes) { - depfile << " \\\n " << cmSystemTools::ConvertToUnixOutputPath(include); - } - depfile << "\n"; - } - - Json::Value ddi(Json::objectValue); - ddi["object"] = arg_obj; - - Json::Value& ddi_provides = ddi["provides"] = Json::arrayValue; - for (std::string const& provide : info.Provides) { - ddi_provides.append(provide); - } - Json::Value& ddi_requires = ddi["requires"] = Json::arrayValue; - for (std::string const& r : info.Requires) { - // Require modules not provided in the same source. - if (!info.Provides.count(r)) { - ddi_requires.append(r); - } + return nullptr; } - cmGeneratedFileStream ddif(arg_ddi); - ddif << ddi; - if (!ddif) { - cmSystemTools::Error("-E cmake_ninja_depends failed to write ", - arg_ddi.c_str()); - return 1; - } - return 0; + auto info = cm::make_unique<cmSourceInfo>(); + info->Provides = finfo.Provides; + info->Requires = finfo.Requires; + info->Includes = finfo.Includes; + return info; } -struct cmFortranObjectInfo +struct cmDyndepObjectInfo { std::string Object; std::vector<std::string> Provides; @@ -1771,7 +1812,8 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( std::string const& dir_cur_src, std::string const& dir_cur_bld, std::string const& arg_dd, std::vector<std::string> const& arg_ddis, std::string const& module_dir, - std::vector<std::string> const& linked_target_dirs) + std::vector<std::string> const& linked_target_dirs, + std::string const& arg_lang) { // Setup path conversions. { @@ -1788,7 +1830,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( this->LocalGenerators.push_back(lgd.release()); } - std::vector<cmFortranObjectInfo> objects; + std::vector<cmDyndepObjectInfo> objects; for (std::string const& arg_ddi : arg_ddis) { // Load the ddi file and compute the module file paths it provides. Json::Value ddio; @@ -1796,13 +1838,12 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( cmsys::ifstream ddif(arg_ddi.c_str(), std::ios::in | std::ios::binary); Json::Reader reader; if (!reader.parse(ddif, ddio, false)) { - cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse ", - arg_ddi.c_str(), - reader.getFormattedErrorMessages().c_str()); + cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse " + arg_ddi + + reader.getFormattedErrorMessages()); return false; } - cmFortranObjectInfo info; + cmDyndepObjectInfo info; info.Object = ddi["object"].asString(); Json::Value const& ddi_provides = ddi["provides"]; if (ddi_provides.isArray()) { @@ -1824,14 +1865,15 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( // Populate the module map with those provided by linked targets first. for (std::string const& linked_target_dir : linked_target_dirs) { - std::string const ltmn = linked_target_dir + "/FortranModules.json"; + std::string const ltmn = + linked_target_dir + "/" + arg_lang + "Modules.json"; Json::Value ltm; cmsys::ifstream ltmf(ltmn.c_str(), std::ios::in | std::ios::binary); Json::Reader reader; if (ltmf && !reader.parse(ltmf, ltm, false)) { - cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse ", - linked_target_dir.c_str(), - reader.getFormattedErrorMessages().c_str()); + cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse " + + linked_target_dir + + reader.getFormattedErrorMessages()); return false; } if (ltm.isObject()) { @@ -1845,7 +1887,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( // We do this after loading the modules provided by linked targets // in case we have one of the same name that must be preferred. Json::Value tm = Json::objectValue; - for (cmFortranObjectInfo const& object : objects) { + for (cmDyndepObjectInfo const& object : objects) { for (std::string const& p : object.Provides) { std::string const mod = module_dir + p; mod_files[p] = mod; @@ -1856,7 +1898,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( cmGeneratedFileStream ddf(arg_dd); ddf << "ninja_dyndep_version = 1.0\n"; - for (cmFortranObjectInfo const& object : objects) { + for (cmDyndepObjectInfo const& object : objects) { std::string const ddComment; std::string const ddRule = "dyndep"; cmNinjaDeps ddOutputs; @@ -1887,7 +1929,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( // Store the map of modules provided by this target in a file for // use by dependents that reference this target in linked-target-dirs. std::string const target_mods_file = - cmSystemTools::GetFilenamePath(arg_dd) + "/FortranModules.json"; + cmSystemTools::GetFilenamePath(arg_dd) + "/" + arg_lang + "Modules.json"; cmGeneratedFileStream tmf(target_mods_file); tmf << tm; @@ -1901,19 +1943,21 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, cmSystemTools::HandleResponseFile(argBeg, argEnd); std::string arg_dd; + std::string arg_lang; std::string arg_tdi; std::vector<std::string> arg_ddis; for (std::string const& arg : arg_full) { if (cmHasLiteralPrefix(arg, "--tdi=")) { arg_tdi = arg.substr(6); + } else if (cmHasLiteralPrefix(arg, "--lang=")) { + arg_lang = arg.substr(7); } else if (cmHasLiteralPrefix(arg, "--dd=")) { arg_dd = arg.substr(5); } else if (!cmHasLiteralPrefix(arg, "--") && cmHasLiteralSuffix(arg, ".ddi")) { arg_ddis.push_back(arg); } else { - cmSystemTools::Error("-E cmake_ninja_dyndep unknown argument: ", - arg.c_str()); + cmSystemTools::Error("-E cmake_ninja_dyndep unknown argument: " + arg); return 1; } } @@ -1921,6 +1965,10 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, cmSystemTools::Error("-E cmake_ninja_dyndep requires value for --tdi="); return 1; } + if (arg_lang.empty()) { + cmSystemTools::Error("-E cmake_ninja_dyndep requires value for --lang="); + return 1; + } if (arg_dd.empty()) { cmSystemTools::Error("-E cmake_ninja_dyndep requires value for --dd="); return 1; @@ -1932,9 +1980,8 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, cmsys::ifstream tdif(arg_tdi.c_str(), std::ios::in | std::ios::binary); Json::Reader reader; if (!reader.parse(tdif, tdio, false)) { - cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse ", - arg_tdi.c_str(), - reader.getFormattedErrorMessages().c_str()); + cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse " + arg_tdi + + reader.getFormattedErrorMessages()); return 1; } } @@ -1962,8 +2009,8 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, static_cast<cmGlobalNinjaGenerator*>(cm.CreateGlobalGenerator("Ninja"))); if (!ggd || !ggd->WriteDyndepFile(dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, - arg_dd, arg_ddis, module_dir, - linked_target_dirs)) { + arg_dd, arg_ddis, module_dir, linked_target_dirs, + arg_lang)) { return 1; } return 0; diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index c619e67..69210ec 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -365,7 +365,8 @@ public: std::string const& arg_dd, std::vector<std::string> const& arg_ddis, std::string const& module_dir, - std::vector<std::string> const& linked_target_dirs); + std::vector<std::string> const& linked_target_dirs, + std::string const& arg_lang); protected: void Generate() override; diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index d8b2e89..f872de5 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -913,10 +913,11 @@ void cmGlobalVisualStudio10Generator::GenerateBuildCommand( if (parser.ParseFile(slnFile, slnData, cmVisualStudioSlnParser::DataGroupProjects)) { std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects(); - for (std::vector<cmSlnProjectEntry>::const_iterator i = - slnProjects.cbegin(); - !useDevEnv && i != slnProjects.cend(); ++i) { - std::string proj = i->GetRelativePath(); + for (cmSlnProjectEntry const& project : slnProjects) { + if (useDevEnv) { + break; + } + std::string proj = project.GetRelativePath(); if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj") { useDevEnv = true; } @@ -1005,7 +1006,7 @@ bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf) winSDK_7_1)) { std::ostringstream m; m << "Found Windows SDK v7.1: " << winSDK_7_1; - mf->DisplayStatus(m.str().c_str(), -1); + mf->DisplayStatus(m.str(), -1); this->DefaultPlatformToolset = "Windows7.1SDK"; return true; } else { diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index 4eb78ba..4b74ef1 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -252,15 +252,10 @@ cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs() return ret; } -bool cmGlobalVisualStudio11Generator::NeedsDeploy( - cmStateEnums::TargetType type) const +bool cmGlobalVisualStudio11Generator::TargetSystemSupportsDeployment() const { - if ((type == cmStateEnums::EXECUTABLE || - type == cmStateEnums::SHARED_LIBRARY) && - (this->SystemIsWindowsPhone || this->SystemIsWindowsStore)) { - return true; - } - return cmGlobalVisualStudio10Generator::NeedsDeploy(type); + return this->SystemIsWindowsPhone || this->SystemIsWindowsStore || + cmGlobalVisualStudio10Generator::TargetSystemSupportsDeployment(); } bool cmGlobalVisualStudio11Generator::IsWindowsDesktopToolsetInstalled() const diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h index 8b4c8b7..f8cce18 100644 --- a/Source/cmGlobalVisualStudio11Generator.h +++ b/Source/cmGlobalVisualStudio11Generator.h @@ -45,8 +45,8 @@ protected: bool UseFolderProperty() const override; static std::set<std::string> GetInstalledWindowsCESDKs(); - /** Return true if the configuration needs to be deployed */ - bool NeedsDeploy(cmStateEnums::TargetType type) const override; + /** Return true if target system supports debugging deployment. */ + bool TargetSystemSupportsDeployment() const override; private: class Factory; diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index a0a9558..6509b56 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -158,24 +158,31 @@ bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf, bool required) { // Find the default version of the Windows 10 SDK. - this->WindowsTargetPlatformVersion = this->GetWindows10SDKVersion(); - if (required && this->WindowsTargetPlatformVersion.empty()) { + std::string const version = this->GetWindows10SDKVersion(); + if (required && version.empty()) { std::ostringstream e; e << "Could not find an appropriate version of the Windows 10 SDK" << " installed on this machine"; mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } + this->SetWindowsTargetPlatformVersion(version, mf); + return true; +} + +void cmGlobalVisualStudio14Generator::SetWindowsTargetPlatformVersion( + std::string const& version, cmMakefile* mf) +{ + this->WindowsTargetPlatformVersion = version; if (!cmSystemTools::VersionCompareEqual(this->WindowsTargetPlatformVersion, this->SystemVersion)) { std::ostringstream e; e << "Selecting Windows SDK version " << this->WindowsTargetPlatformVersion << " to target Windows " << this->SystemVersion << "."; - mf->DisplayStatus(e.str().c_str(), -1); + mf->DisplayStatus(e.str(), -1); } mf->AddDefinition("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION", this->WindowsTargetPlatformVersion.c_str()); - return true; } bool cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index 32008b0..6e12d3e 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -40,6 +40,9 @@ protected: virtual bool SelectWindows10SDK(cmMakefile* mf, bool required); + void SetWindowsTargetPlatformVersion(std::string const& version, + cmMakefile* mf); + // Used to verify that the Desktop toolset for the current generator is // installed on the machine. bool IsWindowsDesktopToolsetInstalled() const override; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index f6db018..21abdf7 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -205,7 +205,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() "Checking Build System", no_working_directory, true, false)) { gt->AddSource(file->GetFullPath()); } else { - cmSystemTools::Error("Error adding rule for ", stamps[0].c_str()); + cmSystemTools::Error("Error adding rule for " + stamps[0]); } } @@ -273,7 +273,7 @@ void cmGlobalVisualStudio8Generator::WriteProjectConfigurations( : this->GetPlatformName()) << "\n"; } - if (this->NeedsDeploy(target.GetType())) { + if (this->NeedsDeploy(target, dstConfig)) { fout << "\t\t{" << guid << "}." << i << "|" << this->GetPlatformName() << ".Deploy.0 = " << dstConfig << "|" << (!platformMapping.empty() ? platformMapping @@ -284,11 +284,32 @@ void cmGlobalVisualStudio8Generator::WriteProjectConfigurations( } bool cmGlobalVisualStudio8Generator::NeedsDeploy( - cmStateEnums::TargetType type) const + cmGeneratorTarget const& target, const char* config) const { - bool needsDeploy = - (type == cmStateEnums::EXECUTABLE || type == cmStateEnums::SHARED_LIBRARY); - return this->TargetsWindowsCE() && needsDeploy; + cmStateEnums::TargetType type = target.GetType(); + bool noDeploy = DeployInhibited(target, config); + return !noDeploy && + (type == cmStateEnums::EXECUTABLE || + type == cmStateEnums::SHARED_LIBRARY) && + this->TargetSystemSupportsDeployment(); +} + +bool cmGlobalVisualStudio8Generator::DeployInhibited( + cmGeneratorTarget const& target, const char* config) const +{ + bool rVal = false; + if (const char* propStr = target.GetProperty("VS_NO_SOLUTION_DEPLOY")) { + cmGeneratorExpression ge; + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(propStr); + std::string prop = cge->Evaluate(target.LocalGenerator, config); + rVal = cmSystemTools::IsOn(prop); + } + return rVal; +} + +bool cmGlobalVisualStudio8Generator::TargetSystemSupportsDeployment() const +{ + return this->TargetsWindowsCE(); } bool cmGlobalVisualStudio8Generator::ComputeTargetDepends() diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index 8719bf3..75f4778 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -54,7 +54,15 @@ protected: bool AddCheckTarget(); /** Return true if the configuration needs to be deployed */ - virtual bool NeedsDeploy(cmStateEnums::TargetType type) const; + virtual bool NeedsDeploy(cmGeneratorTarget const& target, + const char* config) const; + + /** Returns true if deployment has been disabled in cmake file. */ + bool DeployInhibited(cmGeneratorTarget const& target, + const char* config) const; + + /** Returns true if the target system support debugging deployment. */ + virtual bool TargetSystemSupportsDeployment() const; static cmIDEFlagTable const* GetExtraFlagTableVS8(); void WriteSolutionConfigurations( diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 1922906..45927c9 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -918,7 +918,7 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( cmdl.push_back(objs_file); cmGeneratedFileStream fout(objs_file.c_str()); if (!fout) { - cmSystemTools::Error("could not open ", objs_file.c_str()); + cmSystemTools::Error("could not open " + objs_file); return; } diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index 913fc4a..2f9eb3f 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -401,6 +401,12 @@ bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf) // If the Win 8.1 SDK is installed then we can select a SDK matching // the target Windows version. if (this->IsWin81SDKInstalled()) { + // VS 2019 does not default to 8.1 so specify it explicitly when needed. + if (this->Version >= cmGlobalVisualStudioGenerator::VS16 && + !cmSystemTools::VersionCompareGreater(this->SystemVersion, "8.1")) { + this->SetWindowsTargetPlatformVersion("8.1", mf); + return true; + } return cmGlobalVisualStudio14Generator::InitializeWindows(mf); } // Otherwise we must choose a Win 10 SDK even if we are not targeting diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 51c001e..11cc98e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -217,7 +217,7 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( sscanf(version_string.c_str(), "%u.%u", &v[0], &v[1]); unsigned int version_number = 10 * v[0] + v[1]; - if (version_number < 30) { + if (version_number < 50) { cm->IssueMessage(MessageType::FATAL_ERROR, "Xcode " + version_string + " not supported."); return nullptr; @@ -256,15 +256,11 @@ std::string const& cmGlobalXCodeGenerator::GetXcodeBuildCommand() std::string cmGlobalXCodeGenerator::FindXcodeBuildCommand() { - if (this->XcodeVersion >= 40) { - std::string makeProgram = cmSystemTools::FindProgram("xcodebuild"); - if (makeProgram.empty()) { - makeProgram = "xcodebuild"; - } - return makeProgram; + std::string makeProgram = cmSystemTools::FindProgram("xcodebuild"); + if (makeProgram.empty()) { + makeProgram = "xcodebuild"; } - // Use cmakexbuild wrapper to suppress environment dump from output. - return cmSystemTools::GetCMakeCommand() + "xbuild"; + return makeProgram; } bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts, @@ -550,12 +546,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( // run the depend check makefile as a post build rule // this will make sure that when the next target is built // things are up-to-date - if (target->GetType() == cmStateEnums::OBJECT_LIBRARY || - (this->XcodeVersion < 50 && - (target->GetType() == cmStateEnums::EXECUTABLE || - target->GetType() == cmStateEnums::STATIC_LIBRARY || - target->GetType() == cmStateEnums::SHARED_LIBRARY || - target->GetType() == cmStateEnums::MODULE_LIBRARY))) { + if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) { makeHelper.back() = // fill placeholder this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)"); cmCustomCommandLines commandLines; @@ -1183,23 +1174,6 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( } } - if (this->XcodeVersion < 50) { - // Add object library contents as external objects. (Equivalent to - // the externalObjFiles above, except each one is not a cmSourceFile - // within the target.) - std::vector<cmSourceFile const*> objs; - gtgt->GetExternalObjects(objs, ""); - for (auto sourceFile : objs) { - if (sourceFile->GetObjectLibrary().empty()) { - continue; - } - std::string const& obj = sourceFile->GetFullPath(); - cmXCodeObject* xsf = - this->CreateXCodeSourceFileFromPath(obj, gtgt, "", nullptr); - externalObjFiles.push_back(xsf); - } - } - // some build phases only apply to bundles and/or frameworks bool isFrameworkTarget = gtgt->IsFrameworkOnApple(); bool isBundleTarget = gtgt->GetPropertyAsBool("MACOSX_BUNDLE"); @@ -2002,7 +1976,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // so let it replace the framework name. This avoids creating // a per-configuration Info.plist file. this->CurrentLocalGenerator->GenerateFrameworkInfoPList( - gtgt, "$(EXECUTABLE_NAME)", plist.c_str()); + gtgt, "$(EXECUTABLE_NAME)", plist); buildSettings->AddAttribute("INFOPLIST_FILE", this->CreateString(plist)); buildSettings->AddAttribute("MACH_O_TYPE", @@ -2043,7 +2017,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // a per-configuration Info.plist file. The cfbundle plist // is very similar to the application bundle plist this->CurrentLocalGenerator->GenerateAppleInfoPList( - gtgt, "$(EXECUTABLE_NAME)", plist.c_str()); + gtgt, "$(EXECUTABLE_NAME)", plist); buildSettings->AddAttribute("INFOPLIST_FILE", this->CreateString(plist)); } else { @@ -2077,7 +2051,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // so let it replace the framework name. This avoids creating // a per-configuration Info.plist file. this->CurrentLocalGenerator->GenerateFrameworkInfoPList( - gtgt, "$(EXECUTABLE_NAME)", plist.c_str()); + gtgt, "$(EXECUTABLE_NAME)", plist); buildSettings->AddAttribute("INFOPLIST_FILE", this->CreateString(plist)); } else { @@ -2115,7 +2089,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // so let it replace the executable name. This avoids creating // a per-configuration Info.plist file. this->CurrentLocalGenerator->GenerateAppleInfoPList( - gtgt, "$(EXECUTABLE_NAME)", plist.c_str()); + gtgt, "$(EXECUTABLE_NAME)", plist); buildSettings->AddAttribute("INFOPLIST_FILE", this->CreateString(plist)); } @@ -2123,9 +2097,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, default: break; } - if (this->XcodeVersion < 40) { - buildSettings->AddAttribute("PREBINDING", this->CreateString("NO")); - } BuildObjectListOrString dirs(this, true); BuildObjectListOrString fdirs(this, true); @@ -2775,8 +2746,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) // Loop over configuration types and set per-configuration info. for (auto const& configName : this->CurrentConfigurationTypes) { - // Get the current configuration name. - if (this->XcodeVersion >= 50) { + { // Add object library contents as link flags. std::string linkObjs; const char* sep = ""; @@ -2886,7 +2856,7 @@ bool cmGlobalXCodeGenerator::CreateGroups( // Put cmSourceFile instances in proper groups: for (auto const& si : gtgt->GetAllConfigSources()) { cmSourceFile const* sf = si.Source; - if (this->XcodeVersion >= 50 && !sf->GetObjectLibrary().empty()) { + if (!sf->GetObjectLibrary().empty()) { // Object library files go on the link line instead. continue; } @@ -3076,16 +3046,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( v << std::setfill('0') << std::setw(4) << XcodeVersion * 10; group->AddAttribute("LastUpgradeCheck", this->CreateString(v.str())); this->RootObject->AddAttribute("attributes", group); - if (this->XcodeVersion >= 32) { - this->RootObject->AddAttribute("compatibilityVersion", - this->CreateString("Xcode 3.2")); - } else if (this->XcodeVersion >= 31) { - this->RootObject->AddAttribute("compatibilityVersion", - this->CreateString("Xcode 3.1")); - } else { - this->RootObject->AddAttribute("compatibilityVersion", - this->CreateString("Xcode 3.0")); - } + this->RootObject->AddAttribute("compatibilityVersion", + this->CreateString("Xcode 3.2")); // Point Xcode at the top of the source tree. { std::string pdir = @@ -3540,13 +3502,7 @@ void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, cmXCodeObject::Indent(1, fout); fout << "};\n"; cmXCodeObject::Indent(1, fout); - if (this->XcodeVersion >= 32) { - fout << "objectVersion = 46;\n"; - } else if (this->XcodeVersion >= 31) { - fout << "objectVersion = 45;\n"; - } else { - fout << "objectVersion = 44;\n"; - } + fout << "objectVersion = 46;\n"; cmXCode21Object::PrintList(this->XCodeObjects, fout); cmXCodeObject::Indent(1, fout); fout << "rootObject = " << this->RootObject->GetId() @@ -3714,11 +3670,7 @@ void cmGlobalXCodeGenerator::AppendFlag(std::string& flags, // Flag value with escaped quotes and backslashes. for (auto c : flag) { if (c == '\'') { - if (this->XcodeVersion >= 40) { - flags += "'\\''"; - } else { - flags += "\\'"; - } + flags += "'\\''"; } else if (c == '\\') { flags += "\\\\"; } else { diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index b224d09..93134ad 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -85,10 +85,12 @@ bool cmIncludeExternalMSProjectCommand::InitialPass( // Create a target instance for this utility. cmTarget* target = this->Makefile->AddNewTarget(cmStateEnums::UTILITY, utility_name.c_str()); + if (this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); + } target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str()); target->SetProperty("EXTERNAL_MSPROJECT", path.c_str()); - target->SetProperty("EXCLUDE_FROM_ALL", "FALSE"); if (!customType.empty()) target->SetProperty("VS_PROJECT_TYPE", customType.c_str()); diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index 155f055..c64bd8a 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallCommandArguments.h" +#include "cmRange.h" #include "cmSystemTools.h" #include <utility> @@ -220,10 +221,7 @@ void cmInstallCommandIncludesArgument::Parse( if (args->empty()) { return; } - std::vector<std::string>::const_iterator it = args->begin(); - ++it; - for (; it != args->end(); ++it) { - std::string dir = *it; + for (std::string dir : cmMakeRange(*args).advance(1)) { cmSystemTools::ConvertToUnixSlashes(dir); this->IncludeDirs.push_back(std::move(dir)); } diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index a88c7af..62ce9f2 100644 --- a/Source/cmInstallDirectoryGenerator.cxx +++ b/Source/cmInstallDirectoryGenerator.cxx @@ -31,10 +31,12 @@ cmInstallDirectoryGenerator::cmInstallDirectoryGenerator( } // We need per-config actions if any directories have generator expressions. - for (std::vector<std::string>::const_iterator i = dirs.begin(); - !this->ActionsPerConfig && i != dirs.end(); ++i) { - if (cmGeneratorExpression::Find(*i) != std::string::npos) { - this->ActionsPerConfig = true; + if (!this->ActionsPerConfig) { + for (std::string const& dir : dirs) { + if (cmGeneratorExpression::Find(dir) != std::string::npos) { + this->ActionsPerConfig = true; + break; + } } } } diff --git a/Source/cmInstallExportAndroidMKGenerator.cxx b/Source/cmInstallExportAndroidMKGenerator.cxx index 85b7021..186b9df 100644 --- a/Source/cmInstallExportAndroidMKGenerator.cxx +++ b/Source/cmInstallExportAndroidMKGenerator.cxx @@ -67,10 +67,8 @@ void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os) this->EFGen->AddConfiguration(""); } } else { - for (std::vector<std::string>::const_iterator ci = - this->ConfigurationTypes->begin(); - ci != this->ConfigurationTypes->end(); ++ci) { - this->EFGen->AddConfiguration(*ci); + for (std::string const& config : this->ConfigurationTypes) { + this->EFGen->AddConfiguration(config); } } this->EFGen->GenerateImportFile(); @@ -88,11 +86,9 @@ void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs( // Now create a configuration-specific install rule for the import // file of each configuration. std::vector<std::string> files; - for (std::map<std::string, std::string>::const_iterator i = - this->EFGen->GetConfigImportFiles().begin(); - i != this->EFGen->GetConfigImportFiles().end(); ++i) { - files.push_back(i->second); - std::string config_test = this->CreateConfigTest(i->first); + for (auto const& pair : this->EFGen->GetConfigImportFiles()) { + files.push_back(pair.second); + std::string config_test = this->CreateConfigTest(pair.first); os << indent << "if(" << config_test << ")\n"; this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files, false, this->FilePermissions.c_str(), nullptr, diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index 4dde18f..b068e46 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -7,6 +7,7 @@ #include "cmInstallFilesGenerator.h" #include "cmInstallGenerator.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmSystemTools.h" class cmExecutionStatus; @@ -27,10 +28,9 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, if ((args.size() > 1) && (args[1] == "FILES")) { this->IsFilesForm = true; - for (std::vector<std::string>::const_iterator s = args.begin() + 2; - s != args.end(); ++s) { + for (std::string const& arg : cmMakeRange(args).advance(2)) { // Find the source location for each file listed. - this->Files.push_back(this->FindInstallSource(s->c_str())); + this->Files.push_back(this->FindInstallSource(arg.c_str())); } this->CreateInstallGenerator(); } else { diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx index 07094cb..9eb8ad4 100644 --- a/Source/cmInstallFilesGenerator.cxx +++ b/Source/cmInstallFilesGenerator.cxx @@ -29,11 +29,13 @@ cmInstallFilesGenerator::cmInstallFilesGenerator( this->ActionsPerConfig = true; } - // We need per-config actions if any files have generator expressions. - for (std::vector<std::string>::const_iterator i = files.begin(); - !this->ActionsPerConfig && i != files.end(); ++i) { - if (cmGeneratorExpression::Find(*i) != std::string::npos) { - this->ActionsPerConfig = true; + // We need per-config actions if any directories have generator expressions. + if (!this->ActionsPerConfig) { + for (std::string const& file : files) { + if (cmGeneratorExpression::Find(file) != std::string::npos) { + this->ActionsPerConfig = true; + break; + } } } } diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx index d139190..bb4eb3e 100644 --- a/Source/cmInstallGenerator.cxx +++ b/Source/cmInstallGenerator.cxx @@ -69,17 +69,18 @@ void cmInstallGenerator::AddInstallRule( if (cmSystemTools::FileIsFullPath(dest)) { os << "list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES\n"; os << indent << " \""; - for (std::vector<std::string>::const_iterator fi = files.begin(); - fi != files.end(); ++fi) { - if (fi != files.begin()) { + bool firstIteration = true; + for (std::string const& file : files) { + if (!firstIteration) { os << ";"; } os << dest << "/"; if (rename && *rename) { os << rename; } else { - os << cmSystemTools::GetFilenameName(*fi); + os << cmSystemTools::GetFilenameName(file); } + firstIteration = false; } os << "\")\n"; os << indent << "if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n"; diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 59701a1..4fefe23 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -41,22 +41,6 @@ cmInstallTargetGenerator::cmInstallTargetGenerator( cmInstallTargetGenerator::~cmInstallTargetGenerator() = default; -void cmInstallTargetGenerator::GenerateScript(std::ostream& os) -{ - // Warn if installing an exclude-from-all target. - if (this->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { - std::ostringstream msg; - msg << "WARNING: Target \"" << this->Target->GetName() - << "\" has EXCLUDE_FROM_ALL set and will not be built by default " - << "but an install rule has been provided for it. CMake does " - << "not define behavior for this case."; - cmSystemTools::Message(msg.str(), "Warning"); - } - - // Perform the main install script generation. - this->cmInstallGenerator::GenerateScript(os); -} - void cmInstallTargetGenerator::GenerateScriptForConfig( std::ostream& os, const std::string& config, Indent indent) { @@ -123,19 +107,15 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( // There is a bug in cmInstallCommand if this fails. assert(this->NamelinkMode == NamelinkModeNone); - std::string targetName; - std::string targetNameReal; - std::string targetNameImport; - std::string targetNamePDB; - this->Target->GetExecutableNames(targetName, targetNameReal, - targetNameImport, targetNamePDB, config); + cmGeneratorTarget::Names targetNames = + this->Target->GetExecutableNames(config); if (this->ImportLibrary) { - std::string from1 = fromDirConfig + targetNameImport; - std::string to1 = toDir + targetNameImport; + std::string from1 = fromDirConfig + targetNames.ImportLibrary; + std::string to1 = toDir + targetNames.ImportLibrary; filesFrom.push_back(std::move(from1)); filesTo.push_back(std::move(to1)); std::string targetNameImportLib; - if (this->Target->GetImplibGNUtoMS(config, targetNameImport, + if (this->Target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, targetNameImportLib)) { filesFrom.push_back(fromDirConfig + targetNameImportLib); filesTo.push_back(toDir + targetNameImportLib); @@ -144,8 +124,8 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( // An import library looks like a static library. type = cmInstallType_STATIC_LIBRARY; } else { - std::string from1 = fromDirConfig + targetName; - std::string to1 = toDir + targetName; + std::string from1 = fromDirConfig + targetNames.Output; + std::string to1 = toDir + targetNames.Output; // Handle OSX Bundles. if (this->Target->IsAppBundleOnApple()) { @@ -170,12 +150,12 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( if (!mf->PlatformIsAppleEmbedded()) { to1 += "Contents/MacOS/"; } - to1 += targetName; + to1 += targetNames.Output; } else { // Tweaks apply to the real file, so list it first. - if (targetNameReal != targetName) { - std::string from2 = fromDirConfig + targetNameReal; - std::string to2 = toDir += targetNameReal; + if (targetNames.Real != targetNames.Output) { + std::string from2 = fromDirConfig + targetNames.Real; + std::string to2 = toDir += targetNames.Real; filesFrom.push_back(std::move(from2)); filesTo.push_back(std::move(to2)); } @@ -185,23 +165,18 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( filesTo.push_back(std::move(to1)); } } else { - std::string targetName; - std::string targetNameSO; - std::string targetNameReal; - std::string targetNameImport; - std::string targetNamePDB; - this->Target->GetLibraryNames(targetName, targetNameSO, targetNameReal, - targetNameImport, targetNamePDB, config); + cmGeneratorTarget::Names targetNames = + this->Target->GetLibraryNames(config); if (this->ImportLibrary) { // There is a bug in cmInstallCommand if this fails. assert(this->NamelinkMode == NamelinkModeNone); - std::string from1 = fromDirConfig + targetNameImport; - std::string to1 = toDir + targetNameImport; + std::string from1 = fromDirConfig + targetNames.ImportLibrary; + std::string to1 = toDir + targetNames.ImportLibrary; filesFrom.push_back(std::move(from1)); filesTo.push_back(std::move(to1)); std::string targetNameImportLib; - if (this->Target->GetImplibGNUtoMS(config, targetNameImport, + if (this->Target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, targetNameImportLib)) { filesFrom.push_back(fromDirConfig + targetNameImportLib); filesTo.push_back(toDir + targetNameImportLib); @@ -243,11 +218,11 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( type = cmInstallType_DIRECTORY; literal_args += " USE_SOURCE_PERMISSIONS"; - std::string from1 = fromDirConfig + targetName; + std::string from1 = fromDirConfig + targetNames.Output; from1 = cmSystemTools::GetFilenamePath(from1); // Tweaks apply to the binary inside the bundle. - std::string to1 = toDir + targetNameReal; + std::string to1 = toDir + targetNames.Real; filesFrom.push_back(std::move(from1)); filesTo.push_back(std::move(to1)); @@ -256,10 +231,11 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( type = cmInstallType_DIRECTORY; literal_args += " USE_SOURCE_PERMISSIONS"; - std::string targetNameBase = targetName.substr(0, targetName.find('/')); + std::string targetNameBase = + targetNames.Output.substr(0, targetNames.Output.find('/')); std::string from1 = fromDirConfig + targetNameBase; - std::string to1 = toDir + targetName; + std::string to1 = toDir + targetNames.Output; filesFrom.push_back(std::move(from1)); filesTo.push_back(std::move(to1)); @@ -267,25 +243,26 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( bool haveNamelink = false; // Library link name. - std::string fromName = fromDirConfig + targetName; - std::string toName = toDir + targetName; + std::string fromName = fromDirConfig + targetNames.Output; + std::string toName = toDir + targetNames.Output; // Library interface name. std::string fromSOName; std::string toSOName; - if (targetNameSO != targetName) { + if (targetNames.SharedObject != targetNames.Output) { haveNamelink = true; - fromSOName = fromDirConfig + targetNameSO; - toSOName = toDir + targetNameSO; + fromSOName = fromDirConfig + targetNames.SharedObject; + toSOName = toDir + targetNames.SharedObject; } // Library implementation name. std::string fromRealName; std::string toRealName; - if (targetNameReal != targetName && targetNameReal != targetNameSO) { + if (targetNames.Real != targetNames.Output && + targetNames.Real != targetNames.SharedObject) { haveNamelink = true; - fromRealName = fromDirConfig + targetNameReal; - toRealName = toDir + targetNameReal; + fromRealName = fromDirConfig + targetNames.Real; + toRealName = toDir + targetNames.Real; } // Add the names based on the current namelink mode. @@ -416,48 +393,37 @@ std::string cmInstallTargetGenerator::GetInstallFilename( std::string fname; // Compute the name of the library. if (target->GetType() == cmStateEnums::EXECUTABLE) { - std::string targetName; - std::string targetNameReal; - std::string targetNameImport; - std::string targetNamePDB; - target->GetExecutableNames(targetName, targetNameReal, targetNameImport, - targetNamePDB, config); + cmGeneratorTarget::Names targetNames = target->GetExecutableNames(config); if (nameType == NameImplib) { // Use the import library name. - if (!target->GetImplibGNUtoMS(config, targetNameImport, fname, + if (!target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, fname, "${CMAKE_IMPORT_LIBRARY_SUFFIX}")) { - fname = targetNameImport; + fname = targetNames.ImportLibrary; } } else if (nameType == NameReal) { // Use the canonical name. - fname = targetNameReal; + fname = targetNames.Real; } else { // Use the canonical name. - fname = targetName; + fname = targetNames.Output; } } else { - std::string targetName; - std::string targetNameSO; - std::string targetNameReal; - std::string targetNameImport; - std::string targetNamePDB; - target->GetLibraryNames(targetName, targetNameSO, targetNameReal, - targetNameImport, targetNamePDB, config); + cmGeneratorTarget::Names targetNames = target->GetLibraryNames(config); if (nameType == NameImplib) { // Use the import library name. - if (!target->GetImplibGNUtoMS(config, targetNameImport, fname, + if (!target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, fname, "${CMAKE_IMPORT_LIBRARY_SUFFIX}")) { - fname = targetNameImport; + fname = targetNames.ImportLibrary; } } else if (nameType == NameSO) { // Use the soname. - fname = targetNameSO; + fname = targetNames.SharedObject; } else if (nameType == NameReal) { // Use the real name. - fname = targetNameReal; + fname = targetNames.Real; } else { // Use the canonical name. - fname = targetName; + fname = targetNames.Output; } } @@ -825,7 +791,7 @@ void cmInstallTargetGenerator::AddRanlibRule(std::ostream& os, Indent indent, return; } - std::string ranlib = + const std::string& ranlib = this->Target->Target->GetMakefile()->GetRequiredDefinition("CMAKE_RANLIB"); if (ranlib.empty()) { return; diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h index 715b4ae..6df5b1a 100644 --- a/Source/cmInstallTargetGenerator.h +++ b/Source/cmInstallTargetGenerator.h @@ -69,7 +69,6 @@ public: cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; } protected: - void GenerateScript(std::ostream& os) override; void GenerateScriptForConfig(std::ostream& os, const std::string& config, Indent indent) override; void GenerateScriptForConfigObjectLibrary(std::ostream& os, diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index 070b954..b7d602e 100644 --- a/Source/cmInstalledFile.h +++ b/Source/cmInstalledFile.h @@ -32,6 +32,9 @@ public: Property(); ~Property(); + Property(const Property&) = delete; + Property& operator=(const Property&) = delete; + ExpressionVectorType ValueExpressions; }; @@ -41,6 +44,9 @@ public: ~cmInstalledFile(); + cmInstalledFile(const cmInstalledFile&) = delete; + cmInstalledFile& operator=(const cmInstalledFile&) = delete; + void RemoveProperty(const std::string& prop); void SetProperty(cmMakefile const* mf, const std::string& prop, diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 297babf..5474afa 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -19,6 +19,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmStringReplaceHelper.h" #include "cmSystemTools.h" @@ -42,6 +43,15 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args, if (subCommand == "APPEND") { return this->HandleAppendCommand(args); } + if (subCommand == "PREPEND") { + return this->HandlePrependCommand(args); + } + if (subCommand == "POP_BACK") { + return this->HandlePopBackCommand(args); + } + if (subCommand == "POP_FRONT") { + return this->HandlePopFrontCommand(args); + } if (subCommand == "FIND") { return this->HandleFindCommand(args); } @@ -222,20 +232,141 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args) return true; } - const std::string& listName = args[1]; + std::string const& listName = args[1]; // expand the variable std::string listString; this->GetListString(listString, listName); - if (!listString.empty() && !args.empty()) { - listString += ";"; + // If `listString` or `args` is empty, no need to append `;`, + // then index is going to be `1` and points to the end-of-string ";" + auto const offset = + std::string::size_type(listString.empty() || args.empty()); + listString += &";"[offset] + cmJoin(cmMakeRange(args).advance(2), ";"); + + this->Makefile->AddDefinition(listName, listString.c_str()); + return true; +} + +bool cmListCommand::HandlePrependCommand(std::vector<std::string> const& args) +{ + assert(args.size() >= 2); + + // Skip if nothing to prepend. + if (args.size() < 3) { + return true; } - listString += cmJoin(cmMakeRange(args).advance(2), ";"); + + std::string const& listName = args[1]; + // expand the variable + std::string listString; + this->GetListString(listString, listName); + + // If `listString` or `args` is empty, no need to append `;`, + // then `offset` is going to be `1` and points to the end-of-string ";" + auto const offset = + std::string::size_type(listString.empty() || args.empty()); + listString.insert(0, + cmJoin(cmMakeRange(args).advance(2), ";") + &";"[offset]); this->Makefile->AddDefinition(listName, listString.c_str()); return true; } +bool cmListCommand::HandlePopBackCommand(std::vector<std::string> const& args) +{ + assert(args.size() >= 2); + + auto ai = args.cbegin(); + ++ai; // Skip subcommand name + std::string const& listName = *ai++; + std::vector<std::string> varArgsExpanded; + if (!this->GetList(varArgsExpanded, listName)) { + // Can't get the list definition... undefine any vars given after. + for (; ai != args.cend(); ++ai) { + this->Makefile->RemoveDefinition(*ai); + } + return true; + } + + if (!varArgsExpanded.empty()) { + if (ai == args.cend()) { + // No variables are given... Just remove one element. + varArgsExpanded.pop_back(); + } else { + // Ok, assign elements to be removed to the given variables + for (; !varArgsExpanded.empty() && ai != args.cend(); ++ai) { + assert(!ai->empty()); + this->Makefile->AddDefinition(*ai, varArgsExpanded.back().c_str()); + varArgsExpanded.pop_back(); + } + // Undefine the rest variables if the list gets empty earlier... + for (; ai != args.cend(); ++ai) { + this->Makefile->RemoveDefinition(*ai); + } + } + + this->Makefile->AddDefinition(listName, + cmJoin(varArgsExpanded, ";").c_str()); + + } else if (ai != + args.cend()) { // The list is empty, but some args were given + // Need to *undefine* 'em all, cuz there are no items to assign... + for (; ai != args.cend(); ++ai) { + this->Makefile->RemoveDefinition(*ai); + } + } + + return true; +} + +bool cmListCommand::HandlePopFrontCommand(std::vector<std::string> const& args) +{ + assert(args.size() >= 2); + + auto ai = args.cbegin(); + ++ai; // Skip subcommand name + std::string const& listName = *ai++; + std::vector<std::string> varArgsExpanded; + if (!this->GetList(varArgsExpanded, listName)) { + // Can't get the list definition... undefine any vars given after. + for (; ai != args.cend(); ++ai) { + this->Makefile->RemoveDefinition(*ai); + } + return true; + } + + if (!varArgsExpanded.empty()) { + if (ai == args.cend()) { + // No variables are given... Just remove one element. + varArgsExpanded.erase(varArgsExpanded.begin()); + } else { + // Ok, assign elements to be removed to the given variables + auto vi = varArgsExpanded.begin(); + for (; vi != varArgsExpanded.end() && ai != args.cend(); ++ai, ++vi) { + assert(!ai->empty()); + this->Makefile->AddDefinition(*ai, varArgsExpanded.front().c_str()); + } + varArgsExpanded.erase(varArgsExpanded.begin(), vi); + // Undefine the rest variables if the list gets empty earlier... + for (; ai != args.cend(); ++ai) { + this->Makefile->RemoveDefinition(*ai); + } + } + + this->Makefile->AddDefinition(listName, + cmJoin(varArgsExpanded, ";").c_str()); + + } else if (ai != + args.cend()) { // The list is empty, but some args were given + // Need to *undefine* 'em all, cuz there are no items to assign... + for (; ai != args.cend(); ++ai) { + this->Makefile->RemoveDefinition(*ai); + } + } + + return true; +} + bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args) { if (args.size() != 4) { diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h index 76a9856..ea3d643 100644 --- a/Source/cmListCommand.h +++ b/Source/cmListCommand.h @@ -35,6 +35,9 @@ protected: bool HandleLengthCommand(std::vector<std::string> const& args); bool HandleGetCommand(std::vector<std::string> const& args); bool HandleAppendCommand(std::vector<std::string> const& args); + bool HandlePrependCommand(std::vector<std::string> const& args); + bool HandlePopBackCommand(std::vector<std::string> const& args); + bool HandlePopFrontCommand(std::vector<std::string> const& args); bool HandleFindCommand(std::vector<std::string> const& args); bool HandleInsertCommand(std::vector<std::string> const& args); bool HandleJoinCommand(std::vector<std::string> const& args); diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index f855119..f99caed 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -27,6 +27,8 @@ struct cmListFileParser cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt, cmMessenger* messenger, const char* filename); ~cmListFileParser(); + cmListFileParser(const cmListFileParser&) = delete; + cmListFileParser& operator=(const cmListFileParser&) = delete; void IssueFileOpenError(std::string const& text) const; void IssueError(std::string const& text) const; bool ParseFile(); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8090e00..a14fd7d 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -34,6 +34,7 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> #include <assert.h> +#include <initializer_list> #include <iterator> #include <sstream> #include <stdio.h> @@ -51,25 +52,23 @@ // replaced in the form <var> with GetSafeDefinition(var). // ${LANG} is replaced in the variable first with all enabled // languages. -static const char* ruleReplaceVars[] = { - "CMAKE_${LANG}_COMPILER", - "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS", - "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS", - "CMAKE_SHARED_MODULE_${LANG}_FLAGS", - "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS", - "CMAKE_${LANG}_LINK_FLAGS", - "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG", - "CMAKE_${LANG}_ARCHIVE", - "CMAKE_AR", - "CMAKE_CURRENT_SOURCE_DIR", - "CMAKE_CURRENT_BINARY_DIR", - "CMAKE_RANLIB", - "CMAKE_LINKER", - "CMAKE_MT", - "CMAKE_CUDA_HOST_COMPILER", - "CMAKE_CUDA_HOST_LINK_LAUNCHER", - "CMAKE_CL_SHOWINCLUDES_PREFIX" -}; +static auto ruleReplaceVars = { "CMAKE_${LANG}_COMPILER", + "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS", + "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS", + "CMAKE_SHARED_MODULE_${LANG}_FLAGS", + "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS", + "CMAKE_${LANG}_LINK_FLAGS", + "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG", + "CMAKE_${LANG}_ARCHIVE", + "CMAKE_AR", + "CMAKE_CURRENT_SOURCE_DIR", + "CMAKE_CURRENT_BINARY_DIR", + "CMAKE_RANLIB", + "CMAKE_LINKER", + "CMAKE_MT", + "CMAKE_CUDA_HOST_COMPILER", + "CMAKE_CUDA_HOST_LINK_LAUNCHER", + "CMAKE_CL_SHOWINCLUDES_PREFIX" }; cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) : cmOutputConverter(makefile->GetStateSnapshot()) @@ -138,15 +137,13 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) this->VariableMappings[compilerOptionSysroot] = this->Makefile->GetSafeDefinition(compilerOptionSysroot); - for (const char* const* replaceIter = cm::cbegin(ruleReplaceVars); - replaceIter != cm::cend(ruleReplaceVars); ++replaceIter) { - std::string actualReplace = *replaceIter; - if (actualReplace.find("${LANG}") != std::string::npos) { - cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang); + for (std::string replaceVar : ruleReplaceVars) { + if (replaceVar.find("${LANG}") != std::string::npos) { + cmSystemTools::ReplaceString(replaceVar, "${LANG}", lang); } - this->VariableMappings[actualReplace] = - this->Makefile->GetSafeDefinition(actualReplace); + this->VariableMappings[replaceVar] = + this->Makefile->GetSafeDefinition(replaceVar); } } } @@ -369,8 +366,8 @@ void cmLocalGenerator::ProcessEvaluationFiles( std::back_inserter(intersection)); if (!intersection.empty()) { cmSystemTools::Error("Files to be generated by multiple different " - "commands: ", - cmWrap('"', intersection, '"', " ").c_str()); + "commands: " + + cmWrap('"', intersection, '"', " ")); return; } @@ -779,7 +776,7 @@ std::string cmLocalGenerator::GetIncludeFlags( #endif for (std::string const& i : includes) { if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") && - cmSystemTools::IsPathToFramework(i.c_str())) { + cmSystemTools::IsPathToFramework(i)) { std::string frameworkDir = i; frameworkDir += "/../"; frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); @@ -920,6 +917,20 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit( return result; } + // Standard include directories to be added unconditionally at the end. + // These are intended to simulate additional implicit include directories. + std::vector<std::string> userStandardDirs; + { + std::string key = "CMAKE_"; + key += lang; + key += "_STANDARD_INCLUDE_DIRECTORIES"; + std::string const value = this->Makefile->GetSafeDefinition(key); + cmSystemTools::ExpandListArgument(value, userStandardDirs); + for (std::string& usd : userStandardDirs) { + cmSystemTools::ConvertToUnixSlashes(usd); + } + } + // Implicit include directories std::vector<std::string> implicitDirs; std::set<std::string> implicitSet; @@ -928,24 +939,27 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit( return (implicitSet.find(dir) == implicitSet.end()); }; { - std::string rootPath; - if (const char* sysrootCompile = - this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE")) { - rootPath = sysrootCompile; - } else { - rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT"); - } - cmSystemTools::ConvertToUnixSlashes(rootPath); - // Raw list of implicit include directories - std::vector<std::string> impDirVec; + // Start with "standard" directories that we unconditionally add below. + std::vector<std::string> impDirVec = userStandardDirs; // Load implicit include directories for this language. - std::string key = "CMAKE_"; - key += lang; - key += "_IMPLICIT_INCLUDE_DIRECTORIES"; - if (const char* value = this->Makefile->GetDefinition(key)) { - cmSystemTools::ExpandListArgument(value, impDirVec); + // We ignore this for Fortran because: + // * There are no standard library headers to avoid overriding. + // * Compilers like gfortran do not search their own implicit include + // directories for modules ('.mod' files). + if (lang != "Fortran") { + std::string key = "CMAKE_"; + key += lang; + key += "_IMPLICIT_INCLUDE_DIRECTORIES"; + if (const char* value = this->Makefile->GetDefinition(key)) { + size_t const impDirVecOldSize = impDirVec.size(); + cmSystemTools::ExpandListArgument(value, impDirVec); + // FIXME: Use cmRange with 'advance()' when it supports non-const. + for (size_t i = impDirVecOldSize; i < impDirVec.size(); ++i) { + cmSystemTools::ConvertToUnixSlashes(impDirVec[i]); + } + } } // The Platform/UnixPaths module used to hard-code /usr/include for C, CXX, @@ -965,13 +979,8 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit( } for (std::string const& i : impDirVec) { - std::string imd = i; - cmSystemTools::ConvertToUnixSlashes(imd); - if (!rootPath.empty() && !cmHasPrefix(imd, rootPath)) { - imd = rootPath + imd; - } - if (implicitSet.insert(imd).second) { - implicitDirs.emplace_back(std::move(imd)); + if (implicitSet.insert(i).second) { + implicitDirs.emplace_back(i); } } } @@ -1010,23 +1019,10 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit( MoveSystemIncludesToEnd(result, config, lang, target); // Append standard include directories for this language. - { - std::vector<std::string> userStandardDirs; - { - std::string key = "CMAKE_"; - key += lang; - key += "_STANDARD_INCLUDE_DIRECTORIES"; - std::string const value = this->Makefile->GetSafeDefinition(key); - cmSystemTools::ExpandListArgument(value, userStandardDirs); - } - userDirs.reserve(userDirs.size() + userStandardDirs.size()); - for (std::string& usd : userStandardDirs) { - cmSystemTools::ConvertToUnixSlashes(usd); - if (notImplicit(usd)) { - emitDir(usd); - } - userDirs.emplace_back(std::move(usd)); - } + userDirs.reserve(userDirs.size() + userStandardDirs.size()); + for (std::string& usd : userStandardDirs) { + emitDir(usd); + userDirs.emplace_back(std::move(usd)); } // Append compiler implicit include directories @@ -1178,8 +1174,8 @@ void cmLocalGenerator::GetTargetFlags( } if (linkLanguage.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - target->GetName().c_str()); + "CMake can not determine linker language for target: " + + target->GetName()); return; } this->AddLanguageFlagsForLinking(flags, target, linkLanguage, buildType); @@ -1378,9 +1374,9 @@ void cmLocalGenerator::OutputLinkLibraries( std::string linkLanguage = cli.GetLinkLanguage(); - std::string libPathFlag = + const std::string& libPathFlag = this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG"); - std::string libPathTerminator = + const std::string& libPathTerminator = this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR"); // Add standard libraries for this language. @@ -2237,11 +2233,8 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines, dflag = df; } } - - std::set<std::string>::const_iterator defineIt = defines.begin(); - const std::set<std::string>::const_iterator defineEnd = defines.end(); const char* itemSeparator = definesString.empty() ? "" : " "; - for (; defineIt != defineEnd; ++defineIt) { + for (std::string const& define : defines) { // Append the definition with proper escaping. std::string def = dflag; if (this->GetState()->UseWatcomWMake()) { @@ -2255,7 +2248,7 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines, // command line without any escapes. However we still have to // get the '$' and '#' characters through WMake as '$$' and // '$#'. - for (const char* c = defineIt->c_str(); *c; ++c) { + for (const char* c = define.c_str(); *c; ++c) { if (*c == '$' || *c == '#') { def += '$'; } @@ -2264,11 +2257,11 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines, } else { // Make the definition appear properly on the command line. Use // -DNAME="value" instead of -D"NAME=value" for historical reasons. - std::string::size_type eq = defineIt->find("="); - def += defineIt->substr(0, eq); + std::string::size_type eq = define.find('='); + def += define.substr(0, eq); if (eq != std::string::npos) { def += "="; - def += this->EscapeForShell(defineIt->c_str() + eq + 1, true); + def += this->EscapeForShell(define.c_str() + eq + 1, true); } } definesString += itemSeparator; @@ -2825,7 +2818,7 @@ static void cmLGInfoProp(cmMakefile* mf, cmGeneratorTarget* target, void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target, const std::string& targetName, - const char* fname) + const std::string& fname) { // Find the Info.plist template. const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST"); @@ -2859,11 +2852,12 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target, cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING"); cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION"); cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT"); - mf->ConfigureFile(inFile.c_str(), fname, false, false, false); + mf->ConfigureFile(inFile, fname, false, false, false); } void cmLocalGenerator::GenerateFrameworkInfoPList( - cmGeneratorTarget* target, const std::string& targetName, const char* fname) + cmGeneratorTarget* target, const std::string& targetName, + const std::string& fname) { // Find the Info.plist template. const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST"); @@ -2893,5 +2887,5 @@ void cmLocalGenerator::GenerateFrameworkInfoPList( cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER"); cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING"); cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION"); - mf->ConfigureFile(inFile.c_str(), fname, false, false, false); + mf->ConfigureFile(inFile, fname, false, false, false); } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index f9839f6..de12190 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -340,14 +340,14 @@ public: */ void GenerateAppleInfoPList(cmGeneratorTarget* target, const std::string& targetName, - const char* fname); + const std::string& fname); /** * Generate a macOS framework Info.plist file. */ void GenerateFrameworkInfoPList(cmGeneratorTarget* target, const std::string& targetName, - const char* fname); + const std::string& fname); /** Construct a comment for a custom command. */ std::string ConstructComment(cmCustomCommandGenerator const& ccg, const char* default_comment = ""); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index c0afc25..f4e3ed8 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -232,8 +232,8 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os) os << " depth = " << jobs << std::endl; os << std::endl; } else { - cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': ", - pool.c_str()); + cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': " + + pool); } } } @@ -466,10 +466,12 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( cmNinjaDeps ninjaOutputs(outputs.size() + byproducts.size()), ninjaDeps; bool symbolic = false; - for (std::vector<std::string>::const_iterator o = outputs.begin(); - !symbolic && o != outputs.end(); ++o) { - if (cmSourceFile* sf = this->Makefile->GetSource(*o)) { + for (std::string const& output : outputs) { + if (cmSourceFile* sf = this->Makefile->GetSource(output)) { symbolic = sf->GetPropertyAsBool("SYMBOLIC"); + if (symbolic) { + break; + } } } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 7eb4a03..33a31dd 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -22,6 +22,7 @@ #include "cmMakefile.h" #include "cmMakefileTargetGenerator.h" #include "cmOutputConverter.h" +#include "cmRange.h" #include "cmRulePlaceholderExpander.h" #include "cmSourceFile.h" #include "cmState.h" @@ -1054,7 +1055,7 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand( std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile); cmsys::ofstream fout(cleanfilePath.c_str()); if (!fout) { - cmSystemTools::Error("Could not create ", cleanfilePath.c_str()); + cmSystemTools::Error("Could not create " + cleanfilePath); } if (!files.empty()) { fout << "file(REMOVE_RECURSE\n"; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7019552..a497308 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -118,8 +118,8 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles() // If not an in source build, then create the output directory if (this->GetCurrentBinaryDirectory() != this->GetSourceDirectory()) { if (!cmSystemTools::MakeDirectory(this->GetCurrentBinaryDirectory())) { - cmSystemTools::Error("Error creating directory ", - this->GetCurrentBinaryDirectory().c_str()); + cmSystemTools::Error("Error creating directory " + + this->GetCurrentBinaryDirectory()); } } @@ -283,7 +283,7 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() file->GetFullPath(); return file; } else { - cmSystemTools::Error("Error adding rule for ", makefileIn.c_str()); + cmSystemTools::Error("Error adding rule for " + makefileIn); return nullptr; } } @@ -293,9 +293,8 @@ void cmLocalVisualStudio7Generator::WriteConfigurations( const std::string& libName, cmGeneratorTarget* target) { fout << "\t<Configurations>\n"; - for (std::vector<std::string>::const_iterator i = configs.begin(); - i != configs.end(); ++i) { - this->WriteConfiguration(fout, i->c_str(), libName, target); + for (std::string const& config : configs) { + this->WriteConfiguration(fout, config.c_str(), libName, target); } fout << "\t</Configurations>\n"; } @@ -569,9 +568,8 @@ public: void Finish() { this->Stream << (this->First ? "" : "\"") << "/>\n"; } void Write(std::vector<cmCustomCommand> const& ccs) { - for (std::vector<cmCustomCommand>::const_iterator ci = ccs.begin(); - ci != ccs.end(); ++ci) { - this->Write(*ci); + for (cmCustomCommand const& command : ccs) { + this->Write(command); } } void Write(cmCustomCommand const& cc) @@ -656,8 +654,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( : target->GetLinkerLanguage(configName)); if (linkLanguage.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - target->GetName().c_str()); + "CMake can not determine linker language for target: " + + target->GetName()); return; } langForClCompile = linkLanguage; @@ -897,10 +895,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( target->GetManifests(manifest_srcs, configName); if (!manifest_srcs.empty()) { fout << "\n\t\t\t\tAdditionalManifestFiles=\""; - for (std::vector<cmSourceFile const*>::const_iterator mi = - manifest_srcs.begin(); - mi != manifest_srcs.end(); ++mi) { - std::string m = (*mi)->GetFullPath(); + for (cmSourceFile const* manifest : manifest_srcs) { + std::string m = manifest->GetFullPath(); fout << this->ConvertToXMLOutputPath(m.c_str()) << ";"; } fout << "\""; @@ -931,7 +927,7 @@ std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags( std::string extraLinkOptionsBuildTypeDef = rootLinkerFlags + "_" + configTypeUpper; - std::string extraLinkOptionsBuildType = + const std::string& extraLinkOptionsBuildType = this->Makefile->GetRequiredDefinition(extraLinkOptionsBuildTypeDef); return extraLinkOptionsBuildType; @@ -947,21 +943,18 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( std::string extraLinkOptions; if (target->GetType() == cmStateEnums::EXECUTABLE) { extraLinkOptions = - this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") + - std::string(" ") + + this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") + " " + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName); } if (target->GetType() == cmStateEnums::SHARED_LIBRARY) { extraLinkOptions = this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS") + - std::string(" ") + - GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName); + " " + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName); } if (target->GetType() == cmStateEnums::MODULE_LIBRARY) { extraLinkOptions = this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS") + - std::string(" ") + - GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName); + " " + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName); } const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); @@ -1050,13 +1043,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( } case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: { - std::string targetName; - std::string targetNameSO; - std::string targetNameFull; - std::string targetNameImport; - std::string targetNamePDB; - target->GetLibraryNames(targetName, targetNameSO, targetNameFull, - targetNameImport, targetNamePDB, configName); + cmGeneratorTarget::Names targetNames = + target->GetLibraryNames(configName); // Compute the link library and directory information. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName); @@ -1092,7 +1080,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( fout << "\"\n"; temp = target->GetDirectory(configName); temp += "/"; - temp += targetNameFull; + temp += targetNames.Output; fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; this->WriteTargetVersionAttribute(fout, target); @@ -1102,7 +1090,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( fout << "\"\n"; temp = target->GetPDBDirectory(configName); temp += "/"; - temp += targetNamePDB; + temp += targetNames.PDB; fout << "\t\t\t\tProgramDatabaseFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; if (targetOptions.IsDebug()) { @@ -1125,7 +1113,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( temp = target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact); temp += "/"; - temp += targetNameImport; + temp += targetNames.ImportLibrary; fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\""; if (this->FortranProject) { @@ -1134,12 +1122,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( fout << "/>\n"; } break; case cmStateEnums::EXECUTABLE: { - std::string targetName; - std::string targetNameFull; - std::string targetNameImport; - std::string targetNamePDB; - target->GetExecutableNames(targetName, targetNameFull, targetNameImport, - targetNamePDB, configName); + cmGeneratorTarget::Names targetNames = + target->GetExecutableNames(configName); // Compute the link library and directory information. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName); @@ -1177,7 +1161,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( fout << "\"\n"; temp = target->GetDirectory(configName); temp += "/"; - temp += targetNameFull; + temp += targetNames.Output; fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; this->WriteTargetVersionAttribute(fout, target); @@ -1187,8 +1171,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( fout << "\"\n"; std::string path = this->ConvertToXMLOutputPathSingle( target->GetPDBDirectory(configName).c_str()); - fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB - << "\"\n"; + fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" + << targetNames.PDB << "\"\n"; if (targetOptions.IsDebug()) { fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n"; } @@ -1223,7 +1207,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( temp = target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact); temp += "/"; - temp += targetNameImport; + temp += targetNames.ImportLibrary; fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n"; break; @@ -1303,14 +1287,14 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries( { cmLocalVisualStudio7Generator* lg = this->LocalGenerator; std::string currentBinDir = lg->GetCurrentBinaryDirectory(); - for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { - if (l->IsPath) { + for (auto const& lib : libs) { + if (lib.IsPath) { std::string rel = - lg->MaybeConvertToRelativePath(currentBinDir, l->Value.c_str()); + lg->MaybeConvertToRelativePath(currentBinDir, lib.Value.c_str()); fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " "; - } else if (!l->Target || - l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { - fout << l->Value << " "; + } else if (!lib.Target || + lib.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { + fout << lib.Value << " "; } } } @@ -1328,10 +1312,9 @@ void cmLocalVisualStudio7GeneratorInternals::OutputObjects( gt->GetExternalObjects(objs, configName); const char* sep = isep ? isep : ""; - for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin(); - i != objs.end(); ++i) { - if (!(*i)->GetObjectLibrary().empty()) { - std::string const& objFile = (*i)->GetFullPath(); + for (cmSourceFile const* obj : objs) { + if (!obj->GetObjectLibrary().empty()) { + std::string const& objFile = obj->GetFullPath(); std::string rel = lg->MaybeConvertToRelativePath(currentBinDir, objFile); fout << sep << lg->ConvertToXMLOutputPath(rel.c_str()); sep = " "; @@ -1344,10 +1327,8 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories( { const char* comma = ""; std::string currentBinDir = this->GetCurrentBinaryDirectory(); - for (std::vector<std::string>::const_iterator d = dirs.begin(); - d != dirs.end(); ++d) { + for (std::string dir : dirs) { // Remove any trailing slash and skip empty paths. - std::string dir = *d; if (dir.back() == '/') { dir = dir.substr(0, dir.size() - 1); } @@ -1483,9 +1464,8 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( // Compute per-source, per-config information. size_t ci = 0; - for (std::vector<std::string>::const_iterator i = configs.begin(); - i != configs.end(); ++i, ++ci) { - std::string configUpper = cmSystemTools::UpperCase(*i); + for (std::string const& config : configs) { + std::string configUpper = cmSystemTools::UpperCase(config); cmLVS7GFileConfig fc; std::string lang = @@ -1498,7 +1478,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( lang = sourceLang; } - cmGeneratorExpressionInterpreter genexInterpreter(lg, *i, gt, lang); + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gt, lang); bool needfc = false; if (!objectName.empty()) { @@ -1564,7 +1544,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( } } - const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str()); + const std::string& linkLanguage = gt->GetLinkerLanguage(config.c_str()); // If HEADER_FILE_ONLY is set, we must suppress this generation in // the project file fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") || @@ -1589,8 +1569,9 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( } if (needfc) { - this->FileConfigMap[*i] = fc; + this->FileConfigMap[config] = fc; } + ++ci; } } @@ -1654,16 +1635,14 @@ bool cmLocalVisualStudio7Generator::WriteGroup( } // Loop through each source in the source group. - for (std::vector<const cmSourceFile*>::const_iterator sf = - sourceFiles.begin(); - sf != sourceFiles.end(); ++sf) { - std::string source = (*sf)->GetFullPath(); + for (const cmSourceFile* sf : sourceFiles) { + std::string source = sf->GetFullPath(); if (source != libName || target->GetType() == cmStateEnums::UTILITY || target->GetType() == cmStateEnums::GLOBAL_TARGET) { // Look up the source kind and configs. std::map<cmSourceFile const*, size_t>::const_iterator map_it = - sources.Index.find(*sf); + sources.Index.find(sf); // The map entry must exist because we populated it earlier. assert(map_it != sources.Index.end()); cmGeneratorTarget::AllConfigSource const& acs = @@ -1676,7 +1655,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup( // Tell MS-Dev what the source is. If the compiler knows how to // build it, then it will. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n"; - if (cmCustomCommand const* command = (*sf)->GetCustomCommand()) { + if (cmCustomCommand const* command = sf->GetCustomCommand()) { this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo); } else if (!fcinfo.FileConfigMap.empty()) { const char* aCompilerTool = "VCCLCompilerTool"; @@ -1684,8 +1663,8 @@ bool cmLocalVisualStudio7Generator::WriteGroup( if (this->FortranProject) { aCompilerTool = "VFFortranCompilerTool"; } - std::string const& lang = (*sf)->GetLanguage(); - std::string ext = (*sf)->GetExtension(); + std::string const& lang = sf->GetLanguage(); + std::string ext = sf->GetExtension(); ext = cmSystemTools::LowerCase(ext); if (ext == "idl") { aCompilerTool = "VCMIDLTool"; @@ -1713,12 +1692,10 @@ bool cmLocalVisualStudio7Generator::WriteGroup( if (acs.Kind == cmGeneratorTarget::SourceKindExternalObject) { aCompilerTool = "VCCustomBuildTool"; } - for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci = - fcinfo.FileConfigMap.begin(); - fci != fcinfo.FileConfigMap.end(); ++fci) { - cmLVS7GFileConfig const& fc = fci->second; + for (auto const& fci : fcinfo.FileConfigMap) { + cmLVS7GFileConfig const& fc = fci.second; fout << "\t\t\t\t<FileConfiguration\n" - << "\t\t\t\t\tName=\"" << fci->first << "|" + << "\t\t\t\t\tName=\"" << fci.first << "|" << gg->GetPlatformName() << "\""; if (fc.ExcludedFromBuild) { fout << " ExcludedFromBuild=\"true\""; @@ -1741,7 +1718,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup( fileOptions.AddDefines(fc.CompileDefsConfig); // validate source level include directories std::vector<std::string> includes; - this->AppendIncludeDirectories(includes, fc.IncludeDirs, **sf); + this->AppendIncludeDirectories(includes, fc.IncludeDirs, *sf); fileOptions.AddIncludes(includes); fileOptions.OutputFlagMap(fout, 5); fileOptions.OutputAdditionalIncludeDirectories( @@ -1794,12 +1771,11 @@ void cmLocalVisualStudio7Generator::WriteCustomRule( if (this->FortranProject) { customTool = "VFCustomBuildTool"; } - for (std::vector<std::string>::const_iterator i = configs.begin(); - i != configs.end(); ++i) { - cmCustomCommandGenerator ccg(command, *i, this); - cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i]; + for (std::string const& config : configs) { + cmCustomCommandGenerator ccg(command, config, this); + cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[config]; fout << "\t\t\t\t<FileConfiguration\n"; - fout << "\t\t\t\t\tName=\"" << *i << "|" << gg->GetPlatformName() + fout << "\t\t\t\t\tName=\"" << config << "|" << gg->GetPlatformName() << "\">\n"; if (!fc.CompileFlags.empty()) { fout << "\t\t\t\t\t<Tool\n" @@ -1811,7 +1787,7 @@ void cmLocalVisualStudio7Generator::WriteCustomRule( std::string comment = this->ConstructComment(ccg); std::string script = this->ConstructScript(ccg); if (this->FortranProject) { - cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str()); + cmSystemTools::ReplaceString(script, "$(Configuration)", config.c_str()); } /* clang-format off */ fout << "\t\t\t\t\t<Tool\n" @@ -1832,12 +1808,10 @@ void cmLocalVisualStudio7Generator::WriteCustomRule( fout << this->ConvertToXMLOutputPath(source); } else { // Write out the dependencies for the rule. - for (std::vector<std::string>::const_iterator d = - ccg.GetDepends().begin(); - d != ccg.GetDepends().end(); ++d) { + for (std::string const& d : ccg.GetDepends()) { // Get the real name of the dependency in case it is a CMake target. std::string dep; - if (this->GetRealDependency(d->c_str(), i->c_str(), dep)) { + if (this->GetRealDependency(d.c_str(), config.c_str(), dep)) { fout << this->ConvertToXMLOutputPath(dep.c_str()) << ";"; } } @@ -1849,10 +1823,8 @@ void cmLocalVisualStudio7Generator::WriteCustomRule( } else { // Write a rule for the output generated by this command. const char* sep = ""; - for (std::vector<std::string>::const_iterator o = - ccg.GetOutputs().begin(); - o != ccg.GetOutputs().end(); ++o) { - fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str()); + for (std::string const& output : ccg.GetOutputs()) { + fout << sep << this->ConvertToXMLOutputPathSingle(output.c_str()); sep = ";"; } } @@ -2063,16 +2035,14 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter( { fout << "\t<Globals>\n"; - std::vector<std::string> const& props = target->GetPropertyKeys(); - for (std::vector<std::string>::const_iterator i = props.begin(); - i != props.end(); ++i) { - if (i->find("VS_GLOBAL_") == 0) { - std::string name = i->substr(10); + for (std::string const& key : target->GetPropertyKeys()) { + if (key.find("VS_GLOBAL_") == 0) { + std::string name = key.substr(10); if (!name.empty()) { /* clang-format off */ fout << "\t\t<Global\n" << "\t\t\tName=\"" << name << "\"\n" - << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n" + << "\t\t\tValue=\"" << target->GetProperty(key) << "\"\n" << "\t\t/>\n"; /* clang-format on */ } diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 7279d5f..6565f02 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -10,6 +10,7 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmPolicies.h" +#include "cmRange.h" #include "cmState.h" #include "cmSystemTools.h" diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7e33bda..ab37774 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -31,6 +31,7 @@ #include "cmInstallSubdirectoryGenerator.h" #include "cmListFileCache.h" #include "cmMessageType.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmState.h" @@ -292,13 +293,14 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const std::string const& only_filename = cmSystemTools::GetFilenameName(full_path); bool trace = trace_only_this_files.empty(); if (!trace) { - for (std::vector<std::string>::const_iterator i = - trace_only_this_files.begin(); - !trace && i != trace_only_this_files.end(); ++i) { - std::string::size_type const pos = full_path.rfind(*i); + for (std::string const& file : trace_only_this_files) { + std::string::size_type const pos = full_path.rfind(file); trace = (pos != std::string::npos) && - ((pos + i->size()) == full_path.size()) && - (only_filename == cmSystemTools::GetFilenameName(*i)); + ((pos + file.size()) == full_path.size()) && + (only_filename == cmSystemTools::GetFilenameName(file)); + if (trace) { + break; + } } // Do nothing if current file wasn't requested for trace... if (!trace) { @@ -347,6 +349,9 @@ public: this->Makefile->Backtrace = this->Makefile->Backtrace.Pop(); } + cmMakefileCall(const cmMakefileCall&) = delete; + cmMakefileCall& operator=(const cmMakefileCall&) = delete; + private: cmMakefile* Makefile; }; @@ -438,6 +443,9 @@ public: ~IncludeScope(); void Quiet() { this->ReportError = false; } + IncludeScope(const IncludeScope&) = delete; + IncludeScope& operator=(const IncludeScope&) = delete; + private: cmMakefile* Makefile; bool NoPolicyScope; @@ -605,6 +613,9 @@ public: void Quiet() { this->ReportError = false; } + ListFileScope(const ListFileScope&) = delete; + ListFileScope& operator=(const ListFileScope&) = delete; + private: cmMakefile* Makefile; bool ReportError; @@ -949,9 +960,8 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( if (file && file->GetCustomCommand() && !replace) { // The rule file already exists. if (commandLines != file->GetCustomCommand()->GetCommandLines()) { - cmSystemTools::Error("Attempt to add a custom rule to output \"", - outName.c_str(), - "\" which already has a custom rule."); + cmSystemTools::Error("Attempt to add a custom rule to output \"" + + outName + "\" which already has a custom rule."); } return file; } @@ -1091,8 +1101,8 @@ void cmMakefile::AddCustomCommandOldStyle( ti->second.AddSource(sf->GetFullPath()); } else { cmSystemTools::Error("Attempt to add a custom rule to a target " - "that does not exist yet for target ", - target.c_str()); + "that does not exist yet for target " + + target); return; } } @@ -1179,8 +1189,7 @@ cmTarget* cmMakefile::AddUtilityCommand( if (sf) { sf->SetProperty("SYMBOLIC", "1"); } else { - cmSystemTools::Error("Could not get source file entry for ", - force.c_str()); + cmSystemTools::Error("Could not get source file entry for " + force); } // Always create the byproduct sources and mark them generated. @@ -1496,6 +1505,9 @@ public: void Quiet() { this->ReportError = false; } + BuildsystemFileScope(const BuildsystemFileScope&) = delete; + BuildsystemFileScope& operator=(const BuildsystemFileScope&) = delete; + private: cmMakefile* Makefile; cmGlobalGenerator* GG; @@ -1848,10 +1860,8 @@ void cmMakefile::CheckForUnusedVariables() const if (!this->WarnUnused) { return; } - const std::vector<std::string>& unused = this->StateSnapshot.UnusedKeys(); - std::vector<std::string>::const_iterator it = unused.begin(); - for (; it != unused.end(); ++it) { - this->LogUnused("out of scope", *it); + for (const std::string& key : this->StateSnapshot.UnusedKeys()) { + this->LogUnused("out of scope", key); } } @@ -2195,7 +2205,7 @@ cmSourceGroup* cmMakefile::FindSourceGroup( } // Shouldn't get here, but just in case, return the default group. - return &groups.front(); + return groups.data(); } #endif @@ -2427,16 +2437,19 @@ bool cmMakefile::CanIWriteThisFile(std::string const& fileName) const cmSystemTools::SameFile(fileName, this->GetHomeOutputDirectory()); } -std::string cmMakefile::GetRequiredDefinition(const std::string& name) const +const std::string& cmMakefile::GetRequiredDefinition( + const std::string& name) const { - const char* ret = this->GetDefinition(name); - if (!ret) { + static std::string const empty; + const std::string* def = GetDef(name); + if (!def) { cmSystemTools::Error("Error required internal CMake variable not " - "set, cmake may not be built correctly.\n", - "Missing variable is:\n", name.c_str()); - return std::string(); + "set, cmake may not be built correctly.\n" + "Missing variable is:\n" + + name); + return empty; } - return std::string(ret); + return *def; } bool cmMakefile::IsDefinitionSet(const std::string& name) const @@ -3057,10 +3070,8 @@ bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff, // loop over all function blockers to see if any block this command // evaluate in reverse, this is critical for balanced IF statements etc - std::vector<cmFunctionBlocker*>::reverse_iterator pos; - for (pos = this->FunctionBlockers.rbegin(); - pos != this->FunctionBlockers.rend(); ++pos) { - if ((*pos)->IsFunctionBlocked(lff, *this, status)) { + for (cmFunctionBlocker* pos : cmReverseRange(this->FunctionBlockers)) { + if (pos->IsFunctionBlocked(lff, *this, status)) { return true; } } @@ -3548,7 +3559,7 @@ cmState* cmMakefile::GetState() const return this->GetCMakeInstance()->GetState(); } -void cmMakefile::DisplayStatus(const char* message, float s) const +void cmMakefile::DisplayStatus(const std::string& message, float s) const { cmake* cm = this->GetCMakeInstance(); if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) { @@ -3718,22 +3729,23 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output, lineNumber, true, true); } -int cmMakefile::ConfigureFile(const char* infile, const char* outfile, - bool copyonly, bool atOnly, bool escapeQuotes, +int cmMakefile::ConfigureFile(const std::string& infile, + const std::string& outfile, bool copyonly, + bool atOnly, bool escapeQuotes, cmNewLineStyle newLine) { int res = 1; if (!this->CanIWriteThisFile(outfile)) { - cmSystemTools::Error("Attempt to write file: ", outfile, + cmSystemTools::Error("Attempt to write file: " + outfile + " into a source directory."); return 0; } if (!cmSystemTools::FileExists(infile)) { - cmSystemTools::Error("File ", infile, " does not exist."); + cmSystemTools::Error("File " + infile + " does not exist."); return 0; } std::string soutfile = outfile; - std::string sinfile = infile; + const std::string& sinfile = infile; this->AddCMakeDependFile(sinfile); cmSystemTools::ConvertToUnixSlashes(soutfile); @@ -3767,15 +3779,15 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, tempOutputFile += ".tmp"; cmsys::ofstream fout(tempOutputFile.c_str(), omode); if (!fout) { - cmSystemTools::Error("Could not open file for write in copy operation ", - tempOutputFile.c_str()); + cmSystemTools::Error("Could not open file for write in copy operation " + + tempOutputFile); cmSystemTools::ReportLastSystemError(""); return 0; } cmsys::ifstream fin(sinfile.c_str()); if (!fin) { - cmSystemTools::Error("Could not open file for read in copy operation ", - sinfile.c_str()); + cmSystemTools::Error("Could not open file for read in copy operation " + + sinfile); return 0; } @@ -4275,7 +4287,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, // Deprecate old policies, especially those that require a lot // of code to maintain the old behavior. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0065 && + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0066 && !(this->GetCMakeInstance()->GetIsInTryCompile() && ( // Policies set by cmCoreTryCompile::TryCompileCode. @@ -4713,6 +4725,13 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, needCxx17, needCxx20); const char* existingCxxStandard = target->GetProperty("CXX_STANDARD"); + if (existingCxxStandard == nullptr) { + const char* defaultCxxStandard = + this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT"); + if (defaultCxxStandard && *defaultCxxStandard) { + existingCxxStandard = defaultCxxStandard; + } + } const char* const* existingCxxLevel = nullptr; if (existingCxxStandard) { existingCxxLevel = @@ -4815,6 +4834,13 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, this->CheckNeededCLanguage(feature, needC90, needC99, needC11); const char* existingCStandard = target->GetProperty("C_STANDARD"); + if (existingCStandard == nullptr) { + const char* defaultCStandard = + this->GetDefinition("CMAKE_C_STANDARD_DEFAULT"); + if (defaultCStandard && *defaultCStandard) { + existingCStandard = defaultCStandard; + } + } if (existingCStandard) { if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), cmStrCmp(existingCStandard)) == cm::cend(C_STANDARDS)) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 70a5689..88b4c2f 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -313,6 +313,9 @@ public: PolicyPushPop(cmMakefile* m); ~PolicyPushPop(); + PolicyPushPop(const PolicyPushPop&) = delete; + PolicyPushPop& operator=(const PolicyPushPop&) = delete; + private: cmMakefile* Makefile; }; @@ -436,7 +439,7 @@ public: const char* GetDefinition(const std::string&) const; const std::string* GetDef(const std::string&) const; const std::string& GetSafeDefinition(const std::string&) const; - std::string GetRequiredDefinition(const std::string& name) const; + const std::string& GetRequiredDefinition(const std::string& name) const; bool IsDefinitionSet(const std::string&) const; /** * Get the list of all variables in the current space. If argument @@ -607,8 +610,8 @@ public: /** * Copy file but change lines according to ConfigureString */ - int ConfigureFile(const char* infile, const char* outfile, bool copyonly, - bool atOnly, bool escapeQuotes, + int ConfigureFile(const std::string& infile, const std::string& outfile, + bool copyonly, bool atOnly, bool escapeQuotes, cmNewLineStyle = cmNewLineStyle()); /** @@ -639,7 +642,7 @@ public: #endif ///! Display progress or status message. - void DisplayStatus(const char*, float) const; + void DisplayStatus(const std::string&, float) const; /** * Expand the given list file arguments into the full set after @@ -743,6 +746,9 @@ public: cmPolicies::PolicyMap const& pm); ~FunctionPushPop(); + FunctionPushPop(const FunctionPushPop&) = delete; + FunctionPushPop& operator=(const FunctionPushPop&) = delete; + void Quiet() { this->ReportError = false; } private: @@ -757,6 +763,9 @@ public: cmPolicies::PolicyMap const& pm); ~MacroPushPop(); + MacroPushPop(const MacroPushPop&) = delete; + MacroPushPop& operator=(const MacroPushPop&) = delete; + void Quiet() { this->ReportError = false; } private: diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index e8ae5ae..984cd85 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -31,9 +31,8 @@ cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator( : cmMakefileTargetGenerator(target) { this->CustomCommandDriver = OnDepends; - this->GeneratorTarget->GetExecutableNames( - this->TargetNameOut, this->TargetNameReal, this->TargetNameImport, - this->TargetNamePDB, this->ConfigName); + this->TargetNames = + this->GeneratorTarget->GetExecutableNames(this->ConfigName); this->OSXBundleGenerator = new cmOSXBundleGenerator(target, this->ConfigName); @@ -305,18 +304,13 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) std::vector<std::string> commands; // Get the name of the executable to generate. - std::string targetName; - std::string targetNameReal; - std::string targetNameImport; - std::string targetNamePDB; - this->GeneratorTarget->GetExecutableNames(targetName, targetNameReal, - targetNameImport, targetNamePDB, - this->ConfigName); + cmGeneratorTarget::Names targetNames = + this->GeneratorTarget->GetExecutableNames(this->ConfigName); // Construct the full path version of the names. std::string outpath = this->GeneratorTarget->GetDirectory(this->ConfigName); if (this->GeneratorTarget->IsAppBundleOnApple()) { - this->OSXBundleGenerator->CreateAppBundle(targetName, outpath); + this->OSXBundleGenerator->CreateAppBundle(targetNames.Output, outpath); } outpath += "/"; std::string outpathImp; @@ -326,12 +320,12 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) outpath += "/CMakeRelink.dir"; cmSystemTools::MakeDirectory(outpath); outpath += "/"; - if (!targetNameImport.empty()) { + if (!targetNames.ImportLibrary.empty()) { outpathImp = outpath; } } else { cmSystemTools::MakeDirectory(outpath); - if (!targetNameImport.empty()) { + if (!targetNames.ImportLibrary.empty()) { outpathImp = this->GeneratorTarget->GetDirectory( this->ConfigName, cmStateEnums::ImportLibraryArtifact); cmSystemTools::MakeDirectory(outpathImp); @@ -348,10 +342,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) cmSystemTools::MakeDirectory(pdbOutputPath); pdbOutputPath += "/"; - std::string targetFullPath = outpath + targetName; - std::string targetFullPathReal = outpath + targetNameReal; - std::string targetFullPathPDB = pdbOutputPath + targetNamePDB; - std::string targetFullPathImport = outpathImp + targetNameImport; + std::string targetFullPath = outpath + targetNames.Output; + std::string targetFullPathReal = outpath + targetNames.Real; + std::string targetFullPathPDB = pdbOutputPath + targetNames.PDB; + std::string targetFullPathImport = outpathImp + targetNames.ImportLibrary; std::string targetOutPathPDB = this->LocalGenerator->ConvertToOutputFormat( targetFullPathPDB, cmOutputConverter::SHELL); // Convert to the output path to use in constructing commands. @@ -376,8 +370,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // Make sure we have a link language. if (linkLanguage.empty()) { - cmSystemTools::Error("Cannot determine link language for target \"", - this->GeneratorTarget->GetName().c_str(), "\"."); + cmSystemTools::Error("Cannot determine link language for target \"" + + this->GeneratorTarget->GetName() + "\"."); return; } @@ -468,11 +462,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath + ".manifest")); #endif - if (targetNameReal != targetName) { + if (this->TargetNames.Real != this->TargetNames.Output) { exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal)); } - if (!targetNameImport.empty()) { + if (!this->TargetNames.ImportLibrary.empty()) { exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathImport)); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 5a1ef4e..44e6547 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -32,9 +32,8 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator( { this->CustomCommandDriver = OnDepends; if (this->GeneratorTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) { - this->GeneratorTarget->GetLibraryNames( - this->TargetNameOut, this->TargetNameSO, this->TargetNameReal, - this->TargetNameImport, this->TargetNamePDB, this->ConfigName); + this->TargetNames = + this->GeneratorTarget->GetLibraryNames(this->ConfigName); } this->OSXBundleGenerator = @@ -463,8 +462,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // Make sure we have a link language. if (linkLanguage.empty()) { - cmSystemTools::Error("Cannot determine link language for target \"", - this->GeneratorTarget->GetName().c_str(), "\"."); + cmSystemTools::Error("Cannot determine link language for target \"" + + this->GeneratorTarget->GetName() + "\"."); return; } @@ -489,25 +488,20 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } // Construct the name of the library. - std::string targetName; - std::string targetNameSO; - std::string targetNameReal; - std::string targetNameImport; - std::string targetNamePDB; - this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO, - targetNameReal, targetNameImport, - targetNamePDB, this->ConfigName); + this->GeneratorTarget->GetLibraryNames(this->ConfigName); // Construct the full path version of the names. std::string outpath; std::string outpathImp; if (this->GeneratorTarget->IsFrameworkOnApple()) { outpath = this->GeneratorTarget->GetDirectory(this->ConfigName); - this->OSXBundleGenerator->CreateFramework(targetName, outpath); + this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output, + outpath); outpath += "/"; } else if (this->GeneratorTarget->IsCFBundleOnApple()) { outpath = this->GeneratorTarget->GetDirectory(this->ConfigName); - this->OSXBundleGenerator->CreateCFBundle(targetName, outpath); + this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output, + outpath); outpath += "/"; } else if (relink) { outpath = this->Makefile->GetCurrentBinaryDirectory(); @@ -515,14 +509,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( outpath += "/CMakeRelink.dir"; cmSystemTools::MakeDirectory(outpath); outpath += "/"; - if (!targetNameImport.empty()) { + if (!this->TargetNames.ImportLibrary.empty()) { outpathImp = outpath; } } else { outpath = this->GeneratorTarget->GetDirectory(this->ConfigName); cmSystemTools::MakeDirectory(outpath); outpath += "/"; - if (!targetNameImport.empty()) { + if (!this->TargetNames.ImportLibrary.empty()) { outpathImp = this->GeneratorTarget->GetDirectory( this->ConfigName, cmStateEnums::ImportLibraryArtifact); cmSystemTools::MakeDirectory(outpathImp); @@ -539,11 +533,12 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( cmSystemTools::MakeDirectory(pdbOutputPath); pdbOutputPath += "/"; - std::string targetFullPath = outpath + targetName; - std::string targetFullPathPDB = pdbOutputPath + targetNamePDB; - std::string targetFullPathSO = outpath + targetNameSO; - std::string targetFullPathReal = outpath + targetNameReal; - std::string targetFullPathImport = outpathImp + targetNameImport; + std::string targetFullPath = outpath + this->TargetNames.Output; + std::string targetFullPathPDB = pdbOutputPath + this->TargetNames.PDB; + std::string targetFullPathSO = outpath + this->TargetNames.SharedObject; + std::string targetFullPathReal = outpath + this->TargetNames.Real; + std::string targetFullPathImport = + outpathImp + this->TargetNames.ImportLibrary; // Construct the output path version of the names for use in command // arguments. @@ -616,15 +611,16 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( commands1.clear(); } - if (targetName != targetNameReal) { + if (this->TargetNames.Output != this->TargetNames.Real) { libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath)); } - if (targetNameSO != targetNameReal && targetNameSO != targetName) { + if (this->TargetNames.SharedObject != this->TargetNames.Real && + this->TargetNames.SharedObject != this->TargetNames.Output) { libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathSO)); } - if (!targetNameImport.empty()) { + if (!this->TargetNames.ImportLibrary.empty()) { libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathImport)); @@ -820,7 +816,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( vars.ObjectsQuoted = buildObjs.c_str(); if (this->GeneratorTarget->HasSOName(this->ConfigName)) { vars.SONameFlag = this->Makefile->GetSONameFlag(linkLanguage); - vars.TargetSOName = targetNameSO.c_str(); + vars.TargetSOName = this->TargetNames.SharedObject.c_str(); } vars.LinkFlags = linkFlags.c_str(); @@ -981,10 +977,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // Compute the list of outputs. std::vector<std::string> outputs(1, targetFullPathReal); - if (targetNameSO != targetNameReal) { + if (this->TargetNames.SharedObject != this->TargetNames.Real) { outputs.push_back(targetFullPathSO); } - if (targetName != targetNameSO && targetName != targetNameReal) { + if (this->TargetNames.Output != this->TargetNames.SharedObject && + this->TargetNames.Output != this->TargetNames.Real) { outputs.push_back(targetFullPath); } diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index af34169..340e405 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -21,6 +21,7 @@ #include "cmMakefileLibraryTargetGenerator.h" #include "cmMakefileUtilityTargetGenerator.h" #include "cmOutputConverter.h" +#include "cmRange.h" #include "cmRulePlaceholderExpander.h" #include "cmSourceFile.h" #include "cmState.h" @@ -654,19 +655,20 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( std::string cmdVar; if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_SEPARABLE_COMPILATION")) { - cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"; } else if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_PTX_COMPILATION")) { - cmdVar = std::string("CMAKE_CUDA_COMPILE_PTX_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION"; } else { - cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"; } - std::string compileRule = this->Makefile->GetRequiredDefinition(cmdVar); + const std::string& compileRule = + this->Makefile->GetRequiredDefinition(cmdVar); cmSystemTools::ExpandListArgument(compileRule, compileCommands); } else { - const std::string cmdVar = - std::string("CMAKE_") + lang + "_COMPILE_OBJECT"; - std::string compileRule = this->Makefile->GetRequiredDefinition(cmdVar); + const std::string cmdVar = "CMAKE_" + lang + "_COMPILE_OBJECT"; + const std::string& compileRule = + this->Makefile->GetRequiredDefinition(cmdVar); cmSystemTools::ExpandListArgument(compileRule, compileCommands); } @@ -974,18 +976,17 @@ bool cmMakefileTargetGenerator::WriteMakeRule( // For multiple outputs, make the extra ones depend on the first one. std::vector<std::string> const output_depends(1, outputs[0]); std::string binDir = this->LocalGenerator->GetBinaryDirectory(); - for (std::vector<std::string>::const_iterator o = outputs.begin() + 1; - o != outputs.end(); ++o) { + for (std::string const& output : cmMakeRange(outputs).advance(1)) { // Touch the extra output so "make" knows that it was updated, // but only if the output was actually created. std::string const out = this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->MaybeConvertToRelativePath(binDir, *o), + this->LocalGenerator->MaybeConvertToRelativePath(binDir, output), cmOutputConverter::SHELL); std::vector<std::string> output_commands; bool o_symbolic = false; if (need_symbolic) { - if (cmSourceFile* sf = this->Makefile->GetSource(*o)) { + if (cmSourceFile* sf = this->Makefile->GetSource(output)) { o_symbolic = sf->GetPropertyAsBool("SYMBOLIC"); } } @@ -994,13 +995,13 @@ bool cmMakefileTargetGenerator::WriteMakeRule( if (!o_symbolic) { output_commands.push_back("@$(CMAKE_COMMAND) -E touch_nocreate " + out); } - this->LocalGenerator->WriteMakeRule(os, nullptr, *o, output_depends, + this->LocalGenerator->WriteMakeRule(os, nullptr, output, output_depends, output_commands, o_symbolic, in_help); if (!o_symbolic) { // At build time, remove the first output if this one does not exist // so that "make" will rerun the real commands that create this one. - MultipleOutputPairsType::value_type p(*o, outputs[0]); + MultipleOutputPairsType::value_type p(output, outputs[0]); this->MultipleOutputPairs.insert(p); } } diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 529b4db..c053d5b 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -12,12 +12,12 @@ #include <vector> #include "cmCommonTargetGenerator.h" +#include "cmGeneratorTarget.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmOSXBundleGenerator.h" class cmCustomCommandGenerator; class cmGeneratedFileStream; -class cmGeneratorTarget; class cmGlobalUnixMakefileGenerator3; class cmLinkLineComputer; class cmOutputConverter; @@ -231,11 +231,7 @@ protected: bool in_help = false); // Target name info. - std::string TargetNameOut; - std::string TargetNameSO; - std::string TargetNameReal; - std::string TargetNameImport; - std::string TargetNamePDB; + cmGeneratorTarget::Names TargetNames; // macOS content info. std::set<std::string> MacContentFolders; diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 95f5fcb..2724030 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -6,6 +6,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmMessenger.h" +#include "cmRange.h" #include "cmSystemTools.h" class cmExecutionStatus; @@ -68,7 +69,7 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, m->DisplayMessage(type, message, this->Makefile->GetBacktrace()); } else { if (status) { - this->Makefile->DisplayStatus(message.c_str(), -1); + this->Makefile->DisplayStatus(message, -1); } else { cmSystemTools::Message(message); } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index cbc0103..b38d410 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -41,13 +41,10 @@ cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( { this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName()); if (target->GetType() == cmStateEnums::EXECUTABLE) { - this->GetGeneratorTarget()->GetExecutableNames( - this->TargetNameOut, this->TargetNameReal, this->TargetNameImport, - this->TargetNamePDB, GetLocalGenerator()->GetConfigName()); + this->TargetNames = this->GetGeneratorTarget()->GetExecutableNames( + GetLocalGenerator()->GetConfigName()); } else { - this->GetGeneratorTarget()->GetLibraryNames( - this->TargetNameOut, this->TargetNameSO, this->TargetNameReal, - this->TargetNameImport, this->TargetNamePDB, + this->TargetNames = this->GetGeneratorTarget()->GetLibraryNames( GetLocalGenerator()->GetConfigName()); } @@ -71,8 +68,8 @@ void cmNinjaNormalTargetGenerator::Generate() { if (this->TargetLinkLanguage.empty()) { cmSystemTools::Error("CMake can not determine linker language for " - "target: ", - this->GetGeneratorTarget()->GetName().c_str()); + "target: " + + this->GetGeneratorTarget()->GetName()); return; } @@ -286,6 +283,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()); vars.Language = this->TargetLinkLanguage.c_str(); + if (this->TargetLinkLanguage == "Swift") { + vars.SwiftPartialModules = "$SWIFT_PARTIAL_MODULES"; + vars.TargetSwiftModule = "$TARGET_SWIFT_MODULE"; + vars.TargetSwiftDoc = "$TARGET_SWIFT_DOC"; + } std::string responseFlag; if (!useResponseFile) { @@ -395,7 +397,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) /*generator*/ false); } - if (this->TargetNameOut != this->TargetNameReal && + if (this->TargetNames.Output != this->TargetNames.Real && !this->GetGeneratorTarget()->IsFrameworkOnApple()) { std::string cmakeCommand = this->GetLocalGenerator()->ConvertToOutputFormat( @@ -676,7 +678,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() if (this->GetGeneratorTarget()->HasSOName(cfgName)) { vars["SONAME_FLAG"] = this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage); - vars["SONAME"] = this->TargetNameSO; + vars["SONAME"] = this->TargetNames.SharedObject; if (targetType == cmStateEnums::SHARED_LIBRARY) { std::string install_dir = this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName); @@ -687,7 +689,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() } } - if (!this->TargetNameImport.empty()) { + if (!this->TargetNames.ImportLibrary.empty()) { const std::string impLibPath = localGen.ConvertToOutputFormat( targetOutputImplib, cmOutputConverter::SHELL); vars["TARGET_IMPLIB"] = impLibPath; @@ -749,24 +751,25 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() if (gt.IsAppBundleOnApple()) { // Create the app bundle std::string outpath = gt.GetDirectory(cfgName); - this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath); + this->OSXBundleGenerator->CreateAppBundle(this->TargetNames.Output, + outpath); // Calculate the output path targetOutput = outpath; targetOutput += "/"; - targetOutput += this->TargetNameOut; + targetOutput += this->TargetNames.Output; targetOutput = this->ConvertToNinjaPath(targetOutput); targetOutputReal = outpath; targetOutputReal += "/"; - targetOutputReal += this->TargetNameReal; + targetOutputReal += this->TargetNames.Real; targetOutputReal = this->ConvertToNinjaPath(targetOutputReal); } else if (gt.IsFrameworkOnApple()) { // Create the library framework. - this->OSXBundleGenerator->CreateFramework(this->TargetNameOut, + this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output, gt.GetDirectory(cfgName)); } else if (gt.IsCFBundleOnApple()) { // Create the core foundation bundle. - this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut, + this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output, gt.GetDirectory(cfgName)); } @@ -789,6 +792,34 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmNinjaDeps outputs; outputs.push_back(targetOutputReal); + if (this->TargetLinkLanguage == "Swift") { + if (const char* name = gt.GetProperty("SWIFT_MODULE_NAME")) { + vars["TARGET_SWIFT_DOC"] = std::string(name) + ".swiftdoc"; + vars["TARGET_SWIFT_MODULE"] = std::string(name) + ".swiftmodule"; + } else { + vars["TARGET_SWIFT_DOC"] = gt.GetName() + ".swiftdoc"; + vars["TARGET_SWIFT_MODULE"] = gt.GetName() + ".swiftmodule"; + } + outputs.push_back(vars["TARGET_SWIFT_DOC"]); + outputs.push_back(vars["TARGET_SWIFT_MODULE"]); + + cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator(); + + std::string partials; + std::vector<cmSourceFile const*> sources; + gt.GetObjectSources(sources, this->GetConfigName()); + for (cmSourceFile const* source : sources) { + partials += " "; + if (const char* partial = source->GetProperty("SWIFT_PARTIAL_MODULE")) { + partials += partial; + } else { + partials += localGen.GetTargetDirectory(>) + "/" + + gt.GetObjectName(source) + ".swiftmodule"; + } + } + vars["SWIFT_PARTIAL_MODULES"] = partials; + } + // Compute specific libraries to link with. cmNinjaDeps explicitDeps = this->GetObjects(); cmNinjaDeps implicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage); @@ -801,10 +832,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() std::string frameworkPath; std::string linkPath; - cmGeneratorTarget& genTarget = *this->GetGeneratorTarget(); - std::string createRule = genTarget.GetCreateRuleVariable( - this->TargetLinkLanguage, this->GetConfigName()); + std::string createRule = + gt.GetCreateRuleVariable(this->TargetLinkLanguage, this->GetConfigName()); bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE"); cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator(); @@ -817,9 +847,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() this->GetLocalGenerator()->GetStateSnapshot().GetDirectory())); linkLineComputer->SetUseWatcomQuote(useWatcomQuote); - localGen.GetTargetFlags( - linkLineComputer.get(), this->GetConfigName(), vars["LINK_LIBRARIES"], - vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, &genTarget); + localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(), + vars["LINK_LIBRARIES"], vars["FLAGS"], + vars["LINK_FLAGS"], frameworkPath, linkPath, >); // Add OS X version flags, if any. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || @@ -840,7 +870,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() vars["LINK_PATH"] = frameworkPath + linkPath; std::string lwyuFlags; - if (genTarget.GetPropertyAsBool("LINK_WHAT_YOU_USE")) { + if (gt.GetPropertyAsBool("LINK_WHAT_YOU_USE")) { lwyuFlags = " -Wl,--no-as-needed"; } @@ -849,22 +879,21 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // code between the Makefile executable and library generators. if (targetType == cmStateEnums::EXECUTABLE) { std::string t = vars["FLAGS"]; - localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName); + localGen.AddArchitectureFlags(t, >, TargetLinkLanguage, cfgName); t += lwyuFlags; vars["FLAGS"] = t; } else { std::string t = vars["ARCH_FLAGS"]; - localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName); + localGen.AddArchitectureFlags(t, >, TargetLinkLanguage, cfgName); vars["ARCH_FLAGS"] = t; t.clear(); t += lwyuFlags; - localGen.AddLanguageFlagsForLinking(t, &genTarget, TargetLinkLanguage, - cfgName); + localGen.AddLanguageFlagsForLinking(t, >, TargetLinkLanguage, cfgName); vars["LANGUAGE_COMPILE_FLAGS"] = t; } if (this->GetGeneratorTarget()->HasSOName(cfgName)) { vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage); - vars["SONAME"] = this->TargetNameSO; + vars["SONAME"] = this->TargetNames.SharedObject; if (targetType == cmStateEnums::SHARED_LIBRARY) { std::string install_dir = this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName); @@ -877,12 +906,12 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmNinjaDeps byproducts; - if (!this->TargetNameImport.empty()) { + if (!this->TargetNames.ImportLibrary.empty()) { const std::string impLibPath = localGen.ConvertToOutputFormat( targetOutputImplib, cmOutputConverter::SHELL); vars["TARGET_IMPLIB"] = impLibPath; EnsureParentDirectoryExists(impLibPath); - if (genTarget.HasImportLibrary(cfgName)) { + if (gt.HasImportLibrary(cfgName)) { byproducts.push_back(targetOutputImplib); } } @@ -1037,8 +1066,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() emptyDeps, emptyDeps, symlinkVars); } else { cmNinjaDeps symlinks; - std::string const soName = - this->ConvertToNinjaPath(this->GetTargetFilePath(this->TargetNameSO)); + std::string const soName = this->ConvertToNinjaPath( + this->GetTargetFilePath(this->TargetNames.SharedObject)); // If one link has to be created. if (targetOutputReal == soName || targetOutput == soName) { symlinkVars["SONAME"] = soName; @@ -1056,7 +1085,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } // Add aliases for the file name and the target name. - globalGen.AddTargetAlias(this->TargetNameOut, >); + globalGen.AddTargetAlias(this->TargetNames.Output, >); globalGen.AddTargetAlias(this->GetTargetName(), >); } diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h index 01cc881..14991a2 100644 --- a/Source/cmNinjaNormalTargetGenerator.h +++ b/Source/cmNinjaNormalTargetGenerator.h @@ -5,13 +5,12 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include "cmGeneratorTarget.h" #include "cmNinjaTargetGenerator.h" #include <string> #include <vector> -class cmGeneratorTarget; - class cmNinjaNormalTargetGenerator : public cmNinjaTargetGenerator { public: @@ -40,11 +39,7 @@ private: private: // Target name info. - std::string TargetNameOut; - std::string TargetNameSO; - std::string TargetNameReal; - std::string TargetNameImport; - std::string TargetNamePDB; + cmGeneratorTarget::Names TargetNames; std::string TargetLinkLanguage; std::string DeviceLinkObject; }; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 82bc5f2..8d11408 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -102,6 +102,12 @@ bool cmNinjaTargetGenerator::NeedExplicitPreprocessing( return lang == "Fortran"; } +bool cmNinjaTargetGenerator::UsePreprocessedSource( + std::string const& lang) const +{ + return lang == "Fortran"; +} + std::string cmNinjaTargetGenerator::LanguageDyndepRule( const std::string& lang) const { @@ -454,6 +460,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) if (lang == "Swift") { vars.SwiftAuxiliarySources = "$SWIFT_AUXILIARY_SOURCES"; vars.SwiftModuleName = "$SWIFT_MODULE_NAME"; + vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME"; + vars.SwiftPartialModule = "$SWIFT_PARTIAL_MODULE"; + vars.SwiftPartialDoc = "$SWIFT_PARTIAL_DOC"; } // For some cases we do an explicit preprocessor invocation. @@ -493,7 +502,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) if (explicitPP) { // Lookup the explicit preprocessing rule. std::string const ppVar = "CMAKE_" + lang + "_PREPROCESS_SOURCE"; - std::string const ppCmd = + std::string const& ppCmd = this->GetMakefile()->GetRequiredDefinition(ppVar); // Explicit preprocessing always uses a depfile. @@ -555,7 +564,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) cmake + " -E cmake_ninja_depends" " --tdi=" + - tdi + + tdi + " --lang=" + lang + " --pp=$out" " --dep=$DEP_FILE" + (needDyndep ? " --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE" : "")); @@ -585,13 +594,14 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) std::string ddRspContent = "$in"; std::string ddInput = "@" + ddRspFile; - // Run CMake dependency scanner on preprocessed output. + // Run CMake dependency scanner on the source file (using the preprocessed + // source if that was performed). std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); ddCmds.push_back(cmake + " -E cmake_ninja_dyndep" " --tdi=" + - tdi + + tdi + " --lang=" + lang + " --dd=$out" " " + ddInput); @@ -671,19 +681,18 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) std::string cmdVar; if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_SEPARABLE_COMPILATION")) { - cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"; } else if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_PTX_COMPILATION")) { - cmdVar = std::string("CMAKE_CUDA_COMPILE_PTX_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION"; } else { - cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"; } - std::string compileCmd = mf->GetRequiredDefinition(cmdVar); + const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar); cmSystemTools::ExpandListArgument(compileCmd, compileCmds); } else { - const std::string cmdVar = - std::string("CMAKE_") + lang + "_COMPILE_OBJECT"; - std::string compileCmd = mf->GetRequiredDefinition(cmdVar); + const std::string cmdVar = "CMAKE_" + lang + "_COMPILE_OBJECT"; + const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar); cmSystemTools::ExpandListArgument(compileCmd, compileCmds); } @@ -866,24 +875,27 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() this->WriteObjectBuildStatement(sf); } - if (!this->DDIFiles.empty()) { + for (auto const& langDDIFiles : this->DDIFiles) { + std::string const& language = langDDIFiles.first; + cmNinjaDeps const& ddiFiles = langDDIFiles.second; + std::string const ddComment; - std::string const ddRule = this->LanguageDyndepRule("Fortran"); + std::string const ddRule = this->LanguageDyndepRule(language); cmNinjaDeps ddOutputs; cmNinjaDeps ddImplicitOuts; - cmNinjaDeps const& ddExplicitDeps = this->DDIFiles; + cmNinjaDeps const& ddExplicitDeps = ddiFiles; cmNinjaDeps ddImplicitDeps; cmNinjaDeps ddOrderOnlyDeps; cmNinjaVars ddVars; - this->WriteTargetDependInfo("Fortran"); + this->WriteTargetDependInfo(language); - ddOutputs.push_back(this->GetDyndepFilePath("Fortran")); + ddOutputs.push_back(this->GetDyndepFilePath(language)); // Make sure dyndep files for all our dependencies have already - // been generated so that the 'FortranModules.json' files they + // been generated so that the '<LANG>Modules.json' files they // produced as side-effects are available for us to read. - // Ideally we should depend on the 'FortranModules.json' files + // Ideally we should depend on the '<LANG>Modules.json' files // from our dependencies directly, but we don't know which of // our dependencies produces them. Fixing this will require // refactoring the Ninja generator to generate targets in @@ -941,6 +953,22 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( } else { vars["SWIFT_MODULE_NAME"] = this->GeneratorTarget->GetName(); } + + cmGeneratorTarget::Names targetNames = + this->GeneratorTarget->GetLibraryNames(this->GetConfigName()); + vars["SWIFT_LIBRARY_NAME"] = targetNames.Base; + + if (const char* partial = source->GetProperty("SWIFT_PARTIAL_MODULE")) { + vars["SWIFT_PARTIAL_MODULE"] = partial; + } else { + vars["SWIFT_PARTIAL_MODULE"] = objectFileName + ".swiftmodule"; + } + + if (const char* partial = source->GetProperty("SWIFT_PARTIAL_DOC")) { + vars["SWIFT_PARTIAL_DOC"] = partial; + } else { + vars["SWIFT_PARTIAL_DOC"] = objectFileName + ".swiftdoc"; + } } if (!this->NeedDepTypeMSVC(language)) { @@ -1014,6 +1042,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( // For some cases we do an explicit preprocessor invocation. bool const explicitPP = this->NeedExplicitPreprocessing(language); if (explicitPP) { + bool const compilePP = this->UsePreprocessedSource(language); std::string const ppComment; std::string const ppRule = this->LanguagePreprocessRule(language); cmNinjaDeps ppOutputs; @@ -1027,61 +1056,80 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source)); ppOutputs.push_back(ppFileName); - // Move compilation dependencies to the preprocessing build statement. - std::swap(ppExplicitDeps, explicitDeps); - std::swap(ppImplicitDeps, implicitDeps); - std::swap(ppOrderOnlyDeps, orderOnlyDeps); - std::swap(ppVars["IN_ABS"], vars["IN_ABS"]); + if (compilePP) { + // Move compilation dependencies to the preprocessing build statement. + std::swap(ppExplicitDeps, explicitDeps); + std::swap(ppImplicitDeps, implicitDeps); + std::swap(ppOrderOnlyDeps, orderOnlyDeps); + std::swap(ppVars["IN_ABS"], vars["IN_ABS"]); - // The actual compilation will now use the preprocessed source. - explicitDeps.push_back(ppFileName); + // The actual compilation will now use the preprocessed source. + explicitDeps.push_back(ppFileName); + } else { + // Copy compilation dependencies to the preprocessing build statement. + ppExplicitDeps = explicitDeps; + ppImplicitDeps = implicitDeps; + ppOrderOnlyDeps = orderOnlyDeps; + ppVars["IN_ABS"] = vars["IN_ABS"]; + } // Preprocessing and compilation generally use the same flags. ppVars["FLAGS"] = vars["FLAGS"]; - // In case compilation requires flags that are incompatible with - // preprocessing, include them here. - std::string const postFlag = - this->Makefile->GetSafeDefinition("CMAKE_Fortran_POSTPROCESS_FLAG"); - this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag); + if (compilePP) { + // In case compilation requires flags that are incompatible with + // preprocessing, include them here. + std::string const postFlag = this->Makefile->GetSafeDefinition( + "CMAKE_" + language + "_POSTPROCESS_FLAG"); + this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag); + } - // Move preprocessor definitions to the preprocessor build statement. - std::swap(ppVars["DEFINES"], vars["DEFINES"]); + if (compilePP) { + // Move preprocessor definitions to the preprocessor build statement. + std::swap(ppVars["DEFINES"], vars["DEFINES"]); + } else { + // Copy preprocessor definitions to the preprocessor build statement. + ppVars["DEFINES"] = vars["DEFINES"]; + } // Copy include directories to the preprocessor build statement. The // Fortran compilation build statement still needs them for the INCLUDE // directive. ppVars["INCLUDES"] = vars["INCLUDES"]; - // Prepend source file's original directory as an include directory - // so e.g. Fortran INCLUDE statements can look for files in it. - std::vector<std::string> sourceDirectory; - sourceDirectory.push_back( - cmSystemTools::GetParentDirectory(source->GetFullPath())); + if (compilePP) { + // Prepend source file's original directory as an include directory + // so e.g. Fortran INCLUDE statements can look for files in it. + std::vector<std::string> sourceDirectory; + sourceDirectory.push_back( + cmSystemTools::GetParentDirectory(source->GetFullPath())); - std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags( - sourceDirectory, this->GeneratorTarget, language, false, false, - this->GetConfigName()); + std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags( + sourceDirectory, this->GeneratorTarget, language, false, false, + this->GetConfigName()); - vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"]; + vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"]; + } // Explicit preprocessing always uses a depfile. ppVars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ppFileName + ".d", cmOutputConverter::SHELL); - // The actual compilation does not need a depfile because it - // depends on the already-preprocessed source. - vars.erase("DEP_FILE"); + objectFileName + ".d", cmOutputConverter::SHELL); + if (compilePP) { + // The actual compilation does not need a depfile because it + // depends on the already-preprocessed source. + vars.erase("DEP_FILE"); + } if (needDyndep) { // Tell dependency scanner the object file that will result from - // compiling the preprocessed source. + // compiling the source. ppVars["OBJ_FILE"] = objectFileName; // Tell dependency scanner where to store dyndep intermediate results. - std::string const ddiFile = ppFileName + ".ddi"; + std::string const ddiFile = objectFileName + ".ddi"; ppVars["DYNDEP_INTERMEDIATE_FILE"] = ddiFile; ppImplicitOuts.push_back(ddiFile); - this->DDIFiles.push_back(ddiFile); + this->DDIFiles[language].push_back(ddiFile); } this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), @@ -1217,20 +1265,19 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( std::string cmdVar; if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_SEPARABLE_COMPILATION")) { - cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"; } else if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_PTX_COMPILATION")) { - cmdVar = std::string("CMAKE_CUDA_COMPILE_PTX_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION"; } else { - cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"); + cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"; } - std::string compileCmd = + const std::string& compileCmd = this->GetMakefile()->GetRequiredDefinition(cmdVar); cmSystemTools::ExpandListArgument(compileCmd, compileCmds); } else { - const std::string cmdVar = - std::string("CMAKE_") + language + "_COMPILE_OBJECT"; - std::string compileCmd = + const std::string cmdVar = "CMAKE_" + language + "_COMPILE_OBJECT"; + const std::string& compileCmd = this->GetMakefile()->GetRequiredDefinition(cmdVar); cmSystemTools::ExpandListArgument(compileCmd, compileCmds); } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 373c693..6a42da0 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -10,6 +10,7 @@ #include "cmNinjaTypes.h" #include "cmOSXBundleGenerator.h" +#include <map> #include <set> #include <string> #include <vector> @@ -64,6 +65,7 @@ protected: bool NeedExplicitPreprocessing(std::string const& lang) const; std::string LanguageDyndepRule(std::string const& lang) const; bool NeedDyndep(std::string const& lang) const; + bool UsePreprocessedSource(std::string const& lang) const; std::string OrderDependsTargetForTarget(); @@ -165,7 +167,7 @@ private: cmLocalNinjaGenerator* LocalGenerator; /// List of object files for this target. cmNinjaDeps Objects; - cmNinjaDeps DDIFiles; // TODO: Make per-language. + std::map<std::string, cmNinjaDeps> DDIFiles; std::vector<cmCustomCommand const*> CustomCommands; cmNinjaDeps ExtraFiles; }; diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx index 6857d5a..47a8df4 100644 --- a/Source/cmOSXBundleGenerator.cxx +++ b/Source/cmOSXBundleGenerator.cxx @@ -54,8 +54,7 @@ void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName, plist += this->GT->GetAppBundleDirectory(this->ConfigName, cmGeneratorTarget::ContentLevel); plist += "/Info.plist"; - this->LocalGenerator->GenerateAppleInfoPList(this->GT, targetName, - plist.c_str()); + this->LocalGenerator->GenerateAppleInfoPList(this->GT, targetName, plist); this->Makefile->AddCMakeOutputFile(plist); outpath = out; } @@ -90,8 +89,7 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName, } plist += "/Info.plist"; std::string name = cmSystemTools::GetFilenameName(targetName); - this->LocalGenerator->GenerateFrameworkInfoPList(this->GT, name, - plist.c_str()); + this->LocalGenerator->GenerateFrameworkInfoPList(this->GT, name, plist); // Generate Versions directory only for MacOSX frameworks if (this->Makefile->PlatformIsAppleEmbedded()) { @@ -184,7 +182,7 @@ void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName, cmGeneratorTarget::ContentLevel); plist += "/Info.plist"; std::string name = cmSystemTools::GetFilenameName(targetName); - this->LocalGenerator->GenerateAppleInfoPList(this->GT, name, plist.c_str()); + this->LocalGenerator->GenerateAppleInfoPList(this->GT, name, plist); this->Makefile->AddCMakeOutputFile(plist); } diff --git a/Source/cmOrderDirectories.h b/Source/cmOrderDirectories.h index 5916f7a..23e61d6 100644 --- a/Source/cmOrderDirectories.h +++ b/Source/cmOrderDirectories.h @@ -25,6 +25,8 @@ public: cmOrderDirectories(cmGlobalGenerator* gg, cmGeneratorTarget const* target, const char* purpose); ~cmOrderDirectories(); + cmOrderDirectories(const cmOrderDirectories&) = delete; + cmOrderDirectories& operator=(const cmOrderDirectories&) = delete; void AddRuntimeLibrary(std::string const& fullPath, const char* soname = nullptr); void AddLinkLibrary(std::string const& fullPath); diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index 46d04a6..cb9433f 100644 --- a/Source/cmOutputRequiredFilesCommand.cxx +++ b/Source/cmOutputRequiredFilesCommand.cxx @@ -92,6 +92,9 @@ public: */ ~cmLBDepend() { cmDeleteAll(this->DependInformationMap); } + cmLBDepend(const cmLBDepend&) = delete; + cmLBDepend& operator=(const cmLBDepend&) = delete; + /** * Set the makefile that is used as a source of classes. */ @@ -163,7 +166,7 @@ protected: { cmsys::ifstream fin(info->FullPath.c_str()); if (!fin) { - cmSystemTools::Error("error can not open ", info->FullPath.c_str()); + cmSystemTools::Error("error can not open " + info->FullPath); return; } @@ -178,7 +181,7 @@ protected: qstart = line.find('<', 8); // if a < is not found then move on if (qstart == std::string::npos) { - cmSystemTools::Error("unknown include directive ", line.c_str()); + cmSystemTools::Error("unknown include directive " + line); continue; } qend = line.find('>', qstart + 1); diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index 796974c..ab8d103 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -10,11 +10,12 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmRange.h" #include "cmSystemTools.h" class cmExecutionStatus; -static std::string escape_arg(const std::string& arg) +static std::string EscapeArg(const std::string& arg) { // replace ";" with "\;" so output argument lists will split correctly std::string escapedArg; @@ -27,6 +28,81 @@ static std::string escape_arg(const std::string& arg) return escapedArg; } +namespace { +enum insideValues +{ + NONE, + SINGLE, + MULTI +}; + +typedef std::map<std::string, bool> options_map; +typedef std::map<std::string, std::string> single_map; +typedef std::map<std::string, std::vector<std::string>> multi_map; +typedef std::set<std::string> options_set; +} + +// function to be called every time, a new key word was parsed or all +// parameters where parsed. +static void DetectKeywordsMissingValues(insideValues currentState, + const std::string& currentArgName, + int& argumentsFound, + options_set& keywordsMissingValues) +{ + if (currentState == SINGLE || + (currentState == MULTI && argumentsFound == 0)) { + keywordsMissingValues.insert(currentArgName); + } + + argumentsFound = 0; +} + +static void PassParsedArguments(const std::string& prefix, + cmMakefile& makefile, + const options_map& options, + const single_map& singleValArgs, + const multi_map& multiValArgs, + const std::vector<std::string>& unparsed, + const options_set& keywordsMissingValues) +{ + for (auto const& iter : options) { + makefile.AddDefinition(prefix + iter.first, + iter.second ? "TRUE" : "FALSE"); + } + + for (auto const& iter : singleValArgs) { + if (!iter.second.empty()) { + makefile.AddDefinition(prefix + iter.first, iter.second.c_str()); + } else { + makefile.RemoveDefinition(prefix + iter.first); + } + } + + for (auto const& iter : multiValArgs) { + if (!iter.second.empty()) { + makefile.AddDefinition(prefix + iter.first, + cmJoin(cmMakeRange(iter.second), ";").c_str()); + } else { + makefile.RemoveDefinition(prefix + iter.first); + } + } + + if (!unparsed.empty()) { + makefile.AddDefinition(prefix + "UNPARSED_ARGUMENTS", + cmJoin(cmMakeRange(unparsed), ";").c_str()); + } else { + makefile.RemoveDefinition(prefix + "UNPARSED_ARGUMENTS"); + } + + if (!keywordsMissingValues.empty()) { + makefile.AddDefinition( + prefix + "KEYWORDS_MISSING_VALUES", + cmJoin(cmMakeRange(keywordsMissingValues), ";").c_str()); + } else { + makefile.RemoveDefinition(prefix + "KEYWORDS_MISSING_VALUES"); + } +} + bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { @@ -67,9 +143,6 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, // define the result maps holding key/value pairs for // options, single values and multi values - typedef std::map<std::string, bool> options_map; - typedef std::map<std::string, std::string> single_map; - typedef std::map<std::string, std::vector<std::string>> multi_map; options_map options; single_map singleValArgs; multi_map multiValArgs; @@ -114,12 +187,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, multiValArgs[iter]; // default initialize } - enum insideValues - { - NONE, - SINGLE, - MULTI - } insideValues = NONE; + insideValues insideValues = NONE; std::string currentArgName; list.clear(); @@ -155,10 +223,15 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, } } + options_set keywordsMissingValues; + int multiArgumentsFound = 0; + // iterate over the arguments list and fill in the values where applicable for (std::string const& arg : list) { const options_map::iterator optIter = options.find(arg); if (optIter != options.end()) { + DetectKeywordsMissingValues(insideValues, currentArgName, + multiArgumentsFound, keywordsMissingValues); insideValues = NONE; optIter->second = true; continue; @@ -166,6 +239,8 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, const single_map::iterator singleIter = singleValArgs.find(arg); if (singleIter != singleValArgs.end()) { + DetectKeywordsMissingValues(insideValues, currentArgName, + multiArgumentsFound, keywordsMissingValues); insideValues = SINGLE; currentArgName = arg; continue; @@ -173,6 +248,8 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, const multi_map::iterator multiIter = multiValArgs.find(arg); if (multiIter != multiValArgs.end()) { + DetectKeywordsMissingValues(insideValues, currentArgName, + multiArgumentsFound, keywordsMissingValues); insideValues = MULTI; currentArgName = arg; continue; @@ -184,15 +261,18 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, insideValues = NONE; break; case MULTI: + ++multiArgumentsFound; if (parseFromArgV) { - multiValArgs[currentArgName].push_back(escape_arg(arg)); + multiValArgs[currentArgName].push_back(EscapeArg(arg)); } else { multiValArgs[currentArgName].push_back(arg); } break; default: + multiArgumentsFound = 0; + if (parseFromArgV) { - unparsed.push_back(escape_arg(arg)); + unparsed.push_back(EscapeArg(arg)); } else { unparsed.push_back(arg); } @@ -200,36 +280,11 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, } } - // now iterate over the collected values and update their definition - // within the current scope. undefine if necessary. - - for (auto const& iter : options) { - this->Makefile->AddDefinition(prefix + iter.first, - iter.second ? "TRUE" : "FALSE"); - } - for (auto const& iter : singleValArgs) { - if (!iter.second.empty()) { - this->Makefile->AddDefinition(prefix + iter.first, iter.second.c_str()); - } else { - this->Makefile->RemoveDefinition(prefix + iter.first); - } - } - - for (auto const& iter : multiValArgs) { - if (!iter.second.empty()) { - this->Makefile->AddDefinition( - prefix + iter.first, cmJoin(cmMakeRange(iter.second), ";").c_str()); - } else { - this->Makefile->RemoveDefinition(prefix + iter.first); - } - } + DetectKeywordsMissingValues(insideValues, currentArgName, + multiArgumentsFound, keywordsMissingValues); - if (!unparsed.empty()) { - this->Makefile->AddDefinition(prefix + "UNPARSED_ARGUMENTS", - cmJoin(cmMakeRange(unparsed), ";").c_str()); - } else { - this->Makefile->RemoveDefinition(prefix + "UNPARSED_ARGUMENTS"); - } + PassParsedArguments(prefix, *this->Makefile, options, singleValArgs, + multiValArgs, unparsed, keywordsMissingValues); return true; } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 314f27d..8b21166 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -261,7 +261,10 @@ class cmMakefile; 3, 14, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0088, \ "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.", \ - 3, 14, 0, cmPolicies::WARN) + 3, 14, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0089, \ + "Compiler id for IBM Clang-based XL compilers is now XLClang.", 3, \ + 15, 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/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index 6acc7ef..9a764c6 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -4,6 +4,7 @@ #include "cmCustomCommandLines.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmSystemTools.h" @@ -29,13 +30,13 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList); // Create a rule for all sources listed. - for (std::vector<std::string>::const_iterator j = (args.begin() + 2); - j != args.end(); ++j) { - cmSourceFile* curr = this->Makefile->GetSource(*j); + for (std::string const& arg : cmMakeRange(args).advance(2)) { + cmSourceFile* curr = this->Makefile->GetSource(arg); // if we should wrap the class if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) { // Compute the name of the file to generate. - std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(*j); + std::string srcName = + cmSystemTools::GetFilenameWithoutLastExtension(arg); std::string newName = this->Makefile->GetCurrentBinaryDirectory(); newName += "/moc_"; newName += srcName; @@ -47,8 +48,8 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, // Compute the name of the header from which to generate the file. std::string hname; - if (cmSystemTools::FileIsFullPath(*j)) { - hname = *j; + if (cmSystemTools::FileIsFullPath(arg)) { + hname = arg; } else { if (curr && curr->GetIsGenerated()) { hname = this->Makefile->GetCurrentBinaryDirectory(); @@ -56,7 +57,7 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, hname = this->Makefile->GetCurrentSourceDirectory(); } hname += "/"; - hname += *j; + hname += arg; } // Append the generated source file to the list. diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index 43b1fb9..2223e2d 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -4,6 +4,7 @@ #include "cmCustomCommandLines.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmSystemTools.h" @@ -33,13 +34,13 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList); // Create rules for all sources listed. - for (std::vector<std::string>::const_iterator j = (args.begin() + 3); - j != args.end(); ++j) { - cmSourceFile* curr = this->Makefile->GetSource(*j); + for (std::string const& arg : cmMakeRange(args).advance(3)) { + cmSourceFile* curr = this->Makefile->GetSource(arg); // if we should wrap the class if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) { // Compute the name of the files to generate. - std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(*j); + std::string srcName = + cmSystemTools::GetFilenameWithoutLastExtension(arg); std::string hName = this->Makefile->GetCurrentBinaryDirectory(); hName += "/"; hName += srcName; @@ -55,8 +56,8 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, // Compute the name of the ui file from which to generate others. std::string uiName; - if (cmSystemTools::FileIsFullPath(*j)) { - uiName = *j; + if (cmSystemTools::FileIsFullPath(arg)) { + uiName = arg; } else { if (curr && curr->GetIsGenerated()) { uiName = this->Makefile->GetCurrentBinaryDirectory(); @@ -64,7 +65,7 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, uiName = this->Makefile->GetCurrentSourceDirectory(); } uiName += "/"; - uiName += *j; + uiName += arg; } // create the list of headers diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index 653caf7..022947f 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -7,17 +7,10 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> -#include <iterator> +#include <array> #include <sstream> #include <utility> -// - Static variables - -std::string const genNameGen = "AutoGen"; -std::string const genNameMoc = "AutoMoc"; -std::string const genNameUic = "AutoUic"; -std::string const genNameRcc = "AutoRcc"; - // - Static functions /// @brief Merges newOpts into baseOpts @@ -77,27 +70,47 @@ void MergeOptions(std::vector<std::string>& baseOpts, // - Class definitions -std::string const cmQtAutoGen::ListSep = "<<<S>>>"; unsigned int const cmQtAutoGen::ParallelMax = 64; +std::string const cmQtAutoGen::ListSep = "<<<S>>>"; -std::string const& cmQtAutoGen::GeneratorName(GeneratorT type) +std::string const cmQtAutoGen::GenAutoGen = "AutoGen"; +std::string const cmQtAutoGen::GenAutoMoc = "AutoMoc"; +std::string const cmQtAutoGen::GenAutoUic = "AutoUic"; +std::string const cmQtAutoGen::GenAutoRcc = "AutoRcc"; + +std::string const cmQtAutoGen::GenAUTOGEN = "AUTOGEN"; +std::string const cmQtAutoGen::GenAUTOMOC = "AUTOMOC"; +std::string const cmQtAutoGen::GenAUTOUIC = "AUTOUIC"; +std::string const cmQtAutoGen::GenAUTORCC = "AUTORCC"; + +std::string const& cmQtAutoGen::GeneratorName(GenT genType) { - switch (type) { - case GeneratorT::GEN: - return genNameGen; - case GeneratorT::MOC: - return genNameMoc; - case GeneratorT::UIC: - return genNameUic; - case GeneratorT::RCC: - return genNameRcc; + switch (genType) { + case GenT::GEN: + return GenAutoGen; + case GenT::MOC: + return GenAutoMoc; + case GenT::UIC: + return GenAutoUic; + case GenT::RCC: + return GenAutoRcc; } - return genNameGen; + return GenAutoGen; } -std::string cmQtAutoGen::GeneratorNameUpper(GeneratorT genType) +std::string const& cmQtAutoGen::GeneratorNameUpper(GenT genType) { - return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType)); + switch (genType) { + case GenT::GEN: + return GenAUTOGEN; + case GenT::MOC: + return GenAUTOMOC; + case GenT::UIC: + return GenAUTOUIC; + case GenT::RCC: + return GenAUTORCC; + } + return GenAUTOGEN; } std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) @@ -105,13 +118,13 @@ std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) std::string res; std::vector<std::string> lst; if (moc) { - lst.emplace_back("AUTOMOC"); + lst.emplace_back(GenAUTOMOC); } if (uic) { - lst.emplace_back("AUTOUIC"); + lst.emplace_back(GenAUTOUIC); } if (rcc) { - lst.emplace_back("AUTORCC"); + lst.emplace_back(GenAUTORCC); } switch (lst.size()) { case 1: @@ -137,13 +150,21 @@ std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) std::string cmQtAutoGen::Quoted(std::string const& text) { - static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a", - "\b", "\\b", "\f", "\\f", "\n", "\\n", - "\r", "\\r", "\t", "\\t", "\v", "\\v" }; + const std::array<std::pair<const char*, const char*>, 9> replaces = { + { { "\\", "\\\\" }, + { "\"", "\\\"" }, + { "\a", "\\a" }, + { "\b", "\\b" }, + { "\f", "\\f" }, + { "\n", "\\n" }, + { "\r", "\\r" }, + { "\t", "\\t" }, + { "\v", "\\v" } } + }; std::string res = text; - for (const char* const* it = cm::cbegin(rep); it != cm::cend(rep); it += 2) { - cmSystemTools::ReplaceString(res, *it, *(it + 1)); + for (auto const& pair : replaces) { + cmSystemTools::ReplaceString(res, pair.first, pair.second); } res = '"' + res; res += '"'; diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h index 96d1946..6cc8df1 100644 --- a/Source/cmQtAutoGen.h +++ b/Source/cmQtAutoGen.h @@ -14,20 +14,6 @@ class cmQtAutoGen { public: - /// @brief Nested lists separator - static std::string const ListSep; - /// @brief Maximum number of parallel threads/processes in a generator - static unsigned int const ParallelMax; - - /// @brief AutoGen generator type - enum class GeneratorT - { - GEN, // General - MOC, - UIC, - RCC - }; - /// @brief Integer version struct IntegerVersion { @@ -54,11 +40,34 @@ public: } }; + /// @brief AutoGen generator type + enum class GenT + { + GEN, // AUTOGEN + MOC, // AUTOMOC + UIC, // AUTOUIC + RCC // AUTORCC + }; + + /// @brief Nested lists separator + static std::string const ListSep; + // Generator names + static std::string const GenAutoGen; + static std::string const GenAutoMoc; + static std::string const GenAutoUic; + static std::string const GenAutoRcc; + static std::string const GenAUTOGEN; + static std::string const GenAUTOMOC; + static std::string const GenAUTOUIC; + static std::string const GenAUTORCC; + /// @brief Maximum number of parallel threads/processes in a generator + static unsigned int const ParallelMax; + public: /// @brief Returns the generator name - static std::string const& GeneratorName(GeneratorT genType); + static std::string const& GeneratorName(GenT genType); /// @brief Returns the generator name in upper case - static std::string GeneratorNameUpper(GeneratorT genType); + static std::string const& GeneratorNameUpper(GenT genType); /// @brief Returns a string with the requested tool names static std::string Tools(bool moc, bool uic, bool rcc); diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 95a297c..7bd0e52 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -6,10 +6,12 @@ #include "cmAlgorithms.h" #include "cmCustomCommandLines.h" +#include "cmDuration.h" #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmProcessOutput.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -72,9 +74,9 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( continue; } - bool const moc = target->GetPropertyAsBool("AUTOMOC"); - bool const uic = target->GetPropertyAsBool("AUTOUIC"); - bool const rcc = target->GetPropertyAsBool("AUTORCC"); + bool const moc = target->GetPropertyAsBool(cmQtAutoGen::GenAUTOMOC); + bool const uic = target->GetPropertyAsBool(cmQtAutoGen::GenAUTOUIC); + bool const rcc = target->GetPropertyAsBool(cmQtAutoGen::GenAUTORCC); if (moc || uic || rcc) { std::string const mocExec = target->GetSafeProperty("AUTOMOC_EXECUTABLE"); @@ -183,6 +185,68 @@ void cmQtAutoGenGlobalInitializer::AddToGlobalAutoRcc( } } +bool cmQtAutoGenGlobalInitializer::GetExecutableTestOutput( + std::string const& generator, std::string const& executable, + std::string& error, std::string* output) +{ + // Check if we have cached output + { + auto it = this->ExecutableTestOutputs_.find(executable); + if (it != this->ExecutableTestOutputs_.end()) { + // Return output on demand + if (output != nullptr) { + *output = it->second; + } + return true; + } + } + + // Check if the executable exists + if (!cmSystemTools::FileExists(executable, true)) { + error = "The \""; + error += generator; + error += "\" executable "; + error += cmQtAutoGen::Quoted(executable); + error += " does not exist."; + return false; + } + + // Test the executable + std::string stdOut; + { + std::string stdErr; + std::vector<std::string> command; + command.push_back(executable); + command.emplace_back("-h"); + int retVal = 0; + const bool runResult = cmSystemTools::RunSingleCommand( + command, &stdOut, &stdErr, &retVal, nullptr, cmSystemTools::OUTPUT_NONE, + cmDuration::zero(), cmProcessOutput::Auto); + if (!runResult) { + error = "Test run of \""; + error += generator; + error += "\" executable "; + error += cmQtAutoGen::Quoted(executable) + " failed.\n"; + error += cmQtAutoGen::QuotedCommand(command); + error += "\n"; + error += stdOut; + error += "\n"; + error += stdErr; + return false; + } + } + + // Return executable output on demand + if (output != nullptr) { + *output = stdOut; + } + + // Register executable and output + this->ExecutableTestOutputs_.emplace(executable, std::move(stdOut)); + + return true; +} + bool cmQtAutoGenGlobalInitializer::generate() { return (InitializeCustomTargets() && SetupCustomTargets()); diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h index 9e6bac0..74184a0 100644 --- a/Source/cmQtAutoGenGlobalInitializer.h +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -8,6 +8,7 @@ #include <map> #include <memory> // IWYU pragma: keep #include <string> +#include <unordered_map> #include <vector> class cmLocalGenerator; @@ -38,10 +39,15 @@ private: void AddToGlobalAutoRcc(cmLocalGenerator* localGen, std::string const& targetName); + bool GetExecutableTestOutput(std::string const& generator, + std::string const& executable, + std::string& error, std::string* output); + private: std::vector<std::unique_ptr<cmQtAutoGenInitializer>> Initializers_; std::map<cmLocalGenerator*, std::string> GlobalAutoGenTargets_; std::map<cmLocalGenerator*, std::string> GlobalAutoRccTargets_; + std::unordered_map<std::string, std::string> ExecutableTestOutputs_; }; #endif diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index a96d574..2fb6fdf 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -21,11 +21,13 @@ #include "cmPolicies.h" #include "cmProcessOutput.h" #include "cmSourceFile.h" +#include "cmSourceFileLocationKind.h" #include "cmSourceGroup.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmake.h" #include "cmsys/FStream.hxx" #include "cmsys/SystemInformation.hxx" @@ -36,25 +38,9 @@ #include <set> #include <sstream> #include <string> -#include <type_traits> #include <utility> #include <vector> -std::string GetQtExecutableTargetName( - const cmQtAutoGen::IntegerVersion& qtVersion, std::string const& executable) -{ - if (qtVersion.Major == 6) { - return ("Qt6::" + executable); - } - if (qtVersion.Major == 5) { - return ("Qt5::" + executable); - } - if (qtVersion.Major == 4) { - return ("Qt4::" + executable); - } - return (""); -} - static std::size_t GetParallelCPUCount() { static std::size_t count = 0; @@ -69,58 +55,6 @@ static std::size_t GetParallelCPUCount() return count; } -static bool AddToSourceGroup(cmMakefile* makefile, std::string const& fileName, - cmQtAutoGen::GeneratorT genType) -{ - cmSourceGroup* sourceGroup = nullptr; - // Acquire source group - { - std::string property; - std::string groupName; - { - std::array<std::string, 2> props; - // Use generator specific group name - switch (genType) { - case cmQtAutoGen::GeneratorT::MOC: - props[0] = "AUTOMOC_SOURCE_GROUP"; - break; - case cmQtAutoGen::GeneratorT::RCC: - props[0] = "AUTORCC_SOURCE_GROUP"; - break; - default: - props[0] = "AUTOGEN_SOURCE_GROUP"; - break; - } - props[1] = "AUTOGEN_SOURCE_GROUP"; - for (std::string& prop : props) { - const char* propName = makefile->GetState()->GetGlobalProperty(prop); - if ((propName != nullptr) && (*propName != '\0')) { - groupName = propName; - property = std::move(prop); - break; - } - } - } - // Generate a source group on demand - if (!groupName.empty()) { - sourceGroup = makefile->GetOrCreateSourceGroup(groupName); - if (sourceGroup == nullptr) { - std::ostringstream ost; - ost << cmQtAutoGen::GeneratorNameUpper(genType); - ost << ": " << property; - ost << ": Could not find or create the source group "; - ost << cmQtAutoGen::Quoted(groupName); - cmSystemTools::Error(ost.str()); - return false; - } - } - } - if (sourceGroup != nullptr) { - sourceGroup->AddGroupFile(fileName); - } - return true; -} - static void AddCleanFile(cmMakefile* makefile, std::string const& fileName) { makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fileName.c_str(), @@ -343,6 +277,26 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } } + // Check status of policy CMP0071 + { + cmPolicies::PolicyStatus const CMP0071_status = + makefile->GetPolicyStatus(cmPolicies::CMP0071); + switch (CMP0071_status) { + case cmPolicies::WARN: + this->CMP0071Warn = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + // Ignore GENERATED file + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Process GENERATED file + this->CMP0071Accept = true; + break; + } + } + // Common directories { // Collapsed current binary directory @@ -392,23 +346,15 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } // Moc, Uic and _autogen target settings - if (this->Moc.Enabled || this->Uic.Enabled) { + if (this->MocOrUicEnabled()) { // Init moc specific settings if (this->Moc.Enabled && !InitMoc()) { return false; } // Init uic specific settings - if (this->Uic.Enabled) { - if (InitUic()) { - auto* uicTarget = makefile->FindTargetToUse( - GetQtExecutableTargetName(this->QtVersion, "uic")); - if (uicTarget != nullptr) { - this->AutogenTarget.DependTargets.insert(uicTarget); - } - } else { - return false; - } + if (this->Uic.Enabled && !InitUic()) { + return false; } // Autogen target name @@ -449,12 +395,6 @@ bool cmQtAutoGenInitializer::InitCustomTargets() this->AutogenTarget.DependOrigin = this->Target->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS"); - auto* mocTarget = makefile->FindTargetToUse( - GetQtExecutableTargetName(this->QtVersion, "moc")); - if (mocTarget != nullptr) { - this->AutogenTarget.DependTargets.insert(mocTarget); - } - std::string const deps = this->Target->GetSafeProperty("AUTOGEN_TARGET_DEPENDS"); if (!deps.empty()) { @@ -479,8 +419,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } // Add autogen include directory to the origin target INCLUDE_DIRECTORIES - if (this->Moc.Enabled || this->Uic.Enabled || - (this->Rcc.Enabled && this->MultiConfig)) { + if (this->MocOrUicEnabled() || (this->Rcc.Enabled && this->MultiConfig)) { this->Target->AddIncludeDirectory(this->Dir.Include, true); } @@ -490,7 +429,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } // Create autogen target - if ((this->Moc.Enabled || this->Uic.Enabled) && !this->InitAutogenTarget()) { + if (this->MocOrUicEnabled() && !this->InitAutogenTarget()) { return false; } @@ -575,7 +514,18 @@ bool cmQtAutoGenInitializer::InitMoc() } // Moc executable - return GetMocExecutable(); + { + if (!this->GetQtExecutable(this->Moc, "moc", false, nullptr)) { + return false; + } + // Let the _autogen target depend on the moc executable + if (this->Moc.ExecutableTarget != nullptr) { + this->AutogenTarget.DependTargets.insert( + this->Moc.ExecutableTarget->Target); + } + } + + return true; } bool cmQtAutoGenInitializer::InitUic() @@ -618,12 +568,39 @@ bool cmQtAutoGenInitializer::InitUic() } // Uic executable - return GetUicExecutable(); + { + if (!this->GetQtExecutable(this->Uic, "uic", true, nullptr)) { + return false; + } + // Let the _autogen target depend on the uic executable + if (this->Uic.ExecutableTarget != nullptr) { + this->AutogenTarget.DependTargets.insert( + this->Uic.ExecutableTarget->Target); + } + } + + return true; } bool cmQtAutoGenInitializer::InitRcc() { - return GetRccExecutable(); + // Rcc executable + { + std::string stdOut; + if (!this->GetQtExecutable(this->Rcc, "rcc", false, &stdOut)) { + return false; + } + // Evaluate test output + if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) { + if (stdOut.find("--list") != std::string::npos) { + this->Rcc.ListOptions.emplace_back("--list"); + } else { + this->Rcc.ListOptions.emplace_back("-list"); + } + } + } + + return true; } bool cmQtAutoGenInitializer::InitScanFiles() @@ -634,61 +611,78 @@ bool cmQtAutoGenInitializer::InitScanFiles() std::string const SKIP_AUTOGEN_str = "SKIP_AUTOGEN"; std::string const SKIP_AUTOMOC_str = "SKIP_AUTOMOC"; std::string const SKIP_AUTOUIC_str = "SKIP_AUTOUIC"; + std::string const SKIP_AUTORCC_str = "SKIP_AUTORCC"; + std::string const AUTOUIC_OPTIONS_str = "AUTOUIC_OPTIONS"; + std::string const AUTORCC_OPTIONS_str = "AUTORCC_OPTIONS"; + std::string const qrc_str = "qrc"; + std::string const ui_str = "ui"; + + auto makeMUFile = [&](cmSourceFile* sf, std::string const& fullPath, + bool muIt) -> MUFileHandle { + MUFileHandle muf = cm::make_unique<MUFile>(); + muf->RealPath = cmSystemTools::GetRealPath(fullPath); + muf->SF = sf; + muf->Generated = sf->GetIsGenerated(); + bool const skipAutogen = sf->GetPropertyAsBool(SKIP_AUTOGEN_str); + muf->SkipMoc = this->Moc.Enabled && + (skipAutogen || sf->GetPropertyAsBool(SKIP_AUTOMOC_str)); + muf->SkipUic = this->Uic.Enabled && + (skipAutogen || sf->GetPropertyAsBool(SKIP_AUTOUIC_str)); + if (muIt) { + muf->MocIt = this->Moc.Enabled && !muf->SkipMoc; + muf->UicIt = this->Uic.Enabled && !muf->SkipUic; + } + return muf; + }; + + auto addMUFile = [&](MUFileHandle&& muf, bool isHeader) { + if ((muf->MocIt || muf->UicIt) && muf->Generated) { + this->AutogenTarget.FilesGenerated.emplace_back(muf.get()); + } + if (isHeader) { + this->AutogenTarget.Headers.emplace(muf->SF, std::move(muf)); + } else { + this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf)); + } + }; // Scan through target files { - // String constants - std::string const qrc_str = "qrc"; - std::string const SKIP_AUTORCC_str = "SKIP_AUTORCC"; - std::string const AUTORCC_OPTIONS_str = "AUTORCC_OPTIONS"; - // Scan through target files std::vector<cmSourceFile*> srcFiles; this->Target->GetConfigCommonSourceFiles(srcFiles); for (cmSourceFile* sf : srcFiles) { - if (sf->GetPropertyAsBool(SKIP_AUTOGEN_str)) { + // sf->GetExtension() is only valid after sf->GetFullPath() ... + // Since we're iterating over source files that might be not in the + // target we need to check for path errors (not existing files). + std::string pathError; + std::string const& fullPath = sf->GetFullPath(&pathError); + if (!pathError.empty() || fullPath.empty()) { continue; } - - // sf->GetExtension() is only valid after sf->GetFullPath() ... - std::string const& fPath = sf->GetFullPath(); std::string const& ext = sf->GetExtension(); - // Register generated files that will be scanned by moc or uic - if (this->Moc.Enabled || this->Uic.Enabled) { - cmSystemTools::FileFormat const fileType = - cmSystemTools::GetFileFormat(ext); - if ((fileType == cmSystemTools::CXX_FILE_FORMAT) || - (fileType == cmSystemTools::HEADER_FILE_FORMAT)) { - std::string const absPath = cmSystemTools::GetRealPath(fPath); - if ((this->Moc.Enabled && - !sf->GetPropertyAsBool(SKIP_AUTOMOC_str)) || - (this->Uic.Enabled && - !sf->GetPropertyAsBool(SKIP_AUTOUIC_str))) { - // Register source - const bool generated = sf->GetIsGenerated(); - if (fileType == cmSystemTools::HEADER_FILE_FORMAT) { - if (generated) { - this->AutogenTarget.HeadersGenerated.push_back(absPath); - } else { - this->AutogenTarget.Headers.push_back(absPath); - } - } else { - if (generated) { - this->AutogenTarget.SourcesGenerated.push_back(absPath); - } else { - this->AutogenTarget.Sources.push_back(absPath); - } - } - } + // Register files that will be scanned by moc or uic + if (this->MocOrUicEnabled()) { + switch (cmSystemTools::GetFileFormat(ext)) { + case cmSystemTools::HEADER_FILE_FORMAT: + addMUFile(makeMUFile(sf, fullPath, true), true); + break; + case cmSystemTools::CXX_FILE_FORMAT: + addMUFile(makeMUFile(sf, fullPath, true), false); + break; + default: + break; } } + // Register rcc enabled files if (this->Rcc.Enabled) { - if ((ext == qrc_str) && !sf->GetPropertyAsBool(SKIP_AUTORCC_str)) { + if ((ext == qrc_str) && !sf->GetPropertyAsBool(SKIP_AUTOGEN_str) && + !sf->GetPropertyAsBool(SKIP_AUTORCC_str)) { // Register qrc file Qrc qrc; - qrc.QrcFile = cmSystemTools::GetRealPath(fPath); + qrc.QrcFile = cmSystemTools::GetRealPath(fullPath); qrc.QrcName = cmSystemTools::GetFilenameWithoutLastExtension(qrc.QrcFile); qrc.Generated = sf->GetIsGenerated(); @@ -710,15 +704,72 @@ bool cmQtAutoGenInitializer::InitScanFiles() // mocs_compilation.cpp source acknowledged by this target. this->Target->ClearSourcesCache(); + // For source files find additional headers and private headers + if (this->MocOrUicEnabled()) { + std::vector<MUFileHandle> extraHeaders; + extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2); + // Header search suffixes and extensions + std::array<std::string, 2> const suffixes{ { "", "_p" } }; + auto const& exts = makefile->GetCMakeInstance()->GetHeaderExtensions(); + // Scan through sources + for (auto const& pair : this->AutogenTarget.Sources) { + MUFile const& muf = *pair.second; + if (muf.MocIt || muf.UicIt) { + // Search for the default header file and a private header + std::string const& realPath = muf.RealPath; + std::string basePath = cmQtAutoGen::SubDirPrefix(realPath); + basePath += cmSystemTools::GetFilenameWithoutLastExtension(realPath); + for (auto const& suffix : suffixes) { + std::string const suffixedPath = basePath + suffix; + for (auto const& ext : exts) { + std::string fullPath = suffixedPath; + fullPath += '.'; + fullPath += ext; + + auto constexpr locationKind = cmSourceFileLocationKind::Known; + cmSourceFile* sf = makefile->GetSource(fullPath, locationKind); + if (sf != nullptr) { + // Check if we know about this header already + if (this->AutogenTarget.Headers.find(sf) != + this->AutogenTarget.Headers.end()) { + continue; + } + // We only accept not-GENERATED files that do exist. + if (!sf->GetIsGenerated() && + !cmSystemTools::FileExists(fullPath)) { + continue; + } + } else if (cmSystemTools::FileExists(fullPath)) { + // Create a new source file for the existing file + sf = makefile->CreateSource(fullPath, false, locationKind); + } + + if (sf != nullptr) { + auto eMuf = makeMUFile(sf, fullPath, true); + // Ony process moc/uic when the parent is processed as well + if (!muf.MocIt) { + eMuf->MocIt = false; + } + if (!muf.UicIt) { + eMuf->UicIt = false; + } + extraHeaders.emplace_back(std::move(eMuf)); + } + } + } + } + } + // Move generated files to main headers list + for (auto& eMuf : extraHeaders) { + addMUFile(std::move(eMuf), true); + } + } + // Scan through all source files in the makefile to extract moc and uic // parameters. Historically we support non target source file parameters. // The reason is that their file names might be discovered from source files // at generation time. - if (this->Moc.Enabled || this->Uic.Enabled) { - // String constants - std::string const ui_str = "ui"; - std::string const AUTOUIC_OPTIONS_str = "AUTOUIC_OPTIONS"; - + if (this->MocOrUicEnabled()) { for (cmSourceFile* sf : makefile->GetSourceFiles()) { // sf->GetExtension() is only valid after sf->GetFullPath() ... // Since we're iterating over source files that might be not in the @@ -728,132 +779,87 @@ bool cmQtAutoGenInitializer::InitScanFiles() if (!pathError.empty() || fullPath.empty()) { continue; } + std::string const& ext = sf->GetExtension(); - // Check file type - auto const fileType = cmSystemTools::GetFileFormat(sf->GetExtension()); - bool const isSource = (fileType == cmSystemTools::CXX_FILE_FORMAT) || - (fileType == cmSystemTools::HEADER_FILE_FORMAT); - bool const isUi = (this->Moc.Enabled && sf->GetExtension() == ui_str); - - // Process only certain file types - if (isSource || isUi) { - std::string const absFile = cmSystemTools::GetRealPath(fullPath); - // Acquire file properties - bool const skipAUTOGEN = sf->GetPropertyAsBool(SKIP_AUTOGEN_str); - bool const skipMoc = (this->Moc.Enabled && isSource) && - (skipAUTOGEN || sf->GetPropertyAsBool(SKIP_AUTOMOC_str)); - bool const skipUic = this->Uic.Enabled && - (skipAUTOGEN || sf->GetPropertyAsBool(SKIP_AUTOUIC_str)); - - // Register moc and uic skipped file - if (skipMoc) { - this->Moc.Skip.insert(absFile); + auto const fileFormat = cmSystemTools::GetFileFormat(ext); + if (fileFormat == cmSystemTools::HEADER_FILE_FORMAT) { + if (this->AutogenTarget.Headers.find(sf) == + this->AutogenTarget.Headers.end()) { + auto muf = makeMUFile(sf, fullPath, false); + if (muf->SkipMoc || muf->SkipUic) { + this->AutogenTarget.Headers.emplace(sf, std::move(muf)); + } } - if (skipUic) { - this->Uic.Skip.insert(absFile); + } else if (fileFormat == cmSystemTools::CXX_FILE_FORMAT) { + if (this->AutogenTarget.Sources.find(sf) == + this->AutogenTarget.Sources.end()) { + auto muf = makeMUFile(sf, fullPath, false); + if (muf->SkipMoc || muf->SkipUic) { + this->AutogenTarget.Sources.emplace(sf, std::move(muf)); + } } - - // Check if the .ui file has uic options - if (isUi && !skipUic) { + } else if (this->Uic.Enabled && (ext == ui_str)) { + // .ui file + std::string realPath = cmSystemTools::GetRealPath(fullPath); + bool const skipAutogen = sf->GetPropertyAsBool(SKIP_AUTOGEN_str); + bool const skipUic = + (skipAutogen || sf->GetPropertyAsBool(SKIP_AUTOUIC_str)); + if (!skipUic) { + // Check if the .ui file has uic options std::string const uicOpts = sf->GetSafeProperty(AUTOUIC_OPTIONS_str); if (!uicOpts.empty()) { - this->Uic.FileFiles.push_back(absFile); + this->Uic.FileFiles.push_back(std::move(realPath)); std::vector<std::string> optsVec; cmSystemTools::ExpandListArgument(uicOpts, optsVec); this->Uic.FileOptions.push_back(std::move(optsVec)); } + } else { + // Register skipped .ui file + this->Uic.SkipUi.insert(std::move(realPath)); } } } } // Process GENERATED sources and headers - if (this->Moc.Enabled || this->Uic.Enabled) { - if (!this->AutogenTarget.SourcesGenerated.empty() || - !this->AutogenTarget.HeadersGenerated.empty()) { - // Check status of policy CMP0071 - bool policyAccept = false; - bool policyWarn = false; - cmPolicies::PolicyStatus const CMP0071_status = - makefile->GetPolicyStatus(cmPolicies::CMP0071); - switch (CMP0071_status) { - case cmPolicies::WARN: - policyWarn = true; - CM_FALLTHROUGH; - case cmPolicies::OLD: - // Ignore GENERATED file - break; - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::NEW: - // Process GENERATED file - policyAccept = true; - break; + if (this->MocOrUicEnabled() && !this->AutogenTarget.FilesGenerated.empty()) { + if (this->CMP0071Accept) { + // Let the autogen target depend on the GENERATED files + for (MUFile* muf : this->AutogenTarget.FilesGenerated) { + this->AutogenTarget.DependFiles.insert(muf->RealPath); } - - if (policyAccept) { - // Accept GENERATED sources - for (std::string const& absFile : - this->AutogenTarget.HeadersGenerated) { - this->AutogenTarget.Headers.push_back(absFile); - this->AutogenTarget.DependFiles.insert(absFile); - } - for (std::string const& absFile : - this->AutogenTarget.SourcesGenerated) { - this->AutogenTarget.Sources.push_back(absFile); - this->AutogenTarget.DependFiles.insert(absFile); - } - } else { - if (policyWarn) { - std::string msg; - msg += cmPolicies::GetPolicyWarning(cmPolicies::CMP0071); - msg += "\n"; - std::string tools; - std::string property; - if (this->Moc.Enabled && this->Uic.Enabled) { - tools = "AUTOMOC and AUTOUIC"; - property = "SKIP_AUTOGEN"; - } else if (this->Moc.Enabled) { - tools = "AUTOMOC"; - property = "SKIP_AUTOMOC"; - } else if (this->Uic.Enabled) { - tools = "AUTOUIC"; - property = "SKIP_AUTOUIC"; - } - msg += "For compatibility, CMake is excluding the GENERATED source " - "file(s):\n"; - for (const std::string& absFile : - this->AutogenTarget.HeadersGenerated) { - msg.append(" ").append(Quoted(absFile)).append("\n"); - } - for (const std::string& absFile : - this->AutogenTarget.SourcesGenerated) { - msg.append(" ").append(Quoted(absFile)).append("\n"); - } - msg += "from processing by "; - msg += tools; - msg += - ". If any of the files should be processed, set CMP0071 to NEW. " - "If any of the files should not be processed, " - "explicitly exclude them by setting the source file property "; - msg += property; - msg += ":\n set_property(SOURCE file.h PROPERTY "; - msg += property; - msg += " ON)\n"; - makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg); - } + } else if (this->CMP0071Warn) { + std::string msg; + msg += cmPolicies::GetPolicyWarning(cmPolicies::CMP0071); + msg += '\n'; + std::string property; + if (this->Moc.Enabled && this->Uic.Enabled) { + property = "SKIP_AUTOGEN"; + } else if (this->Moc.Enabled) { + property = "SKIP_AUTOMOC"; + } else if (this->Uic.Enabled) { + property = "SKIP_AUTOUIC"; } + msg += "For compatibility, CMake is excluding the GENERATED source " + "file(s):\n"; + for (MUFile* muf : this->AutogenTarget.FilesGenerated) { + msg += " "; + msg += Quoted(muf->RealPath); + msg += '\n'; + } + msg += "from processing by "; + msg += cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false); + msg += ". If any of the files should be processed, set CMP0071 to NEW. " + "If any of the files should not be processed, " + "explicitly exclude them by setting the source file property "; + msg += property; + msg += ":\n set_property(SOURCE file.h PROPERTY "; + msg += property; + msg += " ON)\n"; + makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg); } } - // Sort headers and sources - if (this->Moc.Enabled || this->Uic.Enabled) { - std::sort(this->AutogenTarget.Headers.begin(), - this->AutogenTarget.Headers.end()); - std::sort(this->AutogenTarget.Sources.begin(), - this->AutogenTarget.Sources.end()); - } - // Process qrc files if (!this->Rcc.Qrcs.empty()) { const bool modernQt = (this->QtVersion.Major >= 5); @@ -961,7 +967,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Files provided by the autogen target std::vector<std::string> autogenProvides; if (this->Moc.Enabled) { - this->AddGeneratedSource(this->Moc.MocsCompilation, GeneratorT::MOC, true); + this->AddGeneratedSource(this->Moc.MocsCompilation, this->Moc, true); autogenProvides.push_back(this->Moc.MocsCompilation); } @@ -1109,13 +1115,12 @@ bool cmQtAutoGenInitializer::InitRccTargets() { cmMakefile* makefile = this->Target->Target->GetMakefile(); cmLocalGenerator* localGen = this->Target->GetLocalGenerator(); - auto rccTargetName = GetQtExecutableTargetName(this->QtVersion, "rcc"); for (Qrc const& qrc : this->Rcc.Qrcs) { // Register info file as generated by CMake makefile->AddCMakeOutputFile(qrc.InfoFile); // Register file at target - this->AddGeneratedSource(qrc.RccFile, GeneratorT::RCC); + this->AddGeneratedSource(qrc.RccFile, this->Rcc); std::vector<std::string> ccOutput; ccOutput.push_back(qrc.RccFile); @@ -1174,8 +1179,8 @@ bool cmQtAutoGenInitializer::InitRccTargets() if (!this->TargetsFolder.empty()) { autoRccTarget->SetProperty("FOLDER", this->TargetsFolder.c_str()); } - if (!rccTargetName.empty()) { - autoRccTarget->AddUtility(rccTargetName, makefile); + if (!this->Rcc.ExecutableTargetName.empty()) { + autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, makefile); } } // Add autogen target to the origin target dependencies @@ -1195,8 +1200,8 @@ bool cmQtAutoGenInitializer::InitRccTargets() // Add resource file to the custom command dependencies ccDepends.push_back(fileName); } - if (!rccTargetName.empty()) { - ccDepends.push_back(rccTargetName); + if (!this->Rcc.ExecutableTargetName.empty()) { + ccDepends.push_back(this->Rcc.ExecutableTargetName); } makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends, /*main_dependency*/ std::string(), @@ -1222,7 +1227,7 @@ bool cmQtAutoGenInitializer::SetupCustomTargets() } // Generate autogen target info file - if (this->Moc.Enabled || this->Uic.Enabled) { + if (this->MocOrUicEnabled()) { // Write autogen target info files if (!this->SetupWriteAutogenInfo()) { return false; @@ -1262,22 +1267,74 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo() ofs.Write("AM_INCLUDE_DIR", this->Dir.Include); ofs.WriteConfig("AM_INCLUDE_DIR", this->Dir.ConfigInclude); - ofs.Write("# Files\n"); - ofs.WriteStrings("AM_SOURCES", this->AutogenTarget.Sources); - ofs.WriteStrings("AM_HEADERS", this->AutogenTarget.Headers); - ofs.Write("AM_SETTINGS_FILE", this->AutogenTarget.SettingsFile); - ofs.WriteConfig("AM_SETTINGS_FILE", - this->AutogenTarget.ConfigSettingsFile); + // Use sorted sets + std::set<std::string> headers; + std::set<std::string> sources; + std::set<std::string> moc_headers; + std::set<std::string> moc_sources; + std::set<std::string> moc_skip; + std::set<std::string> uic_headers; + std::set<std::string> uic_sources; + std::set<std::string> uic_skip; + // Filter headers + for (auto const& pair : this->AutogenTarget.Headers) { + MUFile const& muf = *pair.second; + if (muf.Generated && !this->CMP0071Accept) { + continue; + } + if (muf.SkipMoc) { + moc_skip.insert(muf.RealPath); + } + if (muf.SkipUic) { + uic_skip.insert(muf.RealPath); + } + if (muf.MocIt && muf.UicIt) { + headers.insert(muf.RealPath); + } else if (muf.MocIt) { + moc_headers.insert(muf.RealPath); + } else if (muf.UicIt) { + uic_headers.insert(muf.RealPath); + } + } + // Filter sources + for (auto const& pair : this->AutogenTarget.Sources) { + MUFile const& muf = *pair.second; + if (muf.Generated && !this->CMP0071Accept) { + continue; + } + if (muf.SkipMoc) { + moc_skip.insert(muf.RealPath); + } + if (muf.SkipUic) { + uic_skip.insert(muf.RealPath); + } + if (muf.MocIt && muf.UicIt) { + sources.insert(muf.RealPath); + } else if (muf.MocIt) { + moc_sources.insert(muf.RealPath); + } else if (muf.UicIt) { + uic_sources.insert(muf.RealPath); + } + } ofs.Write("# Qt\n"); ofs.WriteUInt("AM_QT_VERSION_MAJOR", this->QtVersion.Major); ofs.Write("AM_QT_MOC_EXECUTABLE", this->Moc.Executable); ofs.Write("AM_QT_UIC_EXECUTABLE", this->Uic.Executable); + ofs.Write("# Files\n"); + ofs.Write("AM_SETTINGS_FILE", this->AutogenTarget.SettingsFile); + ofs.WriteConfig("AM_SETTINGS_FILE", + this->AutogenTarget.ConfigSettingsFile); + ofs.WriteStrings("AM_HEADERS", headers); + ofs.WriteStrings("AM_SOURCES", sources); + // Write moc settings if (this->Moc.Enabled) { ofs.Write("# MOC settings\n"); - ofs.WriteStrings("AM_MOC_SKIP", this->Moc.Skip); + ofs.WriteStrings("AM_MOC_HEADERS", moc_headers); + ofs.WriteStrings("AM_MOC_SOURCES", moc_sources); + ofs.WriteStrings("AM_MOC_SKIP", moc_skip); ofs.WriteStrings("AM_MOC_DEFINITIONS", this->Moc.Defines); ofs.WriteConfigStrings("AM_MOC_DEFINITIONS", this->Moc.ConfigDefines); ofs.WriteStrings("AM_MOC_INCLUDES", this->Moc.Includes); @@ -1294,8 +1351,13 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo() // Write uic settings if (this->Uic.Enabled) { + // Add skipped .ui files + uic_skip.insert(this->Uic.SkipUi.begin(), this->Uic.SkipUi.end()); + ofs.Write("# UIC settings\n"); - ofs.WriteStrings("AM_UIC_SKIP", this->Uic.Skip); + ofs.WriteStrings("AM_UIC_HEADERS", uic_headers); + ofs.WriteStrings("AM_UIC_SOURCES", uic_sources); + ofs.WriteStrings("AM_UIC_SKIP", uic_skip); ofs.WriteStrings("AM_UIC_TARGET_OPTIONS", this->Uic.Options); ofs.WriteConfigStrings("AM_UIC_TARGET_OPTIONS", this->Uic.ConfigOptions); ofs.WriteStrings("AM_UIC_OPTIONS_FILES", this->Uic.FileFiles); @@ -1353,23 +1415,68 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo() return true; } -void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, - GeneratorT genType, - bool prepend) +void cmQtAutoGenInitializer::RegisterGeneratedSource( + std::string const& filename) { - // Register source file in makefile cmMakefile* makefile = this->Target->Target->GetMakefile(); - { - cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); - gFile->SetProperty("GENERATED", "1"); - gFile->SetProperty("SKIP_AUTOGEN", "On"); - } - - // Add source file to source group - AddToSourceGroup(makefile, filename, genType); + cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); + gFile->SetProperty("GENERATED", "1"); + gFile->SetProperty("SKIP_AUTOGEN", "1"); +} +bool cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, + GenVarsT const& genVars, + bool prepend) +{ + // Register source at makefile + this->RegisterGeneratedSource(filename); // Add source file to target this->Target->AddSource(filename, prepend); + // Add source file to source group + return this->AddToSourceGroup(filename, genVars.GenNameUpper); +} + +bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName, + std::string const& genNameUpper) +{ + cmMakefile* makefile = this->Target->Target->GetMakefile(); + cmSourceGroup* sourceGroup = nullptr; + // Acquire source group + { + std::string property; + std::string groupName; + { + // Prefer generator specific source group name + std::array<std::string, 2> props{ { genNameUpper + "_SOURCE_GROUP", + "AUTOGEN_SOURCE_GROUP" } }; + for (std::string& prop : props) { + const char* propName = makefile->GetState()->GetGlobalProperty(prop); + if ((propName != nullptr) && (*propName != '\0')) { + groupName = propName; + property = std::move(prop); + break; + } + } + } + // Generate a source group on demand + if (!groupName.empty()) { + sourceGroup = makefile->GetOrCreateSourceGroup(groupName); + if (sourceGroup == nullptr) { + std::string err; + err += genNameUpper; + err += " error in "; + err += property; + err += ": Could not find or create the source group "; + err += cmQtAutoGen::Quoted(groupName); + cmSystemTools::Error(err); + return false; + } + } + } + if (sourceGroup != nullptr) { + sourceGroup->AddGroupFile(fileName); + } + return true; } static unsigned int CharPtrToUInt(const char* const input) @@ -1384,8 +1491,12 @@ static unsigned int CharPtrToUInt(const char* const input) static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions( cmGeneratorTarget const* target) { - cmMakefile* makefile = target->Target->GetMakefile(); + // Qt version variable prefixes + static std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core", + "QT" } }; + std::vector<cmQtAutoGen::IntegerVersion> result; + result.reserve(prefixes.size() * 2); // Adds a version to the result (nullptr safe) auto addVersion = [&result](const char* major, const char* minor) { cmQtAutoGen::IntegerVersion ver(CharPtrToUInt(major), @@ -1394,8 +1505,7 @@ static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions( result.emplace_back(ver); } }; - // Qt version variable prefixes - std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core", "QT" } }; + cmMakefile* makefile = target->Target->GetMakefile(); // Read versions from variables for (const std::string& prefix : prefixes) { @@ -1439,124 +1549,89 @@ cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target) return res; } -std::pair<bool, std::string> GetQtExecutable( - const cmQtAutoGen::IntegerVersion& qtVersion, cmGeneratorTarget* target, - const std::string& executable, bool ignoreMissingTarget, std::string* output) +bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars, + const std::string& executable, + bool ignoreMissingTarget, + std::string* output) const { - const std::string upperExecutable = cmSystemTools::UpperCase(executable); - std::string result = - target->Target->GetSafeProperty("AUTO" + upperExecutable + "_EXECUTABLE"); - if (!result.empty()) { - cmListFileBacktrace lfbt = target->Target->GetMakefile()->GetBacktrace(); - cmGeneratorExpression ge(lfbt); - std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(result); - result = cge->Evaluate(target->GetLocalGenerator(), ""); - - return std::make_pair(true, result); - } - - std::string err; + auto print_err = [this, &genVars](std::string const& err) { + std::string msg = genVars.GenNameUpper; + msg += " for target "; + msg += this->Target->GetName(); + msg += ": "; + msg += err; + cmSystemTools::Error(msg); + }; - // Find executable + // Custom executable { - const std::string targetName = - GetQtExecutableTargetName(qtVersion, executable); - if (targetName.empty()) { - err = "The AUTO" + upperExecutable + " feature "; - err += "supports only Qt 4, Qt 5 and Qt 6."; - } else { - cmLocalGenerator* localGen = target->GetLocalGenerator(); - cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse(targetName); - if (tgt != nullptr) { - if (tgt->IsImported()) { - result = tgt->ImportedGetLocation(""); - } else { - result = tgt->GetLocation(""); - } - } else { - if (ignoreMissingTarget) { - return std::make_pair(true, ""); - } - - err = "Could not find target " + targetName; + std::string const prop = genVars.GenNameUpper + "_EXECUTABLE"; + std::string const val = this->Target->Target->GetSafeProperty(prop); + if (!val.empty()) { + // Evaluate generator expression + { + cmListFileBacktrace lfbt = + this->Target->Target->GetMakefile()->GetBacktrace(); + cmGeneratorExpression ge(lfbt); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val); + genVars.Executable = + cge->Evaluate(this->Target->GetLocalGenerator(), ""); } + if (genVars.Executable.empty() && !ignoreMissingTarget) { + print_err(prop + " evaluates to an empty value"); + return false; + } + return true; } } - // Test executable - if (err.empty()) { - if (cmSystemTools::FileExists(result, true)) { - std::vector<std::string> command; - command.push_back(result); - command.emplace_back("-h"); - std::string stdOut; - std::string stdErr; - int retVal = 0; - const bool runResult = cmSystemTools::RunSingleCommand( - command, &stdOut, &stdErr, &retVal, nullptr, - cmSystemTools::OUTPUT_NONE, cmDuration::zero(), cmProcessOutput::Auto); - if (!runResult) { - err = "Test of \"" + executable + "\" binary "; - err += cmQtAutoGen::Quoted(result) + " failed: "; - err += cmQtAutoGen::QuotedCommand(command); + // Find executable target + { + // Find executable target name + std::string targetName; + if (this->QtVersion.Major == 4) { + targetName = "Qt4::"; + } else if (this->QtVersion.Major == 5) { + targetName = "Qt5::"; + } else if (this->QtVersion.Major == 6) { + targetName = "Qt6::"; + } + targetName += executable; + + // Find target + cmLocalGenerator* localGen = this->Target->GetLocalGenerator(); + cmGeneratorTarget* target = localGen->FindGeneratorTargetToUse(targetName); + if (target != nullptr) { + genVars.ExecutableTargetName = targetName; + genVars.ExecutableTarget = target; + if (target->IsImported()) { + genVars.Executable = target->ImportedGetLocation(""); } else { - if (output != nullptr) { - *output = stdOut; - } + genVars.Executable = target->GetLocation(""); } } else { - err = "The \"" + executable + "\" binary "; - err += cmQtAutoGen::Quoted(result); - err += " does not exist"; + if (ignoreMissingTarget) { + return true; + } + std::string err = "Could not find "; + err += executable; + err += " executable target "; + err += targetName; + print_err(err); + return false; } } - // Print error - if (!err.empty()) { - std::string msg = "AutoGen ("; - msg += target->GetName(); - msg += "): "; - msg += err; - cmSystemTools::Error(msg); - return std::make_pair(false, ""); - } - - return std::make_pair(true, result); -} - -bool cmQtAutoGenInitializer::GetMocExecutable() -{ - const auto result = - GetQtExecutable(this->QtVersion, this->Target, "moc", false, nullptr); - this->Moc.Executable = result.second; - return result.first; -} - -bool cmQtAutoGenInitializer::GetUicExecutable() -{ - const auto result = - GetQtExecutable(this->QtVersion, this->Target, "uic", true, nullptr); - this->Uic.Executable = result.second; - return result.first; -} - -bool cmQtAutoGenInitializer::GetRccExecutable() -{ - std::string stdOut; - const auto result = - GetQtExecutable(this->QtVersion, this->Target, "rcc", false, &stdOut); - this->Rcc.Executable = result.second; - if (!result.first) { - return false; - } - - if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) { - if (stdOut.find("--list") != std::string::npos) { - this->Rcc.ListOptions.emplace_back("--list"); - } else { - this->Rcc.ListOptions.emplace_back("-list"); + // Test executable + { + std::string err; + if (!this->GlobalInitializer->GetExecutableTestOutput( + executable, genVars.Executable, err, output)) { + print_err(err); + return false; } } + return true; } diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 10f0bf3..700f16b 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -8,15 +8,18 @@ #include "cmQtAutoGen.h" #include <map> +#include <memory> // IWYU pragma: keep #include <ostream> #include <set> #include <string> +#include <unordered_map> #include <utility> #include <vector> class cmGeneratorTarget; class cmTarget; class cmQtAutoGenGlobalInitializer; +class cmSourceFile; /// @brief Initializes the QtAutoGen generators class cmQtAutoGenInitializer : public cmQtAutoGen @@ -40,6 +43,40 @@ public: std::vector<std::string> Resources; }; + /// @brief Moc/Uic file + struct MUFile + { + std::string RealPath; + cmSourceFile* SF = nullptr; + bool Generated = false; + bool SkipMoc = false; + bool SkipUic = false; + bool MocIt = false; + bool UicIt = false; + }; + typedef std::unique_ptr<MUFile> MUFileHandle; + + /// @brief Abstract moc/uic/rcc generator variables base class + struct GenVarsT + { + bool Enabled = false; + // Generator type/name + GenT Gen; + std::string const& GenName; + std::string const& GenNameUpper; + // Executable + std::string ExecutableTargetName; + cmGeneratorTarget* ExecutableTarget = nullptr; + std::string Executable; + + /// @brief Constructor + GenVarsT(GenT gen, std::string const& genName, + std::string const& genNameUpper) + : Gen(gen) + , GenName(genName) + , GenNameUpper(genNameUpper){}; + }; + /// @brief Writes a CMake info file class InfoWriter { @@ -88,6 +125,12 @@ public: bool SetupCustomTargets(); private: + /// @brief If moc or uic is enabled, the autogen target will be generated + bool MocOrUicEnabled() const + { + return (this->Moc.Enabled || this->Uic.Enabled); + } + bool InitMoc(); bool InitUic(); bool InitRcc(); @@ -99,12 +142,14 @@ private: bool SetupWriteAutogenInfo(); bool SetupWriteRccInfo(); - void AddGeneratedSource(std::string const& filename, GeneratorT genType, + void RegisterGeneratedSource(std::string const& filename); + bool AddGeneratedSource(std::string const& filename, GenVarsT const& genVars, bool prepend = false); + bool AddToSourceGroup(std::string const& fileName, + std::string const& genNameUpper); - bool GetMocExecutable(); - bool GetUicExecutable(); - bool GetRccExecutable(); + bool GetQtExecutable(GenVarsT& genVars, const std::string& executable, + bool ignoreMissingTarget, std::string* output) const; bool RccListInputs(std::string const& fileName, std::vector<std::string>& files, @@ -121,6 +166,8 @@ private: std::vector<std::string> ConfigsList; std::string Verbosity; std::string TargetsFolder; + bool CMP0071Accept = false; + bool CMP0071Warn = false; /// @brief Common directories struct @@ -148,47 +195,54 @@ private: std::set<std::string> DependFiles; std::set<cmTarget*> DependTargets; // Sources to process - std::vector<std::string> Headers; - std::vector<std::string> Sources; - std::vector<std::string> HeadersGenerated; - std::vector<std::string> SourcesGenerated; + std::unordered_map<cmSourceFile*, MUFileHandle> Headers; + std::unordered_map<cmSourceFile*, MUFileHandle> Sources; + std::vector<MUFile*> FilesGenerated; } AutogenTarget; /// @brief Moc only variables - struct + struct MocT : public GenVarsT { - bool Enabled = false; - std::string Executable; std::string PredefsCmd; - std::set<std::string> Skip; std::vector<std::string> Includes; std::map<std::string, std::vector<std::string>> ConfigIncludes; std::set<std::string> Defines; std::map<std::string, std::set<std::string>> ConfigDefines; std::string MocsCompilation; + + /// @brief Constructor + MocT() + : GenVarsT(cmQtAutoGen::GenT::MOC, cmQtAutoGen::GenAutoMoc, + cmQtAutoGen::GenAUTOMOC){}; } Moc; - ///@brief Uic only variables - struct + /// @brief Uic only variables + struct UicT : public GenVarsT { - bool Enabled = false; - std::string Executable; - std::set<std::string> Skip; + std::set<std::string> SkipUi; std::vector<std::string> SearchPaths; std::vector<std::string> Options; std::map<std::string, std::vector<std::string>> ConfigOptions; std::vector<std::string> FileFiles; std::vector<std::vector<std::string>> FileOptions; + + /// @brief Constructor + UicT() + : GenVarsT(cmQtAutoGen::GenT::UIC, cmQtAutoGen::GenAutoUic, + cmQtAutoGen::GenAUTOUIC){}; } Uic; /// @brief Rcc only variables - struct + struct RccT : public GenVarsT { - bool Enabled = false; bool GlobalTarget = false; - std::string Executable; std::vector<std::string> ListOptions; std::vector<Qrc> Qrcs; + + /// @brief Constructor + RccT() + : GenVarsT(cmQtAutoGen::GenT::RCC, cmQtAutoGen::GenAutoRcc, + cmQtAutoGen::GenAUTORCC){}; } Rcc; }; diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index e2d7deb..af50c1d 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -43,8 +43,7 @@ std::string cmQtAutoGenerator::Logger::HeadLine(std::string const& title) return head; } -void cmQtAutoGenerator::Logger::Info(GeneratorT genType, - std::string const& message) +void cmQtAutoGenerator::Logger::Info(GenT genType, std::string const& message) { std::string msg = GeneratorName(genType); msg += ": "; @@ -58,7 +57,7 @@ void cmQtAutoGenerator::Logger::Info(GeneratorT genType, } } -void cmQtAutoGenerator::Logger::Warning(GeneratorT genType, +void cmQtAutoGenerator::Logger::Warning(GenT genType, std::string const& message) { std::string msg; @@ -82,7 +81,7 @@ void cmQtAutoGenerator::Logger::Warning(GeneratorT genType, } } -void cmQtAutoGenerator::Logger::WarningFile(GeneratorT genType, +void cmQtAutoGenerator::Logger::WarningFile(GenT genType, std::string const& filename, std::string const& message) { @@ -94,8 +93,7 @@ void cmQtAutoGenerator::Logger::WarningFile(GeneratorT genType, Warning(genType, msg); } -void cmQtAutoGenerator::Logger::Error(GeneratorT genType, - std::string const& message) +void cmQtAutoGenerator::Logger::Error(GenT genType, std::string const& message) { std::string msg; msg += HeadLine(GeneratorName(genType) + " error"); @@ -111,7 +109,7 @@ void cmQtAutoGenerator::Logger::Error(GeneratorT genType, } } -void cmQtAutoGenerator::Logger::ErrorFile(GeneratorT genType, +void cmQtAutoGenerator::Logger::ErrorFile(GenT genType, std::string const& filename, std::string const& message) { @@ -124,7 +122,7 @@ void cmQtAutoGenerator::Logger::ErrorFile(GeneratorT genType, } void cmQtAutoGenerator::Logger::ErrorCommand( - GeneratorT genType, std::string const& message, + GenT genType, std::string const& message, std::vector<std::string> const& command, std::string const& output) { std::string msg; @@ -297,7 +295,7 @@ bool cmQtAutoGenerator::FileSystem::FileRead(std::string& content, return success; } -bool cmQtAutoGenerator::FileSystem::FileRead(GeneratorT genType, +bool cmQtAutoGenerator::FileSystem::FileRead(GenT genType, std::string& content, std::string const& filename) { @@ -343,7 +341,7 @@ bool cmQtAutoGenerator::FileSystem::FileWrite(std::string const& filename, return success; } -bool cmQtAutoGenerator::FileSystem::FileWrite(GeneratorT genType, +bool cmQtAutoGenerator::FileSystem::FileWrite(GenT genType, std::string const& filename, std::string const& content) { @@ -387,7 +385,7 @@ bool cmQtAutoGenerator::FileSystem::MakeDirectory(std::string const& dirname) return cmSystemTools::MakeDirectory(dirname); } -bool cmQtAutoGenerator::FileSystem::MakeDirectory(GeneratorT genType, +bool cmQtAutoGenerator::FileSystem::MakeDirectory(GenT genType, std::string const& dirname) { if (!MakeDirectory(dirname)) { @@ -409,7 +407,7 @@ bool cmQtAutoGenerator::FileSystem::MakeParentDirectory( } bool cmQtAutoGenerator::FileSystem::MakeParentDirectory( - GeneratorT genType, std::string const& filename) + GenT genType, std::string const& filename) { if (!MakeParentDirectory(filename)) { Log()->ErrorFile(genType, filename, "Could not create parent directory"); @@ -447,7 +445,7 @@ void cmQtAutoGenerator::ReadOnlyProcessT::PipeT::UVAlloc(uv_handle_t* handle, { auto& pipe = *reinterpret_cast<PipeT*>(handle->data); pipe.Buffer_.resize(suggestedSize); - buf->base = &pipe.Buffer_.front(); + buf->base = pipe.Buffer_.data(); buf->len = pipe.Buffer_.size(); } @@ -555,11 +553,11 @@ bool cmQtAutoGenerator::ReadOnlyProcessT::start( std::fill_n(reinterpret_cast<char*>(&UVOptions_), sizeof(UVOptions_), 0); UVOptions_.exit_cb = &ReadOnlyProcessT::UVExit; UVOptions_.file = CommandPtr_[0]; - UVOptions_.args = const_cast<char**>(&CommandPtr_.front()); + UVOptions_.args = const_cast<char**>(CommandPtr_.data()); UVOptions_.cwd = Setup_.WorkingDirectory.c_str(); UVOptions_.flags = UV_PROCESS_WINDOWS_HIDE; UVOptions_.stdio_count = static_cast<int>(UVOptionsStdIO_.size()); - UVOptions_.stdio = &UVOptionsStdIO_.front(); + UVOptions_.stdio = UVOptionsStdIO_.data(); // -- Spawn process if (UVProcess_.spawn(*uv_loop, UVOptions_, this) != 0) { diff --git a/Source/cmQtAutoGenerator.h b/Source/cmQtAutoGenerator.h index 9956a99..6771dd8 100644 --- a/Source/cmQtAutoGenerator.h +++ b/Source/cmQtAutoGenerator.h @@ -40,16 +40,16 @@ public: bool ColorOutput() const { return this->ColorOutput_; } void SetColorOutput(bool value); // -- Log info - void Info(GeneratorT genType, std::string const& message); + void Info(GenT genType, std::string const& message); // -- Log warning - void Warning(GeneratorT genType, std::string const& message); - void WarningFile(GeneratorT genType, std::string const& filename, + void Warning(GenT genType, std::string const& message); + void WarningFile(GenT genType, std::string const& filename, std::string const& message); // -- Log error - void Error(GeneratorT genType, std::string const& message); - void ErrorFile(GeneratorT genType, std::string const& filename, + void Error(GenT genType, std::string const& message); + void ErrorFile(GenT genType, std::string const& filename, std::string const& message); - void ErrorCommand(GeneratorT genType, std::string const& message, + void ErrorCommand(GenT genType, std::string const& message, std::vector<std::string> const& command, std::string const& output); @@ -114,13 +114,13 @@ public: bool FileRead(std::string& content, std::string const& filename, std::string* error = nullptr); /// @brief Error logging version - bool FileRead(GeneratorT genType, std::string& content, + bool FileRead(GenT genType, std::string& content, std::string const& filename); bool FileWrite(std::string const& filename, std::string const& content, std::string* error = nullptr); /// @brief Error logging version - bool FileWrite(GeneratorT genType, std::string const& filename, + bool FileWrite(GenT genType, std::string const& filename, std::string const& content); bool FileDiffers(std::string const& filename, std::string const& content); @@ -131,11 +131,11 @@ public: // -- Directory access bool MakeDirectory(std::string const& dirname); /// @brief Error logging version - bool MakeDirectory(GeneratorT genType, std::string const& dirname); + bool MakeDirectory(GenT genType, std::string const& dirname); bool MakeParentDirectory(std::string const& filename); /// @brief Error logging version - bool MakeParentDirectory(GeneratorT genType, std::string const& filename); + bool MakeParentDirectory(GenT genType, std::string const& filename); private: std::mutex Mutex_; diff --git a/Source/cmQtAutoGeneratorMocUic.cxx b/Source/cmQtAutoGeneratorMocUic.cxx index ddff4cf..b02cd44 100644 --- a/Source/cmQtAutoGeneratorMocUic.cxx +++ b/Source/cmQtAutoGeneratorMocUic.cxx @@ -5,7 +5,6 @@ #include <algorithm> #include <array> #include <cstddef> -#include <functional> #include <list> #include <memory> #include <set> @@ -184,11 +183,10 @@ void cmQtAutoGeneratorMocUic::JobParseT::Process(WorkerT& wrk) ParseUic(wrk, meta); } } else { - wrk.LogFileWarning(GeneratorT::GEN, FileName, - "The source file is empty"); + wrk.LogFileWarning(GenT::GEN, FileName, "The source file is empty"); } } else { - wrk.LogFileError(GeneratorT::GEN, FileName, + wrk.LogFileError(GenT::GEN, FileName, "Could not read the file: " + error); } } @@ -275,7 +273,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, emsg += ", but the header "; emsg += Quoted(MocStringHeaders(wrk, mocInc.Base)); emsg += " could not be found."; - wrk.LogFileError(GeneratorT::MOC, FileName, emsg); + wrk.LogFileError(GenT::MOC, FileName, emsg); } return false; } @@ -314,7 +312,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, emsg += Quoted("moc_" + mocInc.Base + ".cpp"); emsg += " for a compatibility with strict mode.\n" "(CMAKE_AUTOMOC_RELAXED_MODE warning)\n"; - wrk.LogFileWarning(GeneratorT::MOC, FileName, emsg); + wrk.LogFileWarning(GenT::MOC, FileName, emsg); } else { std::string emsg = "The file includes the moc file "; emsg += Quoted(mocInc.Inc); @@ -326,7 +324,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, emsg += Quoted("moc_" + mocInc.Base + ".cpp"); emsg += " for compatibility with strict mode.\n" "(CMAKE_AUTOMOC_RELAXED_MODE warning)\n"; - wrk.LogFileWarning(GeneratorT::MOC, FileName, emsg); + wrk.LogFileWarning(GenT::MOC, FileName, emsg); } } } else { @@ -338,7 +336,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, "matching header "; emsg += Quoted(MocStringHeaders(wrk, mocInc.Base)); emsg += " could not be found."; - wrk.LogFileError(GeneratorT::MOC, FileName, emsg); + wrk.LogFileError(GenT::MOC, FileName, emsg); } return false; } @@ -356,7 +354,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, emsg += ", but does not contain a "; emsg += wrk.Moc().MacrosString(); emsg += " macro."; - wrk.LogFileWarning(GeneratorT::MOC, FileName, emsg); + wrk.LogFileWarning(GenT::MOC, FileName, emsg); } } else { // Don't allow <BASE>.moc include other than self in strict mode @@ -367,7 +365,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, "source file.\nThis is not supported. Include "; emsg += Quoted(meta.FileBase + ".moc"); emsg += " to run moc on this source file."; - wrk.LogFileError(GeneratorT::MOC, FileName, emsg); + wrk.LogFileError(GenT::MOC, FileName, emsg); } return false; } @@ -410,7 +408,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, emsg += Quoted(meta.FileBase + ".moc"); emsg += " for compatibility with strict mode.\n" "(CMAKE_AUTOMOC_RELAXED_MODE warning)"; - wrk.LogFileWarning(GeneratorT::MOC, FileName, emsg); + wrk.LogFileWarning(GenT::MOC, FileName, emsg); } // Add own source job jobs.emplace_back( @@ -425,7 +423,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, emsg += "!\nConsider to\n - add #include \""; emsg += meta.FileBase; emsg += ".moc\"\n - enable SKIP_AUTOMOC for this file"; - wrk.LogFileError(GeneratorT::MOC, FileName, emsg); + wrk.LogFileError(GenT::MOC, FileName, emsg); } return false; } @@ -433,8 +431,8 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk, // Convert pre jobs to actual jobs for (JobPre& jobPre : jobs) { - JobHandleT jobHandle(new JobMocT(std::move(jobPre.SourceFile), FileName, - std::move(jobPre.IncludeString))); + JobHandleT jobHandle = cm::make_unique<JobMocT>( + std::move(jobPre.SourceFile), FileName, std::move(jobPre.IncludeString)); if (jobPre.self) { // Read dependencies from this source static_cast<JobMocT&>(*jobHandle).FindDependencies(wrk, meta.Content); @@ -452,8 +450,8 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocHeader(WorkerT& wrk, bool success = true; std::string const macroName = wrk.Moc().FindMacro(meta.Content); if (!macroName.empty()) { - JobHandleT jobHandle( - new JobMocT(std::string(FileName), std::string(), std::string())); + JobHandleT jobHandle = cm::make_unique<JobMocT>( + std::string(FileName), std::string(), std::string()); // Read dependencies from this source static_cast<JobMocT&>(*jobHandle).FindDependencies(wrk, meta.Content); success = wrk.Gen().ParallelJobPushMoc(jobHandle); @@ -519,8 +517,8 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseUicInclude( std::string uiInputFile = UicFindIncludedFile(wrk, meta, includeString); if (!uiInputFile.empty()) { if (!wrk.Uic().skipped(uiInputFile)) { - JobHandleT jobHandle(new JobUicT(std::move(uiInputFile), FileName, - std::move(includeString))); + JobHandleT jobHandle = cm::make_unique<JobUicT>( + std::move(uiInputFile), FileName, std::move(includeString)); success = wrk.Gen().ParallelJobPushUic(jobHandle); } else { // A skipped file is successful @@ -586,7 +584,7 @@ std::string cmQtAutoGeneratorMocUic::JobParseT::UicFindIncludedFile( emsg += Quoted(testFile); emsg += "\n"; } - wrk.LogFileError(GeneratorT::UIC, FileName, emsg); + wrk.LogFileError(GenT::UIC, FileName, emsg); } return res; @@ -602,7 +600,7 @@ void cmQtAutoGeneratorMocUic::JobMocPredefsT::Process(WorkerT& wrk) std::string reason = "Generating "; reason += Quoted(wrk.Moc().PredefsFileRel); reason += " because it doesn't exist"; - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } generate = true; } else if (wrk.Moc().SettingsChanged) { @@ -610,7 +608,7 @@ void cmQtAutoGeneratorMocUic::JobMocPredefsT::Process(WorkerT& wrk) std::string reason = "Generating "; reason += Quoted(wrk.Moc().PredefsFileRel); reason += " because the settings changed."; - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } generate = true; } @@ -627,12 +625,12 @@ void cmQtAutoGeneratorMocUic::JobMocPredefsT::Process(WorkerT& wrk) cmd.push_back("-D" + def); } // Execute command - if (!wrk.RunProcess(GeneratorT::MOC, result, cmd)) { + if (!wrk.RunProcess(GenT::MOC, result, cmd)) { std::string emsg = "The content generation command for "; emsg += Quoted(wrk.Moc().PredefsFileRel); emsg += " failed.\n"; emsg += result.ErrorMessage; - wrk.LogCommandError(GeneratorT::MOC, emsg, cmd, result.StdOut); + wrk.LogCommandError(GenT::MOC, emsg, cmd, result.StdOut); } } @@ -640,14 +638,14 @@ void cmQtAutoGeneratorMocUic::JobMocPredefsT::Process(WorkerT& wrk) if (!result.error()) { if (!fileExists || wrk.FileSys().FileDiffers(wrk.Moc().PredefsFileAbs, result.StdOut)) { - if (wrk.FileSys().FileWrite(GeneratorT::MOC, wrk.Moc().PredefsFileAbs, + if (wrk.FileSys().FileWrite(GenT::MOC, wrk.Moc().PredefsFileAbs, result.StdOut)) { // Success } else { std::string emsg = "Writing "; emsg += Quoted(wrk.Moc().PredefsFileRel); emsg += " failed."; - wrk.LogFileError(GeneratorT::MOC, wrk.Moc().PredefsFileAbs, emsg); + wrk.LogFileError(GenT::MOC, wrk.Moc().PredefsFileAbs, emsg); } } else { // Touch to update the time stamp @@ -655,7 +653,7 @@ void cmQtAutoGeneratorMocUic::JobMocPredefsT::Process(WorkerT& wrk) std::string msg = "Touching "; msg += Quoted(wrk.Moc().PredefsFileRel); msg += "."; - wrk.LogInfo(GeneratorT::MOC, msg); + wrk.LogInfo(GenT::MOC, msg); } wrk.FileSys().Touch(wrk.Moc().PredefsFileAbs); } @@ -713,7 +711,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) reason += " from its source file "; reason += Quoted(SourceFile); reason += " because it doesn't exist"; - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } return true; } @@ -726,7 +724,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) reason += " from "; reason += Quoted(SourceFile); reason += " because the MOC settings changed"; - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } return true; } @@ -739,7 +737,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) isOlder = wrk.FileSys().FileIsOlderThan( BuildFile, wrk.Moc().PredefsFileAbs, &error); if (!isOlder && !error.empty()) { - wrk.LogError(GeneratorT::MOC, error); + wrk.LogError(GenT::MOC, error); return false; } } @@ -749,7 +747,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) reason += Quoted(BuildFile); reason += " because it's older than: "; reason += Quoted(wrk.Moc().PredefsFileAbs); - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } return true; } @@ -762,7 +760,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) std::string error; isOlder = wrk.FileSys().FileIsOlderThan(BuildFile, SourceFile, &error); if (!isOlder && !error.empty()) { - wrk.LogError(GeneratorT::MOC, error); + wrk.LogError(GenT::MOC, error); return false; } } @@ -772,7 +770,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) reason += Quoted(BuildFile); reason += " because it's older than its source file "; reason += Quoted(SourceFile); - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } return true; } @@ -794,7 +792,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) emsg += Quoted(IncluderFile); emsg += ".\n"; emsg += error; - wrk.LogError(GeneratorT::MOC, emsg); + wrk.LogError(GenT::MOC, emsg); return false; } } @@ -815,18 +813,18 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) reason += Quoted(SourceFile); reason += " because it is older than it's dependency file "; reason += Quoted(depFileAbs); - wrk.LogInfo(GeneratorT::MOC, reason); + wrk.LogInfo(GenT::MOC, reason); } return true; } if (!error.empty()) { - wrk.LogError(GeneratorT::MOC, error); + wrk.LogError(GenT::MOC, error); return false; } } else { std::string message = "Could not find dependency file "; message += Quoted(depFileRel); - wrk.LogFileWarning(GeneratorT::MOC, SourceFile, message); + wrk.LogFileWarning(GenT::MOC, SourceFile, message); } } } @@ -837,7 +835,7 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) void cmQtAutoGeneratorMocUic::JobMocT::GenerateMoc(WorkerT& wrk) { // Make sure the parent directory exists - if (wrk.FileSys().MakeParentDirectory(GeneratorT::MOC, BuildFile)) { + if (wrk.FileSys().MakeParentDirectory(GenT::MOC, BuildFile)) { // Compose moc command std::vector<std::string> cmd; cmd.push_back(wrk.Moc().Executable); @@ -855,11 +853,11 @@ void cmQtAutoGeneratorMocUic::JobMocT::GenerateMoc(WorkerT& wrk) // Execute moc command ProcessResultT result; - if (wrk.RunProcess(GeneratorT::MOC, result, cmd)) { + if (wrk.RunProcess(GenT::MOC, result, cmd)) { // Moc command success // Print moc output if (!result.StdOut.empty()) { - wrk.LogInfo(GeneratorT::MOC, result.StdOut); + wrk.LogInfo(GenT::MOC, result.StdOut); } // Notify the generator that a not included file changed (on demand) if (IncludeString.empty()) { @@ -874,7 +872,7 @@ void cmQtAutoGeneratorMocUic::JobMocT::GenerateMoc(WorkerT& wrk) emsg += Quoted(BuildFile); emsg += ".\n"; emsg += result.ErrorMessage; - wrk.LogCommandError(GeneratorT::MOC, emsg, cmd, result.StdOut); + wrk.LogCommandError(GenT::MOC, emsg, cmd, result.StdOut); } wrk.FileSys().FileRemove(BuildFile); } @@ -905,7 +903,7 @@ bool cmQtAutoGeneratorMocUic::JobUicT::UpdateRequired(WorkerT& wrk) reason += " from its source file "; reason += Quoted(SourceFile); reason += " because it doesn't exist"; - wrk.LogInfo(GeneratorT::UIC, reason); + wrk.LogInfo(GenT::UIC, reason); } return true; } @@ -918,7 +916,7 @@ bool cmQtAutoGeneratorMocUic::JobUicT::UpdateRequired(WorkerT& wrk) reason += " from "; reason += Quoted(SourceFile); reason += " because the UIC settings changed"; - wrk.LogInfo(GeneratorT::UIC, reason); + wrk.LogInfo(GenT::UIC, reason); } return true; } @@ -930,7 +928,7 @@ bool cmQtAutoGeneratorMocUic::JobUicT::UpdateRequired(WorkerT& wrk) std::string error; isOlder = wrk.FileSys().FileIsOlderThan(BuildFile, SourceFile, &error); if (!isOlder && !error.empty()) { - wrk.LogError(GeneratorT::UIC, error); + wrk.LogError(GenT::UIC, error); return false; } } @@ -940,7 +938,7 @@ bool cmQtAutoGeneratorMocUic::JobUicT::UpdateRequired(WorkerT& wrk) reason += Quoted(BuildFile); reason += " because it's older than its source file "; reason += Quoted(SourceFile); - wrk.LogInfo(GeneratorT::UIC, reason); + wrk.LogInfo(GenT::UIC, reason); } return true; } @@ -952,7 +950,7 @@ bool cmQtAutoGeneratorMocUic::JobUicT::UpdateRequired(WorkerT& wrk) void cmQtAutoGeneratorMocUic::JobUicT::GenerateUic(WorkerT& wrk) { // Make sure the parent directory exists - if (wrk.FileSys().MakeParentDirectory(GeneratorT::UIC, BuildFile)) { + if (wrk.FileSys().MakeParentDirectory(GenT::UIC, BuildFile)) { // Compose uic command std::vector<std::string> cmd; cmd.push_back(wrk.Uic().Executable); @@ -970,11 +968,11 @@ void cmQtAutoGeneratorMocUic::JobUicT::GenerateUic(WorkerT& wrk) cmd.push_back(SourceFile); ProcessResultT result; - if (wrk.RunProcess(GeneratorT::UIC, result, cmd)) { + if (wrk.RunProcess(GenT::UIC, result, cmd)) { // Uic command success // Print uic output if (!result.StdOut.empty()) { - wrk.LogInfo(GeneratorT::UIC, result.StdOut); + wrk.LogInfo(GenT::UIC, result.StdOut); } } else { // Uic command failed @@ -987,18 +985,13 @@ void cmQtAutoGeneratorMocUic::JobUicT::GenerateUic(WorkerT& wrk) emsg += Quoted(IncluderFile); emsg += ".\n"; emsg += result.ErrorMessage; - wrk.LogCommandError(GeneratorT::UIC, emsg, cmd, result.StdOut); + wrk.LogCommandError(GenT::UIC, emsg, cmd, result.StdOut); } wrk.FileSys().FileRemove(BuildFile); } } } -void cmQtAutoGeneratorMocUic::JobDeleterT::operator()(JobT* job) -{ - delete job; -} - cmQtAutoGeneratorMocUic::WorkerT::WorkerT(cmQtAutoGeneratorMocUic* gen, uv_loop_t* uvLoop) : Gen_(gen) @@ -1018,41 +1011,39 @@ cmQtAutoGeneratorMocUic::WorkerT::~WorkerT() } void cmQtAutoGeneratorMocUic::WorkerT::LogInfo( - GeneratorT genType, std::string const& message) const + GenT genType, std::string const& message) const { - return Log().Info(genType, message); + Log().Info(genType, message); } void cmQtAutoGeneratorMocUic::WorkerT::LogWarning( - GeneratorT genType, std::string const& message) const + GenT genType, std::string const& message) const { - return Log().Warning(genType, message); + Log().Warning(genType, message); } void cmQtAutoGeneratorMocUic::WorkerT::LogFileWarning( - GeneratorT genType, std::string const& filename, - std::string const& message) const + GenT genType, std::string const& filename, std::string const& message) const { - return Log().WarningFile(genType, filename, message); + Log().WarningFile(genType, filename, message); } void cmQtAutoGeneratorMocUic::WorkerT::LogError( - GeneratorT genType, std::string const& message) const + GenT genType, std::string const& message) const { Gen().ParallelRegisterJobError(); Log().Error(genType, message); } void cmQtAutoGeneratorMocUic::WorkerT::LogFileError( - GeneratorT genType, std::string const& filename, - std::string const& message) const + GenT genType, std::string const& filename, std::string const& message) const { Gen().ParallelRegisterJobError(); Log().ErrorFile(genType, filename, message); } void cmQtAutoGeneratorMocUic::WorkerT::LogCommandError( - GeneratorT genType, std::string const& message, + GenT genType, std::string const& message, std::vector<std::string> const& command, std::string const& output) const { Gen().ParallelRegisterJobError(); @@ -1060,7 +1051,7 @@ void cmQtAutoGeneratorMocUic::WorkerT::LogCommandError( } bool cmQtAutoGeneratorMocUic::WorkerT::RunProcess( - GeneratorT genType, ProcessResultT& result, + GenT genType, ProcessResultT& result, std::vector<std::string> const& command) { if (command.empty()) { @@ -1213,7 +1204,7 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) // -- Read info file if (!makefile->ReadListFile(InfoFile())) { - Log().ErrorFile(GeneratorT::GEN, InfoFile(), "File processing failed"); + Log().ErrorFile(GenT::GEN, InfoFile(), "File processing failed"); return false; } @@ -1238,14 +1229,13 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) InfoGetBool("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); Base_.AutogenBuildDir = InfoGet("AM_BUILD_DIR"); if (Base_.AutogenBuildDir.empty()) { - Log().ErrorFile(GeneratorT::GEN, InfoFile(), - "Autogen build directory missing"); + Log().ErrorFile(GenT::GEN, InfoFile(), "Autogen build directory missing"); return false; } // include directory Base_.AutogenIncludeDir = InfoGetConfig("AM_INCLUDE_DIR"); if (Base_.AutogenIncludeDir.empty()) { - Log().ErrorFile(GeneratorT::GEN, InfoFile(), + Log().ErrorFile(GenT::GEN, InfoFile(), "Autogen include directory missing"); return false; } @@ -1253,7 +1243,7 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) // - Files SettingsFile_ = InfoGetConfig("AM_SETTINGS_FILE"); if (SettingsFile_.empty()) { - Log().ErrorFile(GeneratorT::GEN, InfoFile(), "Settings file name missing"); + Log().ErrorFile(GenT::GEN, InfoFile(), "Settings file name missing"); return false; } @@ -1270,9 +1260,8 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) Moc_.Executable = InfoGet("AM_QT_MOC_EXECUTABLE"); Moc_.Enabled = !Moc().Executable.empty(); if (Moc().Enabled) { - { - auto lst = InfoGetList("AM_MOC_SKIP"); - Moc_.SkipList.insert(lst.begin(), lst.end()); + for (std::string& sfl : InfoGetList("AM_MOC_SKIP")) { + Moc_.SkipList.insert(std::move(sfl)); } Moc_.Definitions = InfoGetConfigList("AM_MOC_DEFINITIONS"); Moc_.IncludePaths = InfoGetConfigList("AM_MOC_INCLUDES"); @@ -1334,20 +1323,20 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) } } else { Log().ErrorFile( - GeneratorT::MOC, InfoFile(), + GenT::MOC, InfoFile(), "AUTOMOC_DEPEND_FILTERS list size is not a multiple of 2"); return false; } } if (!error.empty()) { - Log().ErrorFile(GeneratorT::MOC, InfoFile(), error); + Log().ErrorFile(GenT::MOC, InfoFile(), error); return false; } } Moc_.PredefsCmd = InfoGetList("AM_MOC_PREDEFS_CMD"); // Install moc predefs job if (!Moc().PredefsCmd.empty()) { - JobQueues_.MocPredefs.emplace_back(new JobMocPredefsT()); + JobQueues_.MocPredefs.emplace_back(cm::make_unique<JobMocPredefsT>()); } } @@ -1355,9 +1344,8 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) Uic_.Executable = InfoGet("AM_QT_UIC_EXECUTABLE"); Uic_.Enabled = !Uic().Executable.empty(); if (Uic().Enabled) { - { - auto lst = InfoGetList("AM_UIC_SKIP"); - Uic_.SkipList.insert(lst.begin(), lst.end()); + for (std::string& sfl : InfoGetList("AM_UIC_SKIP")) { + Uic_.SkipList.insert(std::move(sfl)); } Uic_.SearchPaths = InfoGetList("AM_UIC_SEARCH_PATHS"); Uic_.TargetOptions = InfoGetConfigList("AM_UIC_TARGET_OPTIONS"); @@ -1369,7 +1357,7 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) std::ostringstream ost; ost << "files/options lists sizes mismatch (" << sources.size() << "/" << options.size() << ")"; - Log().ErrorFile(GeneratorT::UIC, InfoFile(), ost.str()); + Log().ErrorFile(GenT::UIC, InfoFile(), ost.str()); return false; } auto fitEnd = sources.cend(); @@ -1383,53 +1371,44 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) } } - // Initialize source file jobs + // - Headers and sources { - std::hash<std::string> stringHash; - std::set<std::size_t> uniqueHeaders; - - // Add header jobs + auto addHeader = [this](std::string&& hdr, bool moc, bool uic) { + this->JobQueues_.Headers.emplace_back( + cm::make_unique<JobParseT>(std::move(hdr), moc, uic, true)); + }; + auto addSource = [this](std::string&& src, bool moc, bool uic) { + this->JobQueues_.Sources.emplace_back( + cm::make_unique<JobParseT>(std::move(src), moc, uic, false)); + }; + + // Add headers for (std::string& hdr : InfoGetList("AM_HEADERS")) { - const bool moc = !Moc().skipped(hdr); - const bool uic = !Uic().skipped(hdr); - if ((moc || uic) && uniqueHeaders.emplace(stringHash(hdr)).second) { - JobQueues_.Headers.emplace_back( - new JobParseT(std::move(hdr), moc, uic, true)); + addHeader(std::move(hdr), true, true); + } + if (Moc().Enabled) { + for (std::string& hdr : InfoGetList("AM_MOC_HEADERS")) { + addHeader(std::move(hdr), true, false); } } - // Add source jobs - { - std::vector<std::string> sources = InfoGetList("AM_SOURCES"); - // Add header(s) for the source file - for (std::string& src : sources) { - const bool srcMoc = !Moc().skipped(src); - const bool srcUic = !Uic().skipped(src); - if (!srcMoc && !srcUic) { - continue; - } - // Search for the default header file and a private header - { - std::array<std::string, 2> bases; - bases[0] = FileSys().SubDirPrefix(src); - bases[0] += FileSys().GetFilenameWithoutLastExtension(src); - bases[1] = bases[0]; - bases[1] += "_p"; - for (std::string const& headerBase : bases) { - std::string header; - if (Base().FindHeader(header, headerBase)) { - const bool moc = srcMoc && !Moc().skipped(header); - const bool uic = srcUic && !Uic().skipped(header); - if ((moc || uic) && - uniqueHeaders.emplace(stringHash(header)).second) { - JobQueues_.Headers.emplace_back( - new JobParseT(std::move(header), moc, uic, true)); - } - } - } - } - // Add source job - JobQueues_.Sources.emplace_back( - new JobParseT(std::move(src), srcMoc, srcUic)); + if (Uic().Enabled) { + for (std::string& hdr : InfoGetList("AM_UIC_HEADERS")) { + addHeader(std::move(hdr), false, true); + } + } + + // Add sources + for (std::string& src : InfoGetList("AM_SOURCES")) { + addSource(std::move(src), true, true); + } + if (Moc().Enabled) { + for (std::string& src : InfoGetList("AM_MOC_SOURCES")) { + addSource(std::move(src), true, false); + } + } + if (Uic().Enabled) { + for (std::string& src : InfoGetList("AM_UIC_SOURCES")) { + addSource(std::move(src), false, true); } } } @@ -1690,8 +1669,7 @@ void cmQtAutoGeneratorMocUic::SettingsFileWrite() // Only write if any setting changed if (!JobError_ && (Moc().SettingsChanged || Uic().SettingsChanged)) { if (Log().Verbose()) { - Log().Info(GeneratorT::GEN, - "Writing settings file " + Quoted(SettingsFile_)); + Log().Info(GenT::GEN, "Writing settings file " + Quoted(SettingsFile_)); } // Compose settings file content std::string content; @@ -1709,8 +1687,8 @@ void cmQtAutoGeneratorMocUic::SettingsFileWrite() SettingAppend("uic", SettingsStringUic_); } // Write settings file - if (!FileSys().FileWrite(GeneratorT::GEN, SettingsFile_, content)) { - Log().ErrorFile(GeneratorT::GEN, SettingsFile_, + if (!FileSys().FileWrite(GenT::GEN, SettingsFile_, content)) { + Log().ErrorFile(GenT::GEN, SettingsFile_, "Settings file writing failed"); // Remove old settings file to trigger a full rebuild on the next run FileSys().FileRemove(SettingsFile_); @@ -1722,7 +1700,7 @@ void cmQtAutoGeneratorMocUic::SettingsFileWrite() void cmQtAutoGeneratorMocUic::CreateDirectories() { // Create AUTOGEN include directory - if (!FileSys().MakeDirectory(GeneratorT::GEN, Base().AutogenIncludeDir)) { + if (!FileSys().MakeDirectory(GenT::GEN, Base().AutogenIncludeDir)) { RegisterJobError(); } } @@ -1802,7 +1780,7 @@ void cmQtAutoGeneratorMocUic::WorkerSwapJob(JobHandleT& jobHandle) { bool const jobProcessed(jobHandle); if (jobProcessed) { - jobHandle.reset(nullptr); + jobHandle.reset(); } { std::unique_lock<std::mutex> jobsLock(JobsMutex_); @@ -1882,7 +1860,7 @@ bool cmQtAutoGeneratorMocUic::ParallelJobPushMoc(JobHandleT& jobHandle) "- add a directory prefix to a \"<NAME>.moc\" include " "(e.g \"sub/<NAME>.moc\")\n" "- rename the source file(s)\n"; - Log().Error(GeneratorT::MOC, error); + Log().Error(GenT::MOC, error); RegisterJobError(); } // Do not push this job in since the included moc file already @@ -1932,7 +1910,7 @@ bool cmQtAutoGeneratorMocUic::ParallelJobPushUic(JobHandleT& jobHandle) "(e.g \"sub/ui_<NAME>.h\")\n" "- rename the <NAME>.ui file(s) and adjust the \"ui_<NAME>.h\" " "include(s)\n"; - Log().Error(GeneratorT::UIC, error); + Log().Error(GenT::UIC, error); RegisterJobError(); } // Do not push this job in since the uic file already @@ -2019,10 +1997,10 @@ void cmQtAutoGeneratorMocUic::MocGenerateCompilation() if (FileSys().FileDiffers(compAbs, content)) { // Actually write mocs compilation file if (Log().Verbose()) { - Log().Info(GeneratorT::MOC, "Generating MOC compilation " + compAbs); + Log().Info(GenT::MOC, "Generating MOC compilation " + compAbs); } - if (!FileSys().FileWrite(GeneratorT::MOC, compAbs, content)) { - Log().ErrorFile(GeneratorT::MOC, compAbs, + if (!FileSys().FileWrite(GenT::MOC, compAbs, content)) { + Log().ErrorFile(GenT::MOC, compAbs, "mocs compilation file writing failed"); RegisterJobError(); return; @@ -2030,7 +2008,7 @@ void cmQtAutoGeneratorMocUic::MocGenerateCompilation() } else if (MocAutoFileUpdated_) { // Only touch mocs compilation file if (Log().Verbose()) { - Log().Info(GeneratorT::MOC, "Touching mocs compilation " + compAbs); + Log().Info(GenT::MOC, "Touching mocs compilation " + compAbs); } FileSys().Touch(compAbs); } diff --git a/Source/cmQtAutoGeneratorMocUic.h b/Source/cmQtAutoGeneratorMocUic.h index c22df29..e48d7f3 100644 --- a/Source/cmQtAutoGeneratorMocUic.h +++ b/Source/cmQtAutoGeneratorMocUic.h @@ -20,6 +20,7 @@ #include <set> #include <string> #include <thread> +#include <unordered_set> #include <utility> #include <vector> @@ -133,7 +134,7 @@ public: std::string CompFileAbs; std::string PredefsFileRel; std::string PredefsFileAbs; - std::set<std::string> SkipList; + std::unordered_set<std::string> SkipList; std::vector<std::string> IncludePaths; std::vector<std::string> Includes; std::vector<std::string> Definitions; @@ -164,7 +165,7 @@ public: bool Enabled = false; bool SettingsChanged = false; std::string Executable; - std::set<std::string> SkipList; + std::unordered_set<std::string> SkipList; std::vector<std::string> TargetOptions; std::map<std::string, std::vector<std::string>> Options; std::vector<std::string> SearchPaths; @@ -186,15 +187,8 @@ public: virtual void Process(WorkerT& wrk) = 0; }; - /// @brief Deleter for classes derived from Job - /// - struct JobDeleterT - { - void operator()(JobT* job); - }; - // Job management types - typedef std::unique_ptr<JobT, JobDeleterT> JobHandleT; + typedef std::unique_ptr<JobT> JobHandleT; typedef std::deque<JobHandleT> JobQueueT; /// @brief Parse source job @@ -321,22 +315,22 @@ public: const UicSettingsT& Uic() const { return Gen_->Uic(); } // -- Log info - void LogInfo(GeneratorT genType, std::string const& message) const; + void LogInfo(GenT genType, std::string const& message) const; // -- Log warning - void LogWarning(GeneratorT genType, std::string const& message) const; - void LogFileWarning(GeneratorT genType, std::string const& filename, + void LogWarning(GenT genType, std::string const& message) const; + void LogFileWarning(GenT genType, std::string const& filename, std::string const& message) const; // -- Log error - void LogError(GeneratorT genType, std::string const& message) const; - void LogFileError(GeneratorT genType, std::string const& filename, + void LogError(GenT genType, std::string const& message) const; + void LogFileError(GenT genType, std::string const& filename, std::string const& message) const; - void LogCommandError(GeneratorT genType, std::string const& message, + void LogCommandError(GenT genType, std::string const& message, std::vector<std::string> const& command, std::string const& output) const; // -- External processes /// @brief Verbose logging version - bool RunProcess(GeneratorT genType, ProcessResultT& result, + bool RunProcess(GenT genType, ProcessResultT& result, std::vector<std::string> const& command); private: diff --git a/Source/cmQtAutoGeneratorRcc.cxx b/Source/cmQtAutoGeneratorRcc.cxx index 021a15f..5deb532 100644 --- a/Source/cmQtAutoGeneratorRcc.cxx +++ b/Source/cmQtAutoGeneratorRcc.cxx @@ -55,7 +55,7 @@ bool cmQtAutoGeneratorRcc::Init(cmMakefile* makefile) // -- Read info file if (!makefile->ReadListFile(InfoFile())) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "File processing failed"); + Log().ErrorFile(GenT::RCC, InfoFile(), "File processing failed"); return false; } @@ -66,13 +66,13 @@ bool cmQtAutoGeneratorRcc::Init(cmMakefile* makefile) // - Directories AutogenBuildDir_ = InfoGet("ARCC_BUILD_DIR"); if (AutogenBuildDir_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Build directory empty"); + Log().ErrorFile(GenT::RCC, InfoFile(), "Build directory empty"); return false; } IncludeDir_ = InfoGetConfig("ARCC_INCLUDE_DIR"); if (IncludeDir_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Include directory empty"); + Log().ErrorFile(GenT::RCC, InfoFile(), "Include directory empty"); return false; } @@ -95,28 +95,27 @@ bool cmQtAutoGeneratorRcc::Init(cmMakefile* makefile) // - Validity checks if (LockFile_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Lock file name missing"); + Log().ErrorFile(GenT::RCC, InfoFile(), "Lock file name missing"); return false; } if (SettingsFile_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Settings file name missing"); + Log().ErrorFile(GenT::RCC, InfoFile(), "Settings file name missing"); return false; } if (AutogenBuildDir_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), - "Autogen build directory missing"); + Log().ErrorFile(GenT::RCC, InfoFile(), "Autogen build directory missing"); return false; } if (RccExecutable_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "rcc executable missing"); + Log().ErrorFile(GenT::RCC, InfoFile(), "rcc executable missing"); return false; } if (QrcFile_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "rcc input file missing"); + Log().ErrorFile(GenT::RCC, InfoFile(), "rcc input file missing"); return false; } if (RccFileName_.empty()) { - Log().ErrorFile(GeneratorT::RCC, InfoFile(), "rcc output file missing"); + Log().ErrorFile(GenT::RCC, InfoFile(), "rcc output file missing"); return false; } @@ -287,8 +286,7 @@ bool cmQtAutoGeneratorRcc::SettingsFileRead() // Make sure the lock file exists if (!FileSys().FileExists(LockFile_, true)) { if (!FileSys().Touch(LockFile_, true)) { - Log().ErrorFile(GeneratorT::RCC, LockFile_, - "Lock file creation failed"); + Log().ErrorFile(GenT::RCC, LockFile_, "Lock file creation failed"); Error_ = true; return false; } @@ -297,7 +295,7 @@ bool cmQtAutoGeneratorRcc::SettingsFileRead() cmFileLockResult lockResult = LockFileLock_.Lock(LockFile_, static_cast<unsigned long>(-1)); if (!lockResult.IsOk()) { - Log().ErrorFile(GeneratorT::RCC, LockFile_, + Log().ErrorFile(GenT::RCC, LockFile_, "File lock failed: " + lockResult.GetOutputMessage()); Error_ = true; return false; @@ -313,7 +311,7 @@ bool cmQtAutoGeneratorRcc::SettingsFileRead() // This triggers a full rebuild on the next run if the current // build is aborted before writing the current settings in the end. if (SettingsChanged_) { - FileSys().FileWrite(GeneratorT::RCC, SettingsFile_, ""); + FileSys().FileWrite(GenT::RCC, SettingsFile_, ""); } } else { SettingsChanged_ = true; @@ -328,15 +326,14 @@ void cmQtAutoGeneratorRcc::SettingsFileWrite() // Only write if any setting changed if (SettingsChanged_) { if (Log().Verbose()) { - Log().Info(GeneratorT::RCC, - "Writing settings file " + Quoted(SettingsFile_)); + Log().Info(GenT::RCC, "Writing settings file " + Quoted(SettingsFile_)); } // Write settings file std::string content = "rcc:"; content += SettingsString_; content += '\n'; - if (!FileSys().FileWrite(GeneratorT::RCC, SettingsFile_, content)) { - Log().ErrorFile(GeneratorT::RCC, SettingsFile_, + if (!FileSys().FileWrite(GenT::RCC, SettingsFile_, content)) { + Log().ErrorFile(GenT::RCC, SettingsFile_, "Settings file writing failed"); // Remove old settings file to trigger a full rebuild on the next run FileSys().FileRemove(SettingsFile_); @@ -360,7 +357,7 @@ bool cmQtAutoGeneratorRcc::TestQrcRccFiles() reason += " from its source file "; reason += Quoted(QrcFile_); reason += " because it doesn't exist"; - Log().Info(GeneratorT::RCC, reason); + Log().Info(GenT::RCC, reason); } Generate_ = true; return Generate_; @@ -374,7 +371,7 @@ bool cmQtAutoGeneratorRcc::TestQrcRccFiles() reason += " from "; reason += Quoted(QrcFile_); reason += " because the RCC settings changed"; - Log().Info(GeneratorT::RCC, reason); + Log().Info(GenT::RCC, reason); } Generate_ = true; return Generate_; @@ -387,7 +384,7 @@ bool cmQtAutoGeneratorRcc::TestQrcRccFiles() std::string error; isOlder = FileSys().FileIsOlderThan(RccFileOutput_, QrcFile_, &error); if (!error.empty()) { - Log().ErrorFile(GeneratorT::RCC, QrcFile_, error); + Log().ErrorFile(GenT::RCC, QrcFile_, error); Error_ = true; } } @@ -397,7 +394,7 @@ bool cmQtAutoGeneratorRcc::TestQrcRccFiles() reason += Quoted(RccFileOutput_); reason += " because it is older than "; reason += Quoted(QrcFile_); - Log().Info(GeneratorT::RCC, reason); + Log().Info(GenT::RCC, reason); } Generate_ = true; } @@ -424,12 +421,11 @@ bool cmQtAutoGeneratorRcc::TestResourcesRead() std::string parseError; if (!RccListParseOutput(ProcessResult_.StdOut, ProcessResult_.StdErr, Inputs_, parseError)) { - Log().ErrorFile(GeneratorT::RCC, QrcFile_, parseError); + Log().ErrorFile(GenT::RCC, QrcFile_, parseError); Error_ = true; } } else { - Log().ErrorFile(GeneratorT::RCC, QrcFile_, - ProcessResult_.ErrorMessage); + Log().ErrorFile(GenT::RCC, QrcFile_, ProcessResult_.ErrorMessage); Error_ = true; } // Clean up @@ -457,7 +453,7 @@ bool cmQtAutoGeneratorRcc::TestResourcesRead() // rcc does not support the --list command. // Read the qrc file content and parse it. std::string qrcContent; - if (FileSys().FileRead(GeneratorT::RCC, qrcContent, QrcFile_)) { + if (FileSys().FileRead(GenT::RCC, qrcContent, QrcFile_)) { RccListParseContent(qrcContent, Inputs_); } } @@ -483,7 +479,7 @@ bool cmQtAutoGeneratorRcc::TestResources() error = "Could not find the resource file\n "; error += Quoted(resFile); error += '\n'; - Log().ErrorFile(GeneratorT::RCC, QrcFile_, error); + Log().ErrorFile(GenT::RCC, QrcFile_, error); Error_ = true; break; } @@ -496,14 +492,14 @@ bool cmQtAutoGeneratorRcc::TestResources() reason += Quoted(QrcFile_); reason += " because it is older than "; reason += Quoted(resFile); - Log().Info(GeneratorT::RCC, reason); + Log().Info(GenT::RCC, reason); } Generate_ = true; break; } // Print error and break on demand if (!error.empty()) { - Log().ErrorFile(GeneratorT::RCC, QrcFile_, error); + Log().ErrorFile(GenT::RCC, QrcFile_, error); Error_ = true; break; } @@ -522,7 +518,7 @@ void cmQtAutoGeneratorRcc::TestInfoFile() std::string error; isOlder = FileSys().FileIsOlderThan(RccFileOutput_, InfoFile(), &error); if (!error.empty()) { - Log().ErrorFile(GeneratorT::RCC, QrcFile_, error); + Log().ErrorFile(GenT::RCC, QrcFile_, error); Error_ = true; } } @@ -532,7 +528,7 @@ void cmQtAutoGeneratorRcc::TestInfoFile() reason += Quoted(RccFileOutput_); reason += " because it is older than "; reason += Quoted(InfoFile()); - Log().Info(GeneratorT::RCC, reason); + Log().Info(GenT::RCC, reason); } // Touch build file FileSys().Touch(RccFileOutput_); @@ -544,7 +540,7 @@ void cmQtAutoGeneratorRcc::TestInfoFile() void cmQtAutoGeneratorRcc::GenerateParentDir() { // Make sure the parent directory exists - if (!FileSys().MakeParentDirectory(GeneratorT::RCC, RccFileOutput_)) { + if (!FileSys().MakeParentDirectory(GenT::RCC, RccFileOutput_)) { Error_ = true; } } @@ -567,7 +563,7 @@ bool cmQtAutoGeneratorRcc::GenerateRcc() // Rcc process success // Print rcc output if (!ProcessResult_.StdOut.empty()) { - Log().Info(GeneratorT::RCC, ProcessResult_.StdOut); + Log().Info(GenT::RCC, ProcessResult_.StdOut); } BuildFileChanged_ = true; } else { @@ -581,7 +577,7 @@ bool cmQtAutoGeneratorRcc::GenerateRcc() emsg += "\n"; emsg += ProcessResult_.ErrorMessage; } - Log().ErrorCommand(GeneratorT::RCC, emsg, Process_->Setup().Command, + Log().ErrorCommand(GenT::RCC, emsg, Process_->Setup().Command, ProcessResult_.StdOut); } FileSys().FileRemove(RccFileOutput_); @@ -625,19 +621,17 @@ void cmQtAutoGeneratorRcc::GenerateWrapper() if (FileSys().FileDiffers(RccFilePublic_, content)) { // Write new wrapper file if (Log().Verbose()) { - Log().Info(GeneratorT::RCC, - "Generating RCC wrapper file " + RccFilePublic_); + Log().Info(GenT::RCC, "Generating RCC wrapper file " + RccFilePublic_); } - if (!FileSys().FileWrite(GeneratorT::RCC, RccFilePublic_, content)) { - Log().ErrorFile(GeneratorT::RCC, RccFilePublic_, + if (!FileSys().FileWrite(GenT::RCC, RccFilePublic_, content)) { + Log().ErrorFile(GenT::RCC, RccFilePublic_, "RCC wrapper file writing failed"); Error_ = true; } } else if (BuildFileChanged_) { // Just touch the wrapper file if (Log().Verbose()) { - Log().Info(GeneratorT::RCC, - "Touching RCC wrapper file " + RccFilePublic_); + Log().Info(GenT::RCC, "Touching RCC wrapper file " + RccFilePublic_); } FileSys().Touch(RccFilePublic_); } @@ -653,7 +647,7 @@ bool cmQtAutoGeneratorRcc::StartProcess( std::string msg = "Running command:\n"; msg += QuotedCommand(command); msg += '\n'; - Log().Info(GeneratorT::RCC, msg); + Log().Info(GenT::RCC, msg); } // Create process handler @@ -661,7 +655,7 @@ bool cmQtAutoGeneratorRcc::StartProcess( Process_->setup(&ProcessResult_, mergedOutput, command, workingDirectory); // Start process if (!Process_->start(UVLoop(), [this] { UVRequest().send(); })) { - Log().ErrorFile(GeneratorT::RCC, QrcFile_, ProcessResult_.ErrorMessage); + Log().ErrorFile(GenT::RCC, QrcFile_, ProcessResult_.ErrorMessage); Error_ = true; // Clean up Process_.reset(); diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index 55204d7..5917e27 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -3,6 +3,7 @@ #include "cmRST.h" #include "cmAlgorithms.h" +#include "cmRange.h" #include "cmSystemTools.h" #include "cmVersion.h" diff --git a/Source/cmRange.h b/Source/cmRange.h new file mode 100644 index 0000000..3be5193 --- /dev/null +++ b/Source/cmRange.h @@ -0,0 +1,239 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmRange_h +#define cmRange_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <algorithm> +#include <functional> +#include <iterator> + +namespace RangeIterators { + +template <typename Iter, typename UnaryPredicate> +class FilterIterator +{ +public: + using iterator_category = std::bidirectional_iterator_tag; + using value_type = typename std::iterator_traits<Iter>::value_type; + using difference_type = typename std::iterator_traits<Iter>::difference_type; + using pointer = typename std::iterator_traits<Iter>::pointer; + using reference = typename std::iterator_traits<Iter>::reference; + + FilterIterator(Iter b, Iter e, UnaryPredicate p) + : Cur(std::move(b)) + , End(std::move(e)) + , Pred(std::move(p)) + { + this->SatisfyPredicate(); + } + + FilterIterator& operator++() + { + ++this->Cur; + this->SatisfyPredicate(); + return *this; + } + + FilterIterator& operator--() + { + do { + --this->Cur; + } while (!this->Pred(*this->Cur)); + return *this; + } + + bool operator==(FilterIterator const& other) const + { + return this->Cur == other.Cur; + } + + bool operator!=(FilterIterator const& other) const + { + return !this->operator==(other); + } + + auto operator*() const -> decltype(*std::declval<Iter>()) + { + return *this->Cur; + } + +private: + void SatisfyPredicate() + { + while (this->Cur != this->End && !this->Pred(*this->Cur)) { + ++this->Cur; + } + } + + Iter Cur; + Iter End; + UnaryPredicate Pred; +}; + +template <typename Iter, typename UnaryFunction> +class TransformIterator +{ +public: + using iterator_category = std::bidirectional_iterator_tag; + using value_type = + typename std::remove_cv<typename std::remove_reference<decltype( + std::declval<UnaryFunction>()(*std::declval<Iter>()))>::type>::type; + using difference_type = typename std::iterator_traits<Iter>::difference_type; + using pointer = value_type const*; + using reference = value_type const&; + + TransformIterator(Iter i, UnaryFunction f) + : Base(std::move(i)) + , Func(std::move(f)) + { + } + + TransformIterator& operator++() + { + ++this->Base; + return *this; + } + + TransformIterator& operator--() + { + --this->Base; + return *this; + } + + bool operator==(TransformIterator const& other) const + { + return this->Base == other.Base; + } + + bool operator!=(TransformIterator const& other) const + { + return !this->operator==(other); + } + + auto operator*() const + -> decltype(std::declval<UnaryFunction>()(*std::declval<Iter>())) + { + return this->Func(*this->Base); + } + +private: + Iter Base; + UnaryFunction Func; +}; + +} // namespace RangeIterators + +template <typename Iter> +class cmRange +{ +public: + using const_iterator = Iter; + using value_type = typename std::iterator_traits<Iter>::value_type; + using difference_type = typename std::iterator_traits<Iter>::difference_type; + + cmRange(Iter b, Iter e) + : Begin(std::move(b)) + , End(std::move(e)) + { + } + + Iter begin() const { return this->Begin; } + Iter end() const { return this->End; } + bool empty() const { return this->Begin == this->End; } + + difference_type size() const + { + return std::distance(this->Begin, this->End); + } + + cmRange& advance(difference_type amount) & + { + std::advance(this->Begin, amount); + return *this; + } + + cmRange advance(difference_type amount) && + { + std::advance(this->Begin, amount); + return std::move(*this); + } + + cmRange& retreat(difference_type amount) & + { + std::advance(this->End, -amount); + return *this; + } + + cmRange retreat(difference_type amount) && + { + std::advance(this->End, -amount); + return std::move(*this); + } + + template <typename UnaryPredicate> + bool all_of(UnaryPredicate p) const + { + return std::all_of(this->Begin, this->End, std::ref(p)); + } + + template <typename UnaryPredicate> + bool any_of(UnaryPredicate p) const + { + return std::any_of(this->Begin, this->End, std::ref(p)); + } + + template <typename UnaryPredicate> + bool none_of(UnaryPredicate p) const + { + return std::none_of(this->Begin, this->End, std::ref(p)); + } + + template <typename UnaryPredicate> + auto filter(UnaryPredicate p) const + -> cmRange<RangeIterators::FilterIterator<Iter, UnaryPredicate>> + { + using It = RangeIterators::FilterIterator<Iter, UnaryPredicate>; + return { It(this->Begin, this->End, p), It(this->End, this->End, p) }; + } + + template <typename UnaryFunction> + auto transform(UnaryFunction f) const + -> cmRange<RangeIterators::TransformIterator<Iter, UnaryFunction>> + { + using It = RangeIterators::TransformIterator<Iter, UnaryFunction>; + return { It(this->Begin, f), It(this->End, f) }; + } + +private: + Iter Begin; + Iter End; +}; + +template <typename Iter1, typename Iter2> +bool operator==(cmRange<Iter1> const& left, cmRange<Iter2> const& right) +{ + return left.size() == right.size() && + std::equal(left.begin(), left.end(), right.begin()); +} + +template <typename Iter1, typename Iter2> +auto cmMakeRange(Iter1 begin, Iter2 end) -> cmRange<Iter1> +{ + return { begin, end }; +} + +template <typename Range> +auto cmMakeRange(Range const& range) -> cmRange<decltype(range.begin())> +{ + return { range.begin(), range.end() }; +} + +template <typename Range> +auto cmReverseRange(Range const& range) -> cmRange<decltype(range.rbegin())> +{ + return { range.rbegin(), range.rend() }; +} + +#endif diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx index e347a2c..309ee30 100644 --- a/Source/cmRulePlaceholderExpander.cxx +++ b/Source/cmRulePlaceholderExpander.cxx @@ -172,6 +172,36 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable( return replaceValues.SwiftModuleName; } } + if (replaceValues.SwiftLibraryName) { + if (variable == "SWIFT_LIBRARY_NAME") { + return replaceValues.SwiftLibraryName; + } + } + if (replaceValues.SwiftPartialDoc) { + if (variable == "SWIFT_PARTIAL_DOC") { + return replaceValues.SwiftPartialDoc; + } + } + if (replaceValues.SwiftPartialModule) { + if (variable == "SWIFT_PARTIAL_MODULE") { + return replaceValues.SwiftPartialModule; + } + } + if (replaceValues.SwiftPartialModules) { + if (variable == "SWIFT_PARTIAL_MODULES") { + return replaceValues.SwiftPartialModules; + } + } + if (replaceValues.TargetSwiftDoc) { + if (variable == "TARGET_SWIFT_DOC") { + return replaceValues.TargetSwiftDoc; + } + } + if (replaceValues.TargetSwiftModule) { + if (variable == "TARGET_SWIFT_MODULE") { + return replaceValues.TargetSwiftModule; + } + } if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" || variable == "TARGET_INSTALLNAME_DIR") { // All these variables depend on TargetSOName diff --git a/Source/cmRulePlaceholderExpander.h b/Source/cmRulePlaceholderExpander.h index 5c03637..ebd4d41 100644 --- a/Source/cmRulePlaceholderExpander.h +++ b/Source/cmRulePlaceholderExpander.h @@ -60,6 +60,12 @@ public: const char* FilterPrefix; const char* SwiftAuxiliarySources; const char* SwiftModuleName; + const char* SwiftLibraryName; + const char* SwiftPartialModule; + const char* SwiftPartialDoc; + const char* TargetSwiftModule; + const char* TargetSwiftDoc; + const char* SwiftPartialModules; }; // Expand rule variables in CMake of the type found in language rules diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx index 0f51e0e..f98984e 100644 --- a/Source/cmSearchPath.cxx +++ b/Source/cmSearchPath.cxx @@ -144,7 +144,7 @@ void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes) // this will get incorrectly considered a network // path on windows and cause huge delays. std::string p = inPath; - if (!p.empty() && *p.rbegin() != '/') { + if (!p.empty() && p.back() != '/') { p += "/"; } @@ -176,7 +176,7 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths, for (std::string const& path : paths) { std::string dir = path; - if (!subdir.empty() && !dir.empty() && *dir.rbegin() != '/') { + if (!subdir.empty() && !dir.empty() && dir.back() != '/') { dir += "/"; } if (subdir == "include" || subdir == "lib") { diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index e740c05..1903fd9 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -97,13 +97,13 @@ void cmServer::ProcessRequest(cmConnection* connection, } cmSystemTools::SetMessageCallback( - [&request](const char* msg, const char* title) { + [&request](const std::string& msg, const char* title) { reportMessage(msg, title, request); }); if (this->Protocol) { this->Protocol->CMakeInstance()->SetProgressCallback( - [&request](const char* msg, float prog) { + [&request](const std::string& msg, float prog) { reportProgress(msg, prog, request); }); this->WriteResponse(connection, this->Protocol->Process(request), @@ -155,7 +155,7 @@ void cmServer::PrintHello(cmConnection* connection) const this->WriteJsonObject(connection, hello, nullptr); } -void cmServer::reportProgress(const char* msg, float progress, +void cmServer::reportProgress(const std::string& msg, float progress, const cmServerRequest& request) { if (progress < 0.0f || progress > 1.0f) { @@ -165,15 +165,14 @@ void cmServer::reportProgress(const char* msg, float progress, } } -void cmServer::reportMessage(const char* msg, const char* title, +void cmServer::reportMessage(const std::string& msg, const char* title, const cmServerRequest& request) { - assert(msg); std::string titleString; if (title) { titleString = title; } - request.ReportMessage(std::string(msg), titleString); + request.ReportMessage(msg, titleString); } cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) diff --git a/Source/cmServer.h b/Source/cmServer.h index e1ed27a..aba4924 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -119,9 +119,9 @@ public: void OnConnected(cmConnection* connection) override; private: - static void reportProgress(const char* msg, float progress, + static void reportProgress(const std::string& msg, float progress, const cmServerRequest& request); - static void reportMessage(const char* msg, const char* title, + static void reportMessage(const std::string& msg, const char* title, const cmServerRequest& request); // Handle requests: diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx index 844a858..a878890 100644 --- a/Source/cmServerConnection.cxx +++ b/Source/cmServerConnection.cxx @@ -29,7 +29,7 @@ cm::uv_stream_ptr cmStdIoConnection::SetupStream(int file_id) tty.init(*this->Server->GetLoop(), file_id, file_id == 0, static_cast<cmEventBasedConnection*>(this)); uv_tty_set_mode(tty, UV_TTY_MODE_NORMAL); - return std::move(tty); + return { std::move(tty) }; } case UV_FILE: if (file_id == 0) { @@ -43,7 +43,7 @@ cm::uv_stream_ptr cmStdIoConnection::SetupStream(int file_id) pipe.init(*this->Server->GetLoop(), 0, static_cast<cmEventBasedConnection*>(this)); uv_pipe_open(pipe, file_id); - return std::move(pipe); + return { std::move(pipe) }; } default: assert(false && "Unable to determine stream type"); diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index 6bd071c..41555e8 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -5,6 +5,7 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmRange.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index 3c4111b..0d8f1cc 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -8,6 +8,7 @@ #include "cmInstalledFile.h" #include "cmMakefile.h" #include "cmProperty.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmSystemTools.h" @@ -33,25 +34,25 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args, } // Get the scope on which to set the property. - std::vector<std::string>::const_iterator arg = args.begin(); + std::string const& scopeName = args.front(); cmProperty::ScopeType scope; - if (*arg == "GLOBAL") { + if (scopeName == "GLOBAL") { scope = cmProperty::GLOBAL; - } else if (*arg == "DIRECTORY") { + } else if (scopeName == "DIRECTORY") { scope = cmProperty::DIRECTORY; - } else if (*arg == "TARGET") { + } else if (scopeName == "TARGET") { scope = cmProperty::TARGET; - } else if (*arg == "SOURCE") { + } else if (scopeName == "SOURCE") { scope = cmProperty::SOURCE_FILE; - } else if (*arg == "TEST") { + } else if (scopeName == "TEST") { scope = cmProperty::TEST; - } else if (*arg == "CACHE") { + } else if (scopeName == "CACHE") { scope = cmProperty::CACHE; - } else if (*arg == "INSTALL") { + } else if (scopeName == "INSTALL") { scope = cmProperty::INSTALL; } else { std::ostringstream e; - e << "given invalid scope " << *arg << ". " + e << "given invalid scope " << scopeName << ". " << "Valid scopes are GLOBAL, DIRECTORY, " "TARGET, SOURCE, TEST, CACHE, INSTALL."; this->SetError(e.str()); @@ -68,32 +69,32 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args, }; Doing doing = DoingNames; const char* sep = ""; - for (++arg; arg != args.end(); ++arg) { - if (*arg == "PROPERTY") { + for (std::string const& arg : cmMakeRange(args).advance(1)) { + if (arg == "PROPERTY") { doing = DoingProperty; - } else if (*arg == "APPEND") { + } else if (arg == "APPEND") { doing = DoingNone; this->AppendMode = true; this->Remove = false; this->AppendAsString = false; - } else if (*arg == "APPEND_STRING") { + } else if (arg == "APPEND_STRING") { doing = DoingNone; this->AppendMode = true; this->Remove = false; this->AppendAsString = true; } else if (doing == DoingNames) { - this->Names.insert(*arg); + this->Names.insert(arg); } else if (doing == DoingProperty) { - this->PropertyName = *arg; + this->PropertyName = arg; doing = DoingValues; } else if (doing == DoingValues) { this->PropertyValue += sep; sep = ";"; - this->PropertyValue += *arg; + this->PropertyValue += arg; this->Remove = false; } else { std::ostringstream e; - e << "given invalid argument \"" << *arg << "\"."; + e << "given invalid argument \"" << arg << "\"."; this->SetError(e.str()); return false; } diff --git a/Source/cmSiteNameCommand.cxx b/Source/cmSiteNameCommand.cxx index 01758ee..9f041bc 100644 --- a/Source/cmSiteNameCommand.cxx +++ b/Source/cmSiteNameCommand.cxx @@ -52,9 +52,8 @@ bool cmSiteNameCommand::InitialPass(std::vector<std::string> const& args, // try to find the hostname for this computer if (!cmSystemTools::IsOff(hostname_cmd)) { std::string host; - cmSystemTools::RunSingleCommand(hostname_cmd.c_str(), &host, nullptr, - nullptr, nullptr, - cmSystemTools::OUTPUT_NONE); + cmSystemTools::RunSingleCommand(hostname_cmd, &host, nullptr, nullptr, + nullptr, cmSystemTools::OUTPUT_NONE); // got the hostname if (!host.empty()) { diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index a82a58a..d579018 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -34,6 +34,9 @@ public: ~cmSourceFile(); + cmSourceFile(const cmSourceFile&) = delete; + cmSourceFile& operator=(const cmSourceFile&) = delete; + /** * Get the list of the custom commands for this source file */ diff --git a/Source/cmState.h b/Source/cmState.h index f755f83..190eafc 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -35,6 +35,9 @@ public: cmState(); ~cmState(); + cmState(const cmState&) = delete; + cmState& operator=(const cmState&) = delete; + enum Mode { Unknown, diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 6752743..31273cc 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -8,8 +8,10 @@ #include <iterator> #include <utility> +#include "cmAlgorithms.h" #include "cmProperty.h" #include "cmPropertyMap.h" +#include "cmRange.h" #include "cmState.h" #include "cmStatePrivate.h" #include "cmStateTypes.h" @@ -40,9 +42,8 @@ void cmStateDirectory::ComputeRelativePathTopSource() std::string result = snapshots.front().GetDirectory().GetCurrentSource(); - for (std::vector<cmStateSnapshot>::const_iterator it = snapshots.begin() + 1; - it != snapshots.end(); ++it) { - std::string currentSource = it->GetDirectory().GetCurrentSource(); + for (cmStateSnapshot const& snp : cmMakeRange(snapshots).advance(1)) { + std::string currentSource = snp.GetDirectory().GetCurrentSource(); if (cmSystemTools::IsSubDirectory(result, currentSource)) { result = currentSource; } @@ -66,9 +67,8 @@ void cmStateDirectory::ComputeRelativePathTopBinary() std::string result = snapshots.front().GetDirectory().GetCurrentBinary(); - for (std::vector<cmStateSnapshot>::const_iterator it = snapshots.begin() + 1; - it != snapshots.end(); ++it) { - std::string currentBinary = it->GetDirectory().GetCurrentBinary(); + for (cmStateSnapshot const& snp : cmMakeRange(snapshots).advance(1)) { + std::string currentBinary = snp.GetDirectory().GetCurrentBinary(); if (cmSystemTools::IsSubDirectory(result, currentBinary)) { result = currentBinary; } diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 91d6190..252d985 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -13,6 +13,7 @@ #include "cmCryptoHash.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmStringReplaceHelper.h" #include "cmSystemTools.h" #include "cmTimestamp.h" @@ -771,7 +772,7 @@ bool cmStringCommand::HandleRandomCommand(std::vector<std::string> const& args) } result.push_back(0); - this->Makefile->AddDefinition(variableName, &*result.begin()); + this->Makefile->AddDefinition(variableName, result.data()); return true; } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1d20e2f..d762106 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -5,6 +5,7 @@ #include "cmAlgorithms.h" #include "cmDuration.h" #include "cmProcessOutput.h" +#include "cmRange.h" #include "cm_sys_stat.h" #include "cm_uv.h" @@ -323,16 +324,16 @@ void cmSystemTools::Stdout(const std::string& s) } } -void cmSystemTools::Message(const char* m1, const char* title) +void cmSystemTools::Message(const std::string& m, const char* title) { if (s_DisableMessages) { return; } if (s_MessageCallback) { - s_MessageCallback(m1, title); + s_MessageCallback(m, title); return; } - std::cerr << m1 << std::endl << std::flush; + std::cerr << m << std::endl << std::flush; } void cmSystemTools::ReportLastSystemError(const char* msg) @@ -521,6 +522,8 @@ public: } free(this->ArgV); } + cmSystemToolsArgV(const cmSystemToolsArgV&) = delete; + cmSystemToolsArgV& operator=(const cmSystemToolsArgV&) = delete; void Store(std::vector<std::string>& args) const { for (char** arg = this->ArgV; arg && *arg; ++arg) { @@ -533,7 +536,7 @@ void cmSystemTools::ParseUnixCommandLine(const char* command, std::vector<std::string>& args) { // Invoke the underlying parser. - cmSystemToolsArgV argv = cmsysSystem_Parse_CommandForUnix(command, 0); + cmSystemToolsArgV argv(cmsysSystem_Parse_CommandForUnix(command, 0)); argv.Store(args); } @@ -542,8 +545,7 @@ std::vector<std::string> cmSystemTools::HandleResponseFile( std::vector<std::string>::const_iterator argEnd) { std::vector<std::string> arg_full; - for (std::vector<std::string>::const_iterator a = argBeg; a != argEnd; ++a) { - std::string const& arg = *a; + for (std::string const& arg : cmMakeRange(argBeg, argEnd)) { if (cmHasLiteralPrefix(arg, "@")) { cmsys::ifstream responseFile(arg.substr(1).c_str(), std::ios::in); if (!responseFile) { @@ -570,13 +572,14 @@ std::vector<std::string> cmSystemTools::HandleResponseFile( return arg_full; } -std::vector<std::string> cmSystemTools::ParseArguments(const char* command) +std::vector<std::string> cmSystemTools::ParseArguments(const std::string& cmd) { std::vector<std::string> args; std::string arg; bool win_path = false; + const char* command = cmd.c_str(); if (command[0] && command[1] && ((command[0] != '/' && command[1] == ':' && command[2] == '\\') || (command[0] == '\"' && command[1] != '/' && command[2] == ':' && @@ -740,7 +743,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, argv.push_back(nullptr); cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); + cmsysProcess_SetCommand(cp, argv.data()); cmsysProcess_SetWorkingDirectory(cp, dir); if (cmSystemTools::GetRunCommandHideConsole()) { cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); @@ -867,7 +870,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, return result; } -bool cmSystemTools::RunSingleCommand(const char* command, +bool cmSystemTools::RunSingleCommand(const std::string& command, std::string* captureStdOut, std::string* captureStdErr, int* retVal, const char* dir, OutputOption outputflag, @@ -897,7 +900,7 @@ std::string cmSystemTools::PrintSingleCommand( } bool cmSystemTools::DoesFileExistWithExtensions( - const char* name, const std::vector<std::string>& headerExts) + const std::string& name, const std::vector<std::string>& headerExts) { std::string hname; @@ -912,9 +915,9 @@ bool cmSystemTools::DoesFileExistWithExtensions( return false; } -std::string cmSystemTools::FileExistsInParentDirectories(const char* fname, - const char* directory, - const char* toplevel) +std::string cmSystemTools::FileExistsInParentDirectories( + const std::string& fname, const std::string& directory, + const std::string& toplevel) { std::string file = fname; cmSystemTools::ConvertToUnixSlashes(file); @@ -926,7 +929,7 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname, if (cmSystemTools::FileExists(path)) { return path; } - if (dir.size() < strlen(toplevel)) { + if (dir.size() < toplevel.size()) { break; } prevDir = dir; @@ -935,12 +938,6 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname, return ""; } -bool cmSystemTools::cmCopyFile(const std::string& source, - const std::string& destination) -{ - return Superclass::CopyFileAlways(source, destination); -} - #ifdef _WIN32 cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry() { @@ -1219,9 +1216,8 @@ void cmSystemTools::GlobDirs(const std::string& path, void cmSystemTools::ExpandList(std::vector<std::string> const& arguments, std::vector<std::string>& newargs) { - std::vector<std::string>::const_iterator i; - for (i = arguments.begin(); i != arguments.end(); ++i) { - cmSystemTools::ExpandListArgument(*i, newargs); + for (std::string const& arg : arguments) { + cmSystemTools::ExpandListArgument(arg, newargs); } } @@ -1389,14 +1385,6 @@ cmSystemTools::FileFormat cmSystemTools::GetFileFormat(std::string const& ext) return cmSystemTools::UNKNOWN_FILE_FORMAT; } -bool cmSystemTools::Split(const char* s, std::vector<std::string>& l) -{ - std::vector<std::string> temp; - bool res = Superclass::Split(s, temp); - l.insert(l.end(), temp.begin(), temp.end()); - return res; -} - std::string cmSystemTools::ConvertToOutputPath(std::string const& path) { #if defined(_WIN32) && !defined(__CYGWIN__) @@ -1424,7 +1412,7 @@ void cmSystemTools::ConvertToOutputSlashes(std::string& path) #endif } -std::string cmSystemTools::ConvertToRunCommandPath(const char* path) +std::string cmSystemTools::ConvertToRunCommandPath(const std::string& path) { #if defined(_WIN32) && !defined(__CYGWIN__) return cmSystemTools::ConvertToWindowsOutputPath(path); @@ -1438,12 +1426,12 @@ std::string cmSystemTools::RelativePath(std::string const& local, std::string const& remote) { if (!cmSystemTools::FileIsFullPath(local)) { - cmSystemTools::Error("RelativePath must be passed a full path to local: ", - local.c_str()); + cmSystemTools::Error("RelativePath must be passed a full path to local: " + + local); } if (!cmSystemTools::FileIsFullPath(remote)) { - cmSystemTools::Error("RelativePath must be passed a full path to remote: ", - remote.c_str()); + cmSystemTools::Error( + "RelativePath must be passed a full path to remote: " + remote); } return cmsys::SystemTools::RelativePath(local, remote); } @@ -1627,7 +1615,7 @@ void cmSystemTools::EnableVSConsoleOutput() #endif } -bool cmSystemTools::IsPathToFramework(const char* path) +bool cmSystemTools::IsPathToFramework(const std::string& path) { return (cmSystemTools::FileIsFullPath(path) && cmHasLiteralSuffix(path, ".framework")); @@ -1922,8 +1910,8 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) else { cmSystemTools::Error("Problem with archive_write_header(): ", archive_error_string(ext)); - cmSystemTools::Error("Current file: ", - cm_archive_entry_pathname(entry).c_str()); + cmSystemTools::Error("Current file: " + + cm_archive_entry_pathname(entry)); break; } } @@ -2082,7 +2070,8 @@ void cmSystemTools::DoNotInheritStdPipes() #endif } -bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile) +bool cmSystemTools::CopyFileTime(const std::string& fromFile, + const std::string& toFile) { #if defined(_WIN32) && !defined(__CYGWIN__) cmSystemToolsWindowsHandle hFrom = CreateFileW( @@ -2103,14 +2092,14 @@ bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile) return SetFileTime(hTo, &timeCreation, &timeLastAccess, &timeLastWrite) != 0; #else struct stat fromStat; - if (stat(fromFile, &fromStat) < 0) { + if (stat(fromFile.c_str(), &fromStat) < 0) { return false; } struct utimbuf buf; buf.actime = fromStat.st_atime; buf.modtime = fromStat.st_mtime; - return utime(toFile, &buf) >= 0; + return utime(toFile.c_str(), &buf) >= 0; #endif } @@ -2124,7 +2113,8 @@ void cmSystemTools::FileTimeDelete(cmSystemToolsFileTime* t) delete t; } -bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t) +bool cmSystemTools::FileTimeGet(const std::string& fname, + cmSystemToolsFileTime* t) { #if defined(_WIN32) && !defined(__CYGWIN__) cmSystemToolsWindowsHandle h = CreateFileW( @@ -2139,7 +2129,7 @@ bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t) } #else struct stat st; - if (stat(fname, &st) < 0) { + if (stat(fname.c_str(), &st) < 0) { return false; } t->timeBuf.actime = st.st_atime; @@ -2148,7 +2138,8 @@ bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t) return true; } -bool cmSystemTools::FileTimeSet(const char* fname, cmSystemToolsFileTime* t) +bool cmSystemTools::FileTimeSet(const std::string& fname, + const cmSystemToolsFileTime* t) { #if defined(_WIN32) && !defined(__CYGWIN__) cmSystemToolsWindowsHandle h = CreateFileW( @@ -2160,7 +2151,7 @@ bool cmSystemTools::FileTimeSet(const char* fname, cmSystemToolsFileTime* t) return SetFileTime(h, &t->timeCreation, &t->timeLastAccess, &t->timeLastWrite) != 0; #else - return utime(fname, &t->timeBuf) >= 0; + return utime(fname.c_str(), &t->timeBuf) >= 0; #endif } @@ -3015,7 +3006,7 @@ bool cmSystemTools::CheckRPath(std::string const& file, #endif } -bool cmSystemTools::RepeatedRemoveDirectory(const char* dir) +bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir) { // Windows sometimes locks files temporarily so try a few times. for (int i = 0; i < 10; ++i) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 0f92fe2..60e8c18 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -56,7 +56,7 @@ public: */ static std::string TrimWhitespace(const std::string& s); - using MessageCallback = std::function<void(const char*, const char*)>; + using MessageCallback = std::function<void(const std::string&, const char*)>; /** * Set the function used by GUIs to display error messages * Function gets passed: message as a const char*, @@ -74,11 +74,7 @@ public: /** * Display a message. */ - static void Message(const char* m, const char* title = nullptr); - static void Message(const std::string& m, const char* title = nullptr) - { - Message(m.c_str(), title); - } + static void Message(const std::string& m, const char* title = nullptr); using OutputCallback = std::function<void(std::string const&)>; @@ -145,19 +141,19 @@ public: ///! Return true if value is NOTFOUND or ends in -NOTFOUND. static bool IsNOTFOUND(const char* value); ///! Return true if the path is a framework - static bool IsPathToFramework(const char* value); + static bool IsPathToFramework(const std::string& value); static bool DoesFileExistWithExtensions( - const char* name, const std::vector<std::string>& sourceExts); + const std::string& name, const std::vector<std::string>& sourceExts); /** * Check if the given file exists in one of the parent directory of the * given file or directory and if it does, return the name of the file. * Toplevel specifies the top-most directory to where it will look. */ - static std::string FileExistsInParentDirectories(const char* fname, - const char* directory, - const char* toplevel); + static std::string FileExistsInParentDirectories( + const std::string& fname, const std::string& directory, + const std::string& toplevel); static void Glob(const std::string& directory, const std::string& regexp, std::vector<std::string>& files); @@ -176,10 +172,6 @@ public: static bool SimpleGlob(const std::string& glob, std::vector<std::string>& files, int type = 0); - ///! Copy a file. - static bool cmCopyFile(const std::string& source, - const std::string& destination); - /** Rename a file or directory within a single disk volume (atomic if possible). */ static bool RenameFile(const std::string& oldname, @@ -224,7 +216,7 @@ public: OUTPUT_FORWARD, OUTPUT_PASSTHROUGH }; - static bool RunSingleCommand(const char* command, + static bool RunSingleCommand(const std::string& command, std::string* captureStdOut = nullptr, std::string* captureStdErr = nullptr, int* retVal = nullptr, @@ -250,7 +242,7 @@ public: /** * Parse arguments out of a single string command */ - static std::vector<std::string> ParseArguments(const char* command); + static std::vector<std::string> ParseArguments(const std::string& command); /** Parse arguments out of a windows command line string. */ static void ParseWindowsCommandLine(const char* command, @@ -351,9 +343,6 @@ public: cmDuration timeout, std::vector<char>& out, std::vector<char>& err); - /** Split a string on its newlines into multiple lines. Returns - false only if the last line stored had no newline. */ - static bool Split(const char* s, std::vector<std::string>& l); static void SetForceUnixPaths(bool v) { s_ForceUnixPaths = v; } static bool GetForceUnixPaths() { return s_ForceUnixPaths; } @@ -364,7 +353,7 @@ public: // ConvertToRunCommandPath does not use s_ForceUnixPaths and should // be used when RunCommand is called from cmake, because the // running cmake needs paths to be in its format - static std::string ConvertToRunCommandPath(const char* path); + static std::string ConvertToRunCommandPath(const std::string& path); /** compute the relative path from local to remote. local must be a directory. remote can be a file or a directory. @@ -447,13 +436,15 @@ public: /** Copy the file create/access/modify times from the file named by the first argument to that named by the second. */ - static bool CopyFileTime(const char* fromFile, const char* toFile); + static bool CopyFileTime(const std::string& fromFile, + const std::string& toFile); /** Save and restore file times. */ static cmSystemToolsFileTime* FileTimeNew(); static void FileTimeDelete(cmSystemToolsFileTime*); - static bool FileTimeGet(const char* fname, cmSystemToolsFileTime* t); - static bool FileTimeSet(const char* fname, cmSystemToolsFileTime* t); + static bool FileTimeGet(const std::string& fname, cmSystemToolsFileTime* t); + static bool FileTimeSet(const std::string& fname, + const cmSystemToolsFileTime* t); /** Random seed generation. */ static unsigned int RandomSeed(); @@ -497,7 +488,7 @@ public: static bool CheckRPath(std::string const& file, std::string const& newRPath); /** Remove a directory; repeat a few times in case of locked files. */ - static bool RepeatedRemoveDirectory(const char* dir); + static bool RepeatedRemoveDirectory(const std::string& dir); /** Tokenize a string */ static std::vector<std::string> tokenize(const std::string& str, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 93cdd46..46f930a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -5,6 +5,7 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> #include <assert.h> +#include <initializer_list> #include <iterator> #include <set> #include <sstream> @@ -20,6 +21,7 @@ #include "cmMessageType.h" #include "cmMessenger.h" #include "cmProperty.h" +#include "cmRange.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmSourceFileLocationKind.h" @@ -312,23 +314,23 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Setup per-configuration property default values. if (this->GetType() != cmStateEnums::UTILITY) { - const char* configProps[] = { + static const auto configProps = { /* clang-format needs this comment to break after the opening brace */ "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_", "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_", "COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_", - "INTERPROCEDURAL_OPTIMIZATION_", nullptr + "INTERPROCEDURAL_OPTIMIZATION_" }; for (std::string const& configName : configNames) { std::string configUpper = cmSystemTools::UpperCase(configName); - for (const char** p = configProps; *p; ++p) { + for (auto const& prop : configProps) { // Interface libraries have no output locations, so honor only // the configuration map. if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY && - strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0) { + strcmp(prop, "MAP_IMPORTED_CONFIG_") != 0) { continue; } - std::string property = *p; + std::string property = prop; property += configUpper; this->SetPropertyDefault(property, nullptr); } @@ -707,10 +709,8 @@ std::string cmTarget::GetDebugGeneratorExpressions( std::string configString = "$<CONFIG:" + debugConfigs[0] + ">"; if (debugConfigs.size() > 1) { - for (std::vector<std::string>::const_iterator li = - debugConfigs.begin() + 1; - li != debugConfigs.end(); ++li) { - configString += ",$<CONFIG:" + *li + ">"; + for (std::string const& conf : cmMakeRange(debugConfigs).advance(1)) { + configString += ",$<CONFIG:" + conf + ">"; } configString = "$<OR:" + configString + ">"; } diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 5102613..571cd09 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -12,6 +12,7 @@ #include "cmOutputConverter.h" #include "cmProperty.h" #include "cmPropertyMap.h" +#include "cmRange.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTest.h" @@ -94,10 +95,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, std::string emulatorExe(emulatorWithArgs[0]); cmSystemTools::ConvertToUnixSlashes(emulatorExe); os << cmOutputConverter::EscapeForCMake(emulatorExe) << " "; - for (std::vector<std::string>::const_iterator ei = - emulatorWithArgs.begin() + 1; - ei != emulatorWithArgs.end(); ++ei) { - os << cmOutputConverter::EscapeForCMake(*ei) << " "; + for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) { + os << cmOutputConverter::EscapeForCMake(arg) << " "; } } } else { @@ -108,11 +107,10 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, // Generate the command line with full escapes. os << cmOutputConverter::EscapeForCMake(exe); - for (std::vector<std::string>::const_iterator ci = command.begin() + 1; - ci != command.end(); ++ci) { + for (std::string const& arg : cmMakeRange(command).advance(1)) { os << " " << cmOutputConverter::EscapeForCMake( - ge.Parse(*ci)->Evaluate(this->LG, config)); + ge.Parse(arg)->Evaluate(this->LG, config)); } // Finish the test command. @@ -157,12 +155,11 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent) fout << "add_test("; fout << this->Test->GetName() << " \"" << exe << "\""; - for (std::vector<std::string>::const_iterator argit = command.begin() + 1; - argit != command.end(); ++argit) { + for (std::string const& arg : cmMakeRange(command).advance(1)) { // Just double-quote all arguments so they are re-parsed // correctly by the test system. fout << " \""; - for (char c : *argit) { + for (char c : arg) { // Escape quotes within arguments. We should escape // backslashes too but we cannot because it makes the result // inconsistent with previous behavior of this command. diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index c57aabd..4b0707b 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -8,6 +8,7 @@ #include "cmDuration.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmRange.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -172,25 +173,22 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, std::vector<std::string> emulatorWithArgs; cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs); finalCommand += - cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0].c_str()); + cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0]); finalCommand += " "; - for (std::vector<std::string>::const_iterator ei = - emulatorWithArgs.begin() + 1; - ei != emulatorWithArgs.end(); ++ei) { + for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) { finalCommand += "\""; - finalCommand += *ei; + finalCommand += arg; finalCommand += "\""; finalCommand += " "; } } - finalCommand += - cmSystemTools::ConvertToRunCommandPath(this->OutputFile.c_str()); + finalCommand += cmSystemTools::ConvertToRunCommandPath(this->OutputFile); if (!runArgs.empty()) { finalCommand += runArgs; } bool worked = cmSystemTools::RunSingleCommand( - finalCommand.c_str(), out, out, &retVal, nullptr, - cmSystemTools::OUTPUT_NONE, cmDuration::zero()); + finalCommand, out, out, &retVal, nullptr, cmSystemTools::OUTPUT_NONE, + cmDuration::zero()); // set the run var char retChar[16]; const char* retStr; diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx index 9648b21..e4a1b5f 100644 --- a/Source/cmUseMangledMesaCommand.cxx +++ b/Source/cmUseMangledMesaCommand.cxx @@ -19,7 +19,7 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args, this->SetError("called with incorrect number of arguments"); return false; } - const char* inputDir = args[0].c_str(); + const std::string& inputDir = args[0]; std::string glh = inputDir; glh += "/"; glh += "gl.h"; @@ -34,7 +34,7 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args, std::vector<std::string> files; cmSystemTools::Glob(inputDir, "\\.h$", files); if (files.empty()) { - cmSystemTools::Error("Could not open Mesa Directory ", inputDir); + cmSystemTools::Error("Could not open Mesa Directory " + inputDir); return false; } cmSystemTools::MakeDirectory(destDir); @@ -60,8 +60,8 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source, tempOutputFile += ".tmp"; cmsys::ofstream fout(tempOutputFile.c_str()); if (!fout) { - cmSystemTools::Error("Could not open file for write in copy operation: ", - tempOutputFile.c_str(), outdir); + cmSystemTools::Error("Could not open file for write in copy operation: " + + tempOutputFile + outdir); cmSystemTools::ReportLastSystemError(""); return; } diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index 231bca4..b59a587 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -79,7 +79,7 @@ bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args, } // The source exists. - std::string cmakeCFGout = + const std::string& cmakeCFGout = this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR"); std::string utilityDirectory = this->Makefile->GetCurrentBinaryDirectory(); std::string exePath; diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx index 201e1cc..51ecbd1 100644 --- a/Source/cmUuid.cxx +++ b/Source/cmUuid.cxx @@ -4,16 +4,10 @@ #include "cmCryptoHash.h" +#include <array> #include <string.h> -cmUuid::cmUuid() -{ - Groups.push_back(4); - Groups.push_back(2); - Groups.push_back(2); - Groups.push_back(2); - Groups.push_back(6); -} +static const std::array<int, 5> kUuidGroups = { { 4, 2, 2, 2, 6 } }; std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace, std::string const& name) const @@ -83,11 +77,11 @@ bool cmUuid::StringToBinary(std::string const& input, return false; } size_t index = 0; - for (size_t i = 0; i < this->Groups.size(); ++i) { + for (size_t i = 0; i < kUuidGroups.size(); ++i) { if (i != 0 && input[index++] != '-') { return false; } - size_t digits = this->Groups[i] * 2; + size_t digits = kUuidGroups[i] * 2; if (!StringToBinaryImpl(input.substr(index, digits), output)) { return false; } @@ -103,12 +97,12 @@ std::string cmUuid::BinaryToString(const unsigned char* input) const std::string output; size_t inputIndex = 0; - for (size_t i = 0; i < this->Groups.size(); ++i) { + for (size_t i = 0; i < kUuidGroups.size(); ++i) { if (i != 0) { output += '-'; } - size_t bytes = this->Groups[i]; + size_t bytes = kUuidGroups[i]; for (size_t j = 0; j < bytes; ++j) { unsigned char byte = input[inputIndex++]; output += this->ByteToHex(byte); diff --git a/Source/cmUuid.h b/Source/cmUuid.h index 158ce6e..7de20dd 100644 --- a/Source/cmUuid.h +++ b/Source/cmUuid.h @@ -15,8 +15,6 @@ class cmUuid { public: - cmUuid(); - std::string FromMd5(std::vector<unsigned char> const& uuidNamespace, std::string const& name) const; @@ -42,8 +40,6 @@ private: std::string BinaryToString(const unsigned char* input) const; bool IntFromHexDigit(char input, char& output) const; - - std::vector<int> Groups; }; #endif diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h index 5855fed..1230101 100644 --- a/Source/cmVariableWatch.h +++ b/Source/cmVariableWatch.h @@ -72,6 +72,9 @@ protected: this->DeleteDataCall(this->ClientData); } } + Pair() = default; + Pair(const Pair&) = delete; + Pair& operator=(const Pair&) = delete; }; typedef std::vector<std::shared_ptr<Pair>> VectorOfPairs; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 8e08417..b655815 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -622,8 +622,8 @@ void cmVisualStudio10TargetGenerator::Generate() propsLocal += this->DefaultArtifactDir; propsLocal += "\\nasm.props"; ConvertToWindowsSlash(propsLocal); - this->Makefile->ConfigureFile(propsTemplate.c_str(), - propsLocal.c_str(), false, true, true); + this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true, + true); Elem(e1, "Import").Attribute("Project", propsLocal); } } @@ -1321,8 +1321,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( std::string error = "Could not create file: ["; error += sourcePath; error += "] "; - cmSystemTools::Error(error.c_str(), - cmSystemTools::GetLastSystemError().c_str()); + cmSystemTools::Error(error + cmSystemTools::GetLastSystemError()); } } } @@ -2514,8 +2513,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( this->GeneratorTarget->GetLinkerLanguage(configName); if (linkLanguage.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - this->Name.c_str()); + "CMake can not determine linker language for target: " + this->Name); return false; } @@ -3345,8 +3343,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( const std::string& linkLanguage = linkClosure->LinkerLanguage; if (linkLanguage.empty()) { cmSystemTools::Error( - "CMake can not determine linker language for target: ", - this->Name.c_str()); + "CMake can not determine linker language for target: " + this->Name); return false; } @@ -3391,8 +3388,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( this->GeneratorTarget->GetLinkInformation(config); if (!pcli) { cmSystemTools::Error( - "CMake can not compute cmComputeLinkInformation for target: ", - this->Name.c_str()); + "CMake can not compute cmComputeLinkInformation for target: " + + this->Name); return false; } cmComputeLinkInformation& cli = *pcli; @@ -3439,18 +3436,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkDirs.push_back("%(AdditionalLibraryDirectories)"); linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs); - std::string targetName; - std::string targetNameSO; - std::string targetNameFull; - std::string targetNameImport; - std::string targetNamePDB; + cmGeneratorTarget::Names targetNames; if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { - this->GeneratorTarget->GetExecutableNames( - targetName, targetNameFull, targetNameImport, targetNamePDB, config); + targetNames = this->GeneratorTarget->GetExecutableNames(config); } else { - this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO, - targetNameFull, targetNameImport, - targetNamePDB, config); + targetNames = this->GeneratorTarget->GetLibraryNames(config); } if (this->MSTools) { @@ -3491,11 +3481,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string pdb = this->GeneratorTarget->GetPDBDirectory(config); pdb += "/"; - pdb += targetNamePDB; + pdb += targetNames.PDB; std::string imLib = this->GeneratorTarget->GetDirectory( config, cmStateEnums::ImportLibraryArtifact); imLib += "/"; - imLib += targetNameImport; + imLib += targetNames.ImportLibrary; linkOptions.AddFlag("ImportLibrary", imLib); linkOptions.AddFlag("ProgramDataBaseFile", pdb); @@ -3519,7 +3509,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib"); } } else if (this->NsightTegra) { - linkOptions.AddFlag("SoName", targetNameSO); + linkOptions.AddFlag("SoName", targetNames.SharedObject); } linkOptions.Parse(flags); @@ -3579,8 +3569,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( this->GeneratorTarget->GetLinkInformation(config); if (!pcli) { cmSystemTools::Error( - "CMake can not compute cmComputeLinkInformation for target: ", - this->Name.c_str()); + "CMake can not compute cmComputeLinkInformation for target: " + + this->Name); return false; } diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 5c3e533..e8b2668 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -438,14 +438,13 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions( const char* sep = ""; std::vector<std::string>::const_iterator de = cmRemoveDuplicates(this->Defines); - for (std::vector<std::string>::const_iterator di = this->Defines.begin(); - di != de; ++di) { + for (std::string const& di : cmMakeRange(this->Defines.cbegin(), de)) { // Escape the definition for the compiler. std::string define; if (this->Version < cmGlobalVisualStudioGenerator::VS10) { - define = this->LocalGenerator->EscapeForShell(*di, true); + define = this->LocalGenerator->EscapeForShell(di, true); } else { - define = *di; + define = di; } // Escape this flag for the MSBuild. if (this->Version >= cmGlobalVisualStudioGenerator::VS10) { diff --git a/Source/cmWorkingDirectory.h b/Source/cmWorkingDirectory.h index 1f18ce7..d4a164d 100644 --- a/Source/cmWorkingDirectory.h +++ b/Source/cmWorkingDirectory.h @@ -22,6 +22,9 @@ public: cmWorkingDirectory(std::string const& newdir); ~cmWorkingDirectory(); + cmWorkingDirectory(const cmWorkingDirectory&) = delete; + cmWorkingDirectory& operator=(const cmWorkingDirectory&) = delete; + bool SetDirectory(std::string const& newdir); void Pop(); bool Failed() const { return ResultCode != 0; } diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index 1df8a09..512e103 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -146,6 +146,8 @@ public: xmlwr.StartDocument(); } ~cmXMLDocument() { xmlwr.EndDocument(); } + cmXMLDocument(const cmXMLDocument&) = delete; + cmXMLDocument& operator=(const cmXMLDocument&) = delete; private: friend class cmXMLElement; @@ -172,6 +174,9 @@ public: } ~cmXMLElement() { xmlwr.EndElement(); } + cmXMLElement(const cmXMLElement&) = delete; + cmXMLElement& operator=(const cmXMLElement&) = delete; + template <typename T> cmXMLElement& Attribute(const char* name, T const& value) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 8023298..f6f0a95 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -99,6 +99,7 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> #include <cstring> +#include <initializer_list> #include <iostream> #include <iterator> #include <memory> // IWYU pragma: keep @@ -787,13 +788,13 @@ void cmake::SetArgs(const std::vector<std::string>& args) } cmGlobalGenerator* gen = this->CreateGlobalGenerator(value); if (!gen) { - const char* kdevError = nullptr; + std::string kdevError; if (value.find("KDevelop3", 0) != std::string::npos) { kdevError = "\nThe KDevelop3 generator is not supported anymore."; } - cmSystemTools::Error("Could not create named generator ", - value.c_str(), kdevError); + cmSystemTools::Error("Could not create named generator " + value + + kdevError); this->PrintGeneratorList(); } else { this->SetGlobalGenerator(gen); @@ -937,8 +938,8 @@ int cmake::AddCMakePaths() cmSystemTools::Error( "Could not find CMAKE_ROOT !!!\n" "CMake has most likely not been installed correctly.\n" - "Modules directory not found in\n", - cmSystemTools::GetCMakeRoot().c_str()); + "Modules directory not found in\n" + + cmSystemTools::GetCMakeRoot()); return 0; } this->AddCacheEntry("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(), @@ -1105,7 +1106,7 @@ std::string cmake::FindCacheFile(const std::string& binaryDir) if (cmSystemTools::FileExists(cmakeFiles)) { std::string cachePathFound = cmSystemTools::FileExistsInParentDirectories("CMakeCache.txt", - cachePath.c_str(), "/"); + cachePath, "/"); if (!cachePathFound.empty()) { cachePath = cmSystemTools::GetFilenamePath(cachePathFound); } @@ -1705,7 +1706,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) ret = this->Generate(); std::string message = "Build files have been written to: "; message += this->GetHomeOutputDirectory(); - this->UpdateProgress(message.c_str(), -1); + this->UpdateProgress(message, -1); return ret; } @@ -1892,11 +1893,10 @@ bool cmake::LoadCache(const std::string& path, bool internal, std::set<std::string>& includes) { bool result = this->State->LoadCache(path, internal, excludes, includes); - static const char* entries[] = { "CMAKE_CACHE_MAJOR_VERSION", - "CMAKE_CACHE_MINOR_VERSION" }; - for (const char* const* nameIt = cm::cbegin(entries); - nameIt != cm::cend(entries); ++nameIt) { - this->UnwatchUnusedCli(*nameIt); + static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION", + "CMAKE_CACHE_MINOR_VERSION" }; + for (auto const& entry : entries) { + this->UnwatchUnusedCli(entry); } return result; } @@ -1904,13 +1904,12 @@ bool cmake::LoadCache(const std::string& path, bool internal, bool cmake::SaveCache(const std::string& path) { bool result = this->State->SaveCache(path, this->GetMessenger()); - static const char* entries[] = { "CMAKE_CACHE_MAJOR_VERSION", - "CMAKE_CACHE_MINOR_VERSION", - "CMAKE_CACHE_PATCH_VERSION", - "CMAKE_CACHEFILE_DIR" }; - for (const char* const* nameIt = cm::cbegin(entries); - nameIt != cm::cend(entries); ++nameIt) { - this->UnwatchUnusedCli(*nameIt); + static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION", + "CMAKE_CACHE_MINOR_VERSION", + "CMAKE_CACHE_PATCH_VERSION", + "CMAKE_CACHEFILE_DIR" }; + for (auto const& entry : entries) { + this->UnwatchUnusedCli(entry); } return result; } @@ -1925,7 +1924,7 @@ void cmake::SetProgressCallback(ProgressCallbackType f) this->ProgressCallback = std::move(f); } -void cmake::UpdateProgress(const char* msg, float prog) +void cmake::UpdateProgress(const std::string& msg, float prog) { if (this->ProgressCallback && !this->State->GetIsInTryCompile()) { this->ProgressCallback(msg, prog); @@ -2017,8 +2016,8 @@ void cmake::UpdateConversionPathTable() if (tablepath) { cmsys::ifstream table(tablepath->c_str()); if (!table) { - cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", - tablepath->c_str(), ". CMake can not open file."); + cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to " + *tablepath + + ". CMake can not open file."); cmSystemTools::ReportLastSystemError("CMake can not open file."); } else { std::string a, b; @@ -2326,8 +2325,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args) } cmGlobalGenerator* gen = this->CreateGlobalGenerator(value); if (!gen) { - cmSystemTools::Error("Could not create named generator ", - value.c_str()); + cmSystemTools::Error("Could not create named generator " + value); this->PrintGeneratorList(); } else { this->SetGlobalGenerator(gen); @@ -2354,7 +2352,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args) outFile += "/CMakeLists.txt"; // Copy file - if (!cmSystemTools::cmCopyFile(inFile, outFile)) { + if (!cmsys::SystemTools::CopyFileAlways(inFile, outFile)) { std::cerr << "Error copying file \"" << inFile << "\" to \"" << outFile << "\".\n"; return 1; @@ -2474,7 +2472,7 @@ static bool cmakeCheckStampFile(const std::string& stampName, bool verbose) return true; } cmSystemTools::RemoveFile(stampTemp); - cmSystemTools::Error("Cannot restore timestamp ", stampName.c_str()); + cmSystemTools::Error("Cannot restore timestamp " + stampName); return false; } @@ -2640,7 +2638,7 @@ int cmake::Build(int jobs, const std::string& dir, const std::string& target, } std::string message = "Build files have been written to: "; message += this->GetHomeOutputDirectory(); - this->UpdateProgress(message.c_str(), -1); + this->UpdateProgress(message, -1); // Restore the previously set directories to their original value. this->SetHomeDirectory(homeOrig); diff --git a/Source/cmake.h b/Source/cmake.h index 53d44f1..6fa2d3a 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -273,7 +273,7 @@ public: ///! Parse command line arguments that might set cache values bool SetCacheArgs(const std::vector<std::string>&); - using ProgressCallbackType = std::function<void(const char*, float)>; + using ProgressCallbackType = std::function<void(const std::string&, float)>; /** * Set the function used by GUIs to receive progress updates * Function gets passed: message as a const char*, a progress @@ -284,7 +284,7 @@ public: void SetProgressCallback(ProgressCallbackType f); ///! this is called by generators to update the progress - void UpdateProgress(const char* msg, float prog); + void UpdateProgress(const std::string& msg, float prog); #if defined(CMAKE_BUILD_WITH_CMAKE) ///! Get the variable watch object diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 890b74e..e6f4021 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -142,20 +142,21 @@ static std::string cmakemainGetStack(cmake* cm) return msg; } -static void cmakemainMessageCallback(const char* m, const char* /*unused*/, - cmake* cm) +static void cmakemainMessageCallback(const std::string& m, + const char* /*unused*/, cmake* cm) { std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush; } -static void cmakemainProgressCallback(const char* m, float prog, cmake* cm) +static void cmakemainProgressCallback(const std::string& m, float prog, + cmake* cm) { cmMakefile* mf = cmakemainGetMakefile(cm); std::string dir; - if ((mf) && (strstr(m, "Configuring") == m) && (prog < 0)) { + if (mf && cmHasLiteralPrefix(m, "Configuring") && (prog < 0)) { dir = " "; dir += mf->GetCurrentSourceDirectory(); - } else if ((mf) && (strstr(m, "Generating") == m)) { + } else if (mf && cmHasLiteralPrefix(m, "Generating")) { dir = " "; dir += mf->GetCurrentBinaryDirectory(); } @@ -319,10 +320,11 @@ int do_cmake(int ac, char const* const* av) cmake cm(role, mode); cm.SetHomeDirectory(""); cm.SetHomeOutputDirectory(""); - cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) { - cmakemainMessageCallback(msg, title, &cm); - }); - cm.SetProgressCallback([&cm](const char* msg, float prog) { + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const char* title) { + cmakemainMessageCallback(msg, title, &cm); + }); + cm.SetProgressCallback([&cm](const std::string& msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); }); cm.SetWorkingMode(workingMode); @@ -498,11 +500,12 @@ static int do_build(int ac, char const* const* av) return 1; } - cmake cm(cmake::RoleInternal, cmState::Unknown); - cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) { - cmakemainMessageCallback(msg, title, &cm); - }); - cm.SetProgressCallback([&cm](const char* msg, float prog) { + cmake cm(cmake::RoleInternal, cmState::Project); + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const char* title) { + cmakemainMessageCallback(msg, title, &cm); + }); + cm.SetProgressCallback([&cm](const std::string& msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); }); return cm.Build(jobs, dir, target, config, nativeOptions, clean, verbose); @@ -541,10 +544,11 @@ static int do_open(int ac, char const* const* av) } cmake cm(cmake::RoleInternal, cmState::Unknown); - cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) { - cmakemainMessageCallback(msg, title, &cm); - }); - cm.SetProgressCallback([&cm](const char* msg, float prog) { + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const char* title) { + cmakemainMessageCallback(msg, title, &cm); + }); + cm.SetProgressCallback([&cm](const std::string& msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); }); return cm.Open(dir, false) ? 0 : 1; diff --git a/Source/cmakexbuild.cxx b/Source/cmakexbuild.cxx deleted file mode 100644 index 2951945..0000000 --- a/Source/cmakexbuild.cxx +++ /dev/null @@ -1,80 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ - -#include "cmConfigure.h" // IWYU pragma: keep - -#include "cmsys/Process.h" -#include <iostream> -#include <string> -#include <vector> - -#include "cmDuration.h" -#include "cmSystemTools.h" - -// This is a wrapper program for xcodebuild -// it calls xcodebuild, and does two things -// it removes much of the output, all the setenv -// stuff. Also, it checks for the text file busy -// error, and re-runs xcodebuild until that error does -// not show up. - -int RunXCode(std::vector<const char*>& argv, bool& hitbug) -{ - hitbug = false; - cmsysProcess* cp = cmsysProcess_New(); - cmsysProcess_SetCommand(cp, &*argv.begin()); - cmsysProcess_SetTimeout(cp, 0); - cmsysProcess_Execute(cp); - std::vector<char> out; - std::vector<char> err; - std::string line; - int pipe = - cmSystemTools::WaitForLine(cp, line, std::chrono::seconds(100), out, err); - while (pipe != cmsysProcess_Pipe_None) { - if (line.find("/bin/sh: bad interpreter: Text file busy") != - std::string::npos) { - hitbug = true; - std::cerr << "Hit xcodebuild bug : " << line << "\n"; - } - // if the bug is hit, no more output should be generated - // because it may contain bogus errors - // also remove all output with setenv in it to tone down - // the verbosity of xcodebuild - if (!hitbug && (line.find("setenv") == std::string::npos)) { - if (pipe == cmsysProcess_Pipe_STDERR) { - std::cerr << line << "\n"; - } else if (pipe == cmsysProcess_Pipe_STDOUT) { - std::cout << line << "\n"; - } - } - pipe = cmSystemTools::WaitForLine(cp, line, std::chrono::seconds(100), out, - err); - } - cmsysProcess_WaitForExit(cp, nullptr); - if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) { - return cmsysProcess_GetExitValue(cp); - } - if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) { - return -1; - } - return -1; -} - -int main(int ac, char* av[]) -{ - std::vector<const char*> argv; - argv.push_back("xcodebuild"); - for (int i = 1; i < ac; i++) { - argv.push_back(av[i]); - } - argv.push_back(nullptr); - bool hitbug = true; - int ret = 0; - while (hitbug) { - ret = RunXCode(argv, hitbug); - } - if (ret < 0) { - return 255; - } - return ret; -} diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index d20c5d2..6e1a27c 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -9,6 +9,7 @@ #include "cmMakefile.h" #include "cmQtAutoGeneratorMocUic.h" #include "cmQtAutoGeneratorRcc.h" +#include "cmRange.h" #include "cmState.h" #include "cmStateDirectory.h" #include "cmStateSnapshot.h" @@ -37,6 +38,7 @@ #include "cmsys/Process.h" #include "cmsys/Terminal.h" #include <algorithm> +#include <array> #include <iostream> #include <iterator> #include <memory> // IWYU pragma: keep @@ -350,12 +352,13 @@ struct CoCompiler bool NoOriginalCommand; }; -static CoCompiler CoCompilers[] = { // Table of options and handlers. - { "--cppcheck=", HandleCppCheck, false }, - { "--cpplint=", HandleCppLint, false }, - { "--iwyu=", HandleIWYU, false }, - { "--lwyu=", HandleLWYU, true }, - { "--tidy=", HandleTidy, false } +static const std::array<CoCompiler, 5> CoCompilers = { + { // Table of options and handlers. + { "--cppcheck=", HandleCppCheck, false }, + { "--cpplint=", HandleCppLint, false }, + { "--iwyu=", HandleIWYU, false }, + { "--lwyu=", HandleLWYU, true }, + { "--tidy=", HandleTidy, false } } }; struct CoCompileJob @@ -386,16 +389,15 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args) doing_options = false; } else if (doing_options) { bool optionFound = false; - for (CoCompiler const* cc = cm::cbegin(CoCompilers); - cc != cm::cend(CoCompilers); ++cc) { - size_t optionLen = strlen(cc->Option); - if (arg.compare(0, optionLen, cc->Option) == 0) { + for (CoCompiler const& cc : CoCompilers) { + size_t optionLen = strlen(cc.Option); + if (arg.compare(0, optionLen, cc.Option) == 0) { optionFound = true; CoCompileJob job; job.Command = arg.substr(optionLen); - job.Handler = cc->Handler; + job.Handler = cc.Handler; jobs.push_back(std::move(job)); - if (cc->NoOriginalCommand) { + if (cc.NoOriginalCommand) { runOriginalCmd = false; } } @@ -419,9 +421,8 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args) if (jobs.empty()) { std::cerr << "__run_co_compile missing command to run. " "Looking for one or more of the following:\n"; - for (CoCompiler const* cc = cm::cbegin(CoCompilers); - cc != cm::cend(CoCompilers); ++cc) { - std::cerr << cc->Option << "\n"; + for (CoCompiler const& cc : CoCompilers) { + std::cerr << cc.Option << "\n"; } return 1; } @@ -482,7 +483,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) // If error occurs we want to continue copying next files. bool return_value = false; for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) { - if (!cmSystemTools::cmCopyFile(args[cc], args.back())) { + if (!cmsys::SystemTools::CopyFileAlways(args[cc], args.back())) { std::cerr << "Error copying file \"" << args[cc] << "\" to \"" << args.back() << "\".\n"; return_value = true; @@ -817,8 +818,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) if (args[1] == "chdir" && args.size() >= 4) { std::string const& directory = args[2]; if (!cmSystemTools::FileExists(directory)) { - cmSystemTools::Error("Directory does not exist for chdir command: ", - args[2].c_str()); + cmSystemTools::Error("Directory does not exist for chdir command: " + + args[2]); return 1; } @@ -826,7 +827,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) cmWrap('"', cmMakeRange(args).advance(3), '"', " "); int retval = 0; if (cmSystemTools::RunSingleCommand( - command.c_str(), nullptr, nullptr, &retval, directory.c_str(), + command, nullptr, nullptr, &retval, directory.c_str(), cmSystemTools::OUTPUT_PASSTHROUGH, cmDuration::zero())) { return retval; } @@ -1065,12 +1066,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) format) != cm::cend(knownFormats); if (!isKnown) { - cmSystemTools::Error("Unknown -E tar --format= argument: ", - format.c_str()); + cmSystemTools::Error("Unknown -E tar --format= argument: " + + format); return 1; } } else { - cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str()); + cmSystemTools::Error("Unknown option to -E tar: " + arg); return 1; } } else { @@ -1094,8 +1095,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) ++nCompress; } if ((format == "7zip" || format == "zip") && nCompress > 0) { - cmSystemTools::Error("Can not use compression flags with format: ", - format.c_str()); + cmSystemTools::Error("Can not use compression flags with format: " + + format); return 1; } if (nCompress > 1) { @@ -1109,18 +1110,18 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) if (flags.find_first_of('t') != std::string::npos) { if (!cmSystemTools::ListTar(outFile.c_str(), verbose)) { - cmSystemTools::Error("Problem listing tar: ", outFile.c_str()); + cmSystemTools::Error("Problem listing tar: " + outFile); return 1; } } else if (flags.find_first_of('c') != std::string::npos) { if (!cmSystemTools::CreateTar(outFile.c_str(), files, compress, verbose, mtime, format)) { - cmSystemTools::Error("Problem creating tar: ", outFile.c_str()); + cmSystemTools::Error("Problem creating tar: " + outFile); return 1; } } else if (flags.find_first_of('x') != std::string::npos) { if (!cmSystemTools::ExtractTar(outFile.c_str(), verbose)) { - cmSystemTools::Error("Problem extracting tar: ", outFile.c_str()); + cmSystemTools::Error("Problem extracting tar: " + outFile); return 1; } #ifdef WIN32 diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index e7da994..8577506 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -179,13 +179,6 @@ IF(KWSYS_USE_ConsoleBuf) SET(KWSYS_USE_Encoding 1) ENDIF() -# Setup the large file support default. -IF(KWSYS_LFS_DISABLE) - SET(KWSYS_LFS_REQUESTED 0) -ELSE() - SET(KWSYS_LFS_REQUESTED 1) -ENDIF() - # Specify default 8 bit encoding for Windows IF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE) SET(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_ACP) @@ -353,30 +346,6 @@ IF(KWSYS_STANDALONE) ENDIF() #----------------------------------------------------------------------------- -# Configure Large File Support. -KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CSTDIO - "Checking whether header cstdio is available" DIRECT) -SET(KWSYS_LFS_AVAILABLE 0) -IF(KWSYS_LFS_REQUESTED) - # Large File Support is requested. - SET(KWSYS_LFS_REQUESTED 1) - - # Check for large file support. - SET(KWSYS_PLATFORM_CXX_TEST_DEFINES - -DKWSYS_CXX_HAS_CSTDIO=${KWSYS_CXX_HAS_CSTDIO}) - KWSYS_PLATFORM_CXX_TEST_RUN(KWSYS_LFS_WORKS - "Checking for Large File Support" DIRECT) - SET(KWSYS_PLATFORM_CXX_TEST_DEFINES) - - IF(KWSYS_LFS_WORKS) - SET(KWSYS_LFS_AVAILABLE 1) - ENDIF() -ELSE() - # Large File Support is not requested. - SET(KWSYS_LFS_REQUESTED 0) -ENDIF() - -#----------------------------------------------------------------------------- # Configure the standard library header wrappers based on compiler's # capabilities and parent project's request. Enforce 0/1 as only # possible values for configuration into Configure.hxx. @@ -575,9 +544,6 @@ IF(KWSYS_USE_SystemInformation) COMPILE_DEFINITIONS KWSYS_SYS_HAS_MACHINE_CPU_H=1) ENDIF() ENDIF() - IF(KWSYS_LFS_AVAILABLE AND NOT KWSYS_LFS_DISABLE) - SET(KWSYS_PLATFORM_CXX_TEST_DEFINES -DKWSYS_HAS_LFS=1) - ENDIF() KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_RLIMIT64 "Checking whether CXX compiler has rlimit64" DIRECT) SET(KWSYS_PLATFORM_CXX_TEST_DEFINES) diff --git a/Source/kwsys/CommandLineArguments.hxx.in b/Source/kwsys/CommandLineArguments.hxx.in index 31115e5..7db9015 100644 --- a/Source/kwsys/CommandLineArguments.hxx.in +++ b/Source/kwsys/CommandLineArguments.hxx.in @@ -62,6 +62,9 @@ public: CommandLineArguments(); ~CommandLineArguments(); + CommandLineArguments(const CommandLineArguments&) = delete; + CommandLineArguments& operator=(const CommandLineArguments&) = delete; + /** * Various argument types. */ diff --git a/Source/kwsys/Configure.h.in b/Source/kwsys/Configure.h.in index bec1abc..5323c57 100644 --- a/Source/kwsys/Configure.h.in +++ b/Source/kwsys/Configure.h.in @@ -28,43 +28,6 @@ /* Whether kwsys namespace is "kwsys". */ #define @KWSYS_NAMESPACE@_NAME_IS_KWSYS @KWSYS_NAME_IS_KWSYS@ -/* Whether Large File Support is requested. */ -#define @KWSYS_NAMESPACE@_LFS_REQUESTED @KWSYS_LFS_REQUESTED@ - -/* Whether Large File Support is available. */ -#if @KWSYS_NAMESPACE@_LFS_REQUESTED -# define @KWSYS_NAMESPACE@_LFS_AVAILABLE @KWSYS_LFS_AVAILABLE@ -#endif - -/* Setup Large File Support if requested. */ -#if @KWSYS_NAMESPACE@_LFS_REQUESTED -/* Since LFS is requested this header must be included before system - headers whether or not LFS is available. */ -# if 0 && (defined(_SYS_TYPES_H) || defined(_SYS_TYPES_INCLUDED)) -# error "@KWSYS_NAMESPACE@/Configure.h must be included before sys/types.h" -# endif -/* Enable the large file API if it is available. */ -# if @KWSYS_NAMESPACE@_LFS_AVAILABLE && \ - !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINES) -# if !defined(_LARGEFILE_SOURCE) && \ - !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE_SOURCE) -# define _LARGEFILE_SOURCE -# endif -# if !defined(_LARGEFILE64_SOURCE) && \ - !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE64_SOURCE) -# define _LARGEFILE64_SOURCE -# endif -# if !defined(_LARGE_FILES) && \ - !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGE_FILES) -# define _LARGE_FILES -# endif -# if !defined(_FILE_OFFSET_BITS) && \ - !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS) -# define _FILE_OFFSET_BITS 64 -# endif -# endif -#endif - /* Setup the export macro. */ #if @KWSYS_BUILD_SHARED@ # if defined(_WIN32) || defined(__CYGWIN__) diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index 31b1c15..59530a4 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -102,7 +102,7 @@ bool Directory::Load(const std::string& name) # endif char* buf; size_t n = name.size(); - if (*name.rbegin() == '/' || *name.rbegin() == '\\') { + if (name.back() == '/' || name.back() == '\\') { buf = new char[n + 1 + 1]; sprintf(buf, "%s*", name.c_str()); } else { @@ -144,7 +144,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) # endif char* buf; size_t n = name.size(); - if (*name.rbegin() == '/') { + if (name.back() == '/') { buf = new char[n + 1 + 1]; sprintf(buf, "%s*", name.c_str()); } else { diff --git a/Source/kwsys/Glob.cxx b/Source/kwsys/Glob.cxx index 6952d24..829c138 100644 --- a/Source/kwsys/Glob.cxx +++ b/Source/kwsys/Glob.cxx @@ -263,7 +263,7 @@ bool Glob::RecurseDirectory(std::string::size_type start, } } else { if (!this->Internals->Expressions.empty() && - this->Internals->Expressions.rbegin()->find(fname)) { + this->Internals->Expressions.back().find(fname)) { this->AddFile(this->Internals->Files, realname); } } diff --git a/Source/kwsys/Glob.hxx.in b/Source/kwsys/Glob.hxx.in index bd4a176..4c3bde1 100644 --- a/Source/kwsys/Glob.hxx.in +++ b/Source/kwsys/Glob.hxx.in @@ -41,17 +41,9 @@ public: , content(c) { } - Message(const Message& msg) - : type(msg.type) - , content(msg.content) - { - } - Message& operator=(Message const& msg) - { - this->type = msg.type; - this->content = msg.content; - return *this; - } + ~Message() = default; + Message(const Message& msg) = default; + Message& operator=(Message const& msg) = default; }; typedef std::vector<Message> GlobMessages; diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index f323efc..4354753 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -4620,7 +4620,7 @@ std::string SystemInformationImplementation::RunProcess( // Run the application kwsysProcess* gp = kwsysProcess_New(); - kwsysProcess_SetCommand(gp, &*args.begin()); + kwsysProcess_SetCommand(gp, args.data()); kwsysProcess_SetOption(gp, kwsysProcess_Option_HideWindow, 1); kwsysProcess_Execute(gp); diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in index 9e1ce6c..5e93878 100644 --- a/Source/kwsys/SystemInformation.hxx.in +++ b/Source/kwsys/SystemInformation.hxx.in @@ -56,6 +56,9 @@ public: SystemInformation(); ~SystemInformation(); + SystemInformation(const SystemInformation&) = delete; + SystemInformation& operator=(const SystemInformation&) = delete; + const char* GetVendorString(); const char* GetVendorID(); std::string GetTypeID(); diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index cbdfe11..33a92e4 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -416,6 +416,9 @@ public: { } ~Free() { free(const_cast<envchar*>(this->Env)); } + + Free(const Free&) = delete; + Free& operator=(const Free&) = delete; }; const envchar* Release(const envchar* env) @@ -473,7 +476,7 @@ void SystemTools::GetPath(std::vector<std::string>& path, const char* env) } // A hack to make the below algorithm work. - if (!pathEnv.empty() && *pathEnv.rbegin() != pathSep) { + if (!pathEnv.empty() && pathEnv.back() != pathSep) { pathEnv += pathSep; } std::string::size_type start = 0; @@ -1943,7 +1946,7 @@ void SystemTools::ConvertToUnixSlashes(std::string& path) // a single / pathCString = path.c_str(); size_t size = path.size(); - if (size > 1 && *path.rbegin() == '/') { + if (size > 1 && path.back() == '/') { // if it is c:/ then do not remove the trailing slash if (!((size == 3 && pathCString[1] == ':'))) { path.resize(size - 1); @@ -2692,7 +2695,7 @@ std::string SystemTools::FindName(const std::string& name, for (std::vector<std::string>::iterator i = path.begin(); i != path.end(); ++i) { std::string& p = *i; - if (p.empty() || *p.rbegin() != '/') { + if (p.empty() || p.back() != '/') { p += "/"; } } @@ -2810,7 +2813,7 @@ std::string SystemTools::FindProgram(const std::string& name, for (std::vector<std::string>::iterator i = path.begin(); i != path.end(); ++i) { std::string& p = *i; - if (p.empty() || *p.rbegin() != '/') { + if (p.empty() || p.back() != '/') { p += "/"; } } @@ -2888,7 +2891,7 @@ std::string SystemTools::FindLibrary(const std::string& name, for (std::vector<std::string>::iterator i = path.begin(); i != path.end(); ++i) { std::string& p = *i; - if (p.empty() || *p.rbegin() != '/') { + if (p.empty() || p.back() != '/') { p += "/"; } } @@ -3234,10 +3237,10 @@ void SystemTools::AddTranslationPath(const std::string& a, if (SystemTools::FileIsFullPath(path_b) && path_b.find("..") == std::string::npos) { // Before inserting make sure path ends with '/' - if (!path_a.empty() && *path_a.rbegin() != '/') { + if (!path_a.empty() && path_a.back() != '/') { path_a += '/'; } - if (!path_b.empty() && *path_b.rbegin() != '/') { + if (!path_b.empty() && path_b.back() != '/') { path_b += '/'; } if (!(path_a == path_b)) { @@ -3446,7 +3449,7 @@ std::string SystemTools::RelativePath(const std::string& local, // between each entry that does not already have one for (std::vector<std::string>::iterator vit1 = finalPath.begin(); vit1 != finalPath.end(); ++vit1) { - if (!relativePath.empty() && *relativePath.rbegin() != '/') { + if (!relativePath.empty() && relativePath.back() != '/') { relativePath += "/"; } relativePath += *vit1; @@ -3648,7 +3651,7 @@ void SystemTools::SplitPath(const std::string& p, } #endif if (!homedir.empty() && - (*homedir.rbegin() == '/' || *homedir.rbegin() == '\\')) { + (homedir.back() == '/' || homedir.back() == '\\')) { homedir.resize(homedir.size() - 1); } SystemTools::SplitPath(homedir, components); @@ -4016,7 +4019,7 @@ bool SystemTools::LocateFileInDir(const char* filename, const char* dir, filename_dir = SystemTools::GetFilenamePath(filename_dir); filename_dir_base = SystemTools::GetFilenameName(filename_dir); #if defined(_WIN32) - if (filename_dir_base.empty() || *filename_dir_base.rbegin() == ':') + if (filename_dir_base.empty() || filename_dir_base.back() == ':') #else if (filename_dir_base.empty()) #endif @@ -4092,7 +4095,7 @@ bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath) std::string tempPath = path; // create a buffer // if the path passed in has quotes around it, first remove the quotes - if (!path.empty() && path[0] == '"' && *path.rbegin() == '"') { + if (!path.empty() && path[0] == '"' && path.back() == '"') { tempPath = path.substr(1, path.length() - 2); } @@ -4169,7 +4172,7 @@ bool SystemTools::GetLineFromStream(std::istream& is, std::string& line, bool haveData = !line.empty() || !is.eof(); if (!line.empty()) { // Avoid storing a carriage return character. - if (*line.rbegin() == '\r') { + if (line.back() == '\r') { line.resize(line.size() - 1); } @@ -4307,7 +4310,7 @@ bool SystemTools::IsSubDirectory(const std::string& cSubdir, if (subdir.size() <= dir.size() || dir.empty()) { return false; } - bool isRootPath = *dir.rbegin() == '/'; // like "/" or "C:/" + bool isRootPath = dir.back() == '/'; // like "/" or "C:/" size_t expectedSlashPosition = isRootPath ? dir.size() - 1u : dir.size(); if (subdir[expectedSlashPosition] != '/') { return false; diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 1967860..33b579f 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -54,6 +54,9 @@ class @KWSYS_NAMESPACE@_EXPORT SystemToolsManager public: SystemToolsManager(); ~SystemToolsManager(); + + SystemToolsManager(const SystemToolsManager&) = delete; + SystemToolsManager& operator=(const SystemToolsManager&) = delete; }; // This instance will show up in any translation unit that uses diff --git a/Source/kwsys/hashtable.hxx.in b/Source/kwsys/hashtable.hxx.in index fc0d60e..0981c66 100644 --- a/Source/kwsys/hashtable.hxx.in +++ b/Source/kwsys/hashtable.hxx.in @@ -73,7 +73,7 @@ struct _Hashtable_node void public_method_to_quiet_warning_about_all_methods_private(); private: - void operator=(_Hashtable_node<_Val> const&); // poison node assignment + void operator=(_Hashtable_node<_Val> const&) = delete; }; template <class _Val, class _Key, class _HashFcn, class _ExtractKey, diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index b77d729..cfd5666 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -136,42 +136,6 @@ int main() } #endif -#ifdef TEST_KWSYS_LFS_WORKS -/* Return 0 when LFS is available and 1 otherwise. */ -# define _LARGEFILE_SOURCE -# define _LARGEFILE64_SOURCE -# define _LARGE_FILES -# define _FILE_OFFSET_BITS 64 -# include <sys/types.h> - -# include <assert.h> -# include <sys/stat.h> -# if KWSYS_CXX_HAS_CSTDIO -# include <cstdio> -# endif -# include <stdio.h> - -int main(int, char** argv) -{ -/* check that off_t can hold 2^63 - 1 and perform basic operations... */ -# define OFF_T_64 (((off_t)1 << 62) - 1 + ((off_t)1 << 62)) - if (OFF_T_64 % 2147483647 != 1) - return 1; - - // stat breaks on SCO OpenServer - struct stat buf; - stat(argv[0], &buf); - if (!S_ISREG(buf.st_mode)) - return 2; - - FILE* file = fopen(argv[0], "r"); - off_t offset = ftello(file); - fseek(file, offset, SEEK_CUR); - fclose(file); - return 0; -} -#endif - #ifdef TEST_KWSYS_CXX_HAS_SETENV # include <stdlib.h> int main() @@ -212,12 +176,6 @@ int main() #endif #ifdef TEST_KWSYS_CXX_HAS_RLIMIT64 -# if defined(KWSYS_HAS_LFS) -# define _LARGEFILE_SOURCE -# define _LARGEFILE64_SOURCE -# define _LARGE_FILES -# define _FILE_OFFSET_BITS 64 -# endif # include <sys/resource.h> int main() { diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt index f6a9153..91f7e25 100644 --- a/Tests/CMakeLib/CMakeLists.txt +++ b/Tests/CMakeLib/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories( set(CMakeLib_TESTS testGeneratedFileStream.cxx testRST.cxx + testRange.cxx testString.cxx testSystemTools.cxx testUTF8.cxx diff --git a/Tests/CMakeLib/testRange.cxx b/Tests/CMakeLib/testRange.cxx new file mode 100644 index 0000000..5ae805f --- /dev/null +++ b/Tests/CMakeLib/testRange.cxx @@ -0,0 +1,45 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#include "cmRange.h" + +#include <iostream> +#include <string> +#include <vector> + +#define ASSERT_TRUE(x) \ + do { \ + if (!(x)) { \ + std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \ + return false; \ + } \ + } while (false) + +int testRange(int /*unused*/, char* /*unused*/ []) +{ + std::vector<int> const testData = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + ASSERT_TRUE(!cmMakeRange(testData).empty()); + ASSERT_TRUE(cmMakeRange(testData).size() == 10); + + ASSERT_TRUE(!cmMakeRange(testData).advance(5).empty()); + ASSERT_TRUE(cmMakeRange(testData).advance(5).size() == 5); + + ASSERT_TRUE(cmMakeRange(testData).advance(5).retreat(5).empty()); + ASSERT_TRUE(cmMakeRange(testData).advance(5).retreat(5).size() == 0); + + ASSERT_TRUE(cmMakeRange(testData).any_of([](int n) { return n % 3 == 0; })); + ASSERT_TRUE(cmMakeRange(testData).all_of([](int n) { return n < 11; })); + ASSERT_TRUE(cmMakeRange(testData).none_of([](int n) { return n > 11; })); + + std::vector<int> const evenData = { 2, 4, 6, 8, 10 }; + ASSERT_TRUE(cmMakeRange(testData).filter([](int n) { return n % 2 == 0; }) == + cmMakeRange(evenData)); + + std::vector<std::string> const stringRange = { "1", "2", "3", "4", "5" }; + ASSERT_TRUE(cmMakeRange(testData) + .transform([](int n) { return std::to_string(n); }) + .retreat(5) == cmMakeRange(stringRange)); + + return 0; +} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 6c888cc..1b5ed03 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -459,7 +459,7 @@ if(BUILD_TESTING) set(runCxxDialectTest 1) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL Clang - AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) + AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4 AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") if(NOT APPLE OR POLICY CMP0025) set(runCxxDialectTest 1) endif() @@ -1413,6 +1413,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindCURL) endif() + if(CMake_TEST_FindCups) + add_subdirectory(FindCups) + endif() + if(CMake_TEST_FindDoxygen) add_subdirectory(FindDoxygen) endif() @@ -1494,10 +1498,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindODBC) endif() - if(CMake_TEST_FindOctave) - add_subdirectory(FindOctave) - endif() - if(CMake_TEST_FindOpenCL) add_subdirectory(FindOpenCL) endif() @@ -3268,12 +3268,14 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --output-log "${CMake_BINARY_DIR}/Tests/CTestTest/testOutput.log" ) - configure_file("${CMake_SOURCE_DIR}/Tests/CTestTest2/test.cmake.in" - "${CMake_BINARY_DIR}/Tests/CTestTest2/test.cmake" @ONLY ESCAPE_QUOTES) - add_test(CTestTest2 ${CMAKE_CTEST_COMMAND} - -S "${CMake_BINARY_DIR}/Tests/CTestTest2/test.cmake" -V - --output-log "${CMake_BINARY_DIR}/Tests/CTestTest2/testOutput.log" - ) + if(NOT CMake_TEST_EXTERNAL_CMAKE) + configure_file("${CMake_SOURCE_DIR}/Tests/CTestTest2/test.cmake.in" + "${CMake_BINARY_DIR}/Tests/CTestTest2/test.cmake" @ONLY ESCAPE_QUOTES) + add_test(CTestTest2 ${CMAKE_CTEST_COMMAND} + -S "${CMake_BINARY_DIR}/Tests/CTestTest2/test.cmake" -V + --output-log "${CMake_BINARY_DIR}/Tests/CTestTest2/testOutput.log" + ) + endif() if("${CMAKE_GENERATOR}" MATCHES "Makefiles" OR "${CMAKE_GENERATOR}" MATCHES "Ninja") configure_file("${CMake_SOURCE_DIR}/Tests/CTestTestLaunchers/test.cmake.in" @@ -3305,11 +3307,13 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT}) endif () - get_test_property(CTestTest2 TIMEOUT PREVIOUS_TIMEOUT) - if ("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND) - set_tests_properties ( CTestTest2 - PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT}) - endif () + if(NOT CMake_TEST_EXTERNAL_CMAKE) + get_test_property(CTestTest2 TIMEOUT PREVIOUS_TIMEOUT) + if("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND) + set_tests_properties ( CTestTest2 + PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT}) + endif() + endif() endif () if(CMake_TEST_EXTERNAL_CMAKE) @@ -3373,6 +3377,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --build-options ${build_options} -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM} -DCMake_TEST_Fortran_SUBMODULES:BOOL=${CMake_TEST_Fortran_SUBMODULES} + ${CMake_TEST_FortranModules_BUILD_OPTIONS} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranModules") endif() diff --git a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt index 9be69f1..1f9d3ac 100644 --- a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt @@ -57,7 +57,7 @@ else() message("Unhandled Platform") endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") check_cxx_compiler_flag("-x c++" HAVE_X_CXX) if(NOT HAVE_X_CXX) message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++' check failed") diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index b0bc656..6ccdcc3 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -338,11 +338,11 @@ else() add_executable(CompileFeaturesGenex2 genex_test.cpp) target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_std_11) - target_compile_definitions(CompileFeaturesGenex2 PRIVATE ${genex_test_defs}) + target_compile_definitions(CompileFeaturesGenex2 PRIVATE ${genex_test_defs} ALLOW_LATER_STANDARDS=1) add_library(std_11_iface INTERFACE) target_compile_features(std_11_iface INTERFACE cxx_std_11) add_executable(CompileFeaturesGenex3 genex_test.cpp) target_link_libraries(CompileFeaturesGenex3 PRIVATE std_11_iface) - target_compile_definitions(CompileFeaturesGenex3 PRIVATE ${genex_test_defs}) + target_compile_definitions(CompileFeaturesGenex3 PRIVATE ${genex_test_defs} ALLOW_LATER_STANDARDS=1) endif() diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp index 59f9006..4539789 100644 --- a/Tests/CompileFeatures/genex_test.cpp +++ b/Tests/CompileFeatures/genex_test.cpp @@ -15,10 +15,10 @@ # if !HAVE_CXX_STD_11 # error HAVE_CXX_STD_11 is false with CXX_STANDARD == 11 # endif -# if HAVE_CXX_STD_14 +# if HAVE_CXX_STD_14 && !defined(ALLOW_LATER_STANDARDS) # error HAVE_CXX_STD_14 is true with CXX_STANDARD == 11 # endif -# if HAVE_CXX_STD_17 +# if HAVE_CXX_STD_17 && !defined(ALLOW_LATER_STANDARDS) # error HAVE_CXX_STD_17 is true with CXX_STANDARD == 11 # endif #endif diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 811fff3..b5df961 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -407,7 +407,7 @@ endforeach() unset(_configs) if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4) - OR CMAKE_C_COMPILER_ID STREQUAL Clang) + OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")) AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja")) include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test) diff --git a/Tests/FindOctave/CMakeLists.txt b/Tests/FindCups/CMakeLists.txt index 1acc966..5be1ac1 100644 --- a/Tests/FindOctave/CMakeLists.txt +++ b/Tests/FindCups/CMakeLists.txt @@ -1,10 +1,10 @@ -add_test(NAME FindOctave.Test COMMAND +add_test(NAME FindCups.Test COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --build-and-test - "${CMake_SOURCE_DIR}/Tests/FindOctave/Test" - "${CMake_BINARY_DIR}/Tests/FindOctave/Test" + "${CMake_SOURCE_DIR}/Tests/FindCups/Test" + "${CMake_BINARY_DIR}/Tests/FindCups/Test" ${build_generator_args} - --build-project TestFindOctave + --build-project FindCups --build-options ${build_options} --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) diff --git a/Tests/FindCups/Test/CMakeLists.txt b/Tests/FindCups/Test/CMakeLists.txt new file mode 100644 index 0000000..9e90553 --- /dev/null +++ b/Tests/FindCups/Test/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.10) +project(TestFindCups C) +include(CTest) + +find_package(Cups REQUIRED) + +add_definitions(-DCMAKE_EXPECTED_CUPS_VERSION="${CUPS_VERSION_STRING}") + +add_executable(test_tgt main.c) +target_link_libraries(test_tgt Cups::Cups) +add_test(NAME test_tgt COMMAND test_tgt) + +add_executable(test_var main.c) +target_include_directories(test_var PRIVATE ${CUPS_INCLUDE_DIRS}) +target_link_libraries(test_var PRIVATE ${CUPS_LIBRARIES}) +add_test(NAME test_var COMMAND test_var) diff --git a/Tests/FindCups/Test/main.c b/Tests/FindCups/Test/main.c new file mode 100644 index 0000000..b69d621 --- /dev/null +++ b/Tests/FindCups/Test/main.c @@ -0,0 +1,12 @@ +#include <cups/cups.h> + +int main() +{ + int num_options = 0; + cups_option_t* options = NULL; + + num_options = cupsAddOption(CUPS_COPIES, "1", num_options, &options); + cupsFreeOptions(num_options, options); + + return 0; +} diff --git a/Tests/FindOctave/Test/CMakeLists.txt b/Tests/FindOctave/Test/CMakeLists.txt deleted file mode 100644 index 73aa831..0000000 --- a/Tests/FindOctave/Test/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -cmake_minimum_required(VERSION 3.3) -project(TestFindOctave CXX) -enable_testing() - -find_package(Octave REQUIRED COMPONENTS Development Interpreter) - -add_definitions(-DCMAKE_EXPECTED_Octave_VERSION=${Octave_VERSION}) - -add_executable(test_tgt main.cpp) -target_link_libraries(test_tgt Octave::Octave) -add_test(NAME test_tgt COMMAND test_tgt) - -add_executable(test_octinterp_tgt interp_main.cpp) -target_link_libraries(test_octinterp_tgt Octave::Octinterp) -add_test(NAME test_octinterp_tgt COMMAND test_octinterp_tgt) - -add_test(NAME test_tgt_exe - COMMAND Octave::Interpreter -q --eval "runtests('.')" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - -add_executable(test_var main.cpp) -target_include_directories(test_var PRIVATE ${Octave_INCLUDE_DIRS}) -target_link_libraries(test_var PRIVATE ${Octave_LIBRARIES}) -add_test(NAME test_var COMMAND test_var) diff --git a/Tests/FindOctave/Test/interp_main.cpp b/Tests/FindOctave/Test/interp_main.cpp deleted file mode 100644 index 1efa187..0000000 --- a/Tests/FindOctave/Test/interp_main.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include <iostream> -#include <oct.h> -#include <octave.h> -#include <parse.h> -#include <toplev.h> - -int main(void) -{ - string_vector argv(2); - argv(0) = "embedded"; - argv(1) = "-q"; - - try { - octave_main(2, argv.c_str_vec(), 1); - octave_value_list in; - in(0) = 72.0; - const octave_value_list result = feval("sqrt", in); - std::cout << "result is " << result(0).scalar_value() << std::endl; - clean_up_and_exit(0); - } catch (const octave::exit_exception& ex) { - std::cerr << "Octave interpreter exited with status = " << ex.exit_status() - << std::endl; - } catch (const octave::execution_exception&) { - std::cerr << "error encountered in Octave evaluator!" << std::endl; - } -} diff --git a/Tests/FindOctave/Test/main.cpp b/Tests/FindOctave/Test/main.cpp deleted file mode 100644 index 68270b1..0000000 --- a/Tests/FindOctave/Test/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include <iostream> -#include <oct.h> - -// http://www.dm.unibo.it/~achilles/calc/octave.html/Standalone-Programs.html -int main(void) -{ - int n = 2; - Matrix a_matrix = Matrix(n, n); - for (octave_idx_type i = 0; i < n; i++) { - for (octave_idx_type j = 0; j < n; j++) { - a_matrix(i, j) = (i + 1) * 10 + (j + 1); - } - } - - std::cout << a_matrix << std::endl; - - return EXIT_SUCCESS; -} diff --git a/Tests/FindOctave/Test/testtrue.m b/Tests/FindOctave/Test/testtrue.m deleted file mode 100644 index 0c28a9e..0000000 --- a/Tests/FindOctave/Test/testtrue.m +++ /dev/null @@ -1 +0,0 @@ -%!assert(true) diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index 7023615..929fa4d 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -46,7 +46,7 @@ function(test_fortran_c_interface_module) FortranCInterface_VERIFY() FortranCInterface_VERIFY(CXX) if(CMAKE_Fortran_COMPILER_SUPPORTS_F90) - if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro|PathScale|Absoft") + if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|PathScale|Absoft") set(module_expected 1) endif() if(FortranCInterface_MODULE_FOUND OR module_expected) diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt index b7b8320..761c405 100644 --- a/Tests/IncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.6) 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 OR CMAKE_C_COMPILER_ID STREQUAL AppleClang) + OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") OR CMAKE_C_COMPILER_ID STREQUAL AppleClang) AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja" OR (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT XCODE_VERSION VERSION_LESS 6.0))) diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt index 45bb229..b584e16 100644 --- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt +++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt @@ -61,7 +61,7 @@ if (C_expected_features) string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_C_COMPILER_VERSION}") if (CMAKE_C_COMPILER_ID STREQUAL "GNU" - OR CMAKE_C_COMPILER_ID STREQUAL "Clang" + OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_C_COMPILER_ID STREQUAL "Intel") add_executable(WriteCompilerDetectionHeader_C11 main.c) @@ -118,7 +118,7 @@ string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" COMPILER_VERSION_MINO string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_CXX_COMPILER_VERSION}") if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" - OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" + OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "SunPro" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") @@ -128,7 +128,8 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" endif() # for msvc the compiler version determines which c++11 features are available. -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" + OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")) if(";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;") list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) diff --git a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt index f4b726f..9b32e59 100644 --- a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt +++ b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt @@ -5,10 +5,48 @@ include("../AutogenCoreTest.cmake") # Dummy executable to generate a clean target add_executable(dummy dummy.cpp) -set(timeformat "%Y%j%H%M%S") +# Utility variables +set(timeformat "%Y.%j.%H.%M%S") set(mocBasicSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocBasic") set(mocBasicBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocBasic") +# Utility macros +macro(sleep) + message(STATUS "Sleeping for a few seconds.") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +endmacro() + +macro(acquire_timestamp When) + file(TIMESTAMP "${mocBasicBin}" time${When} "${timeformat}") +endmacro() + +macro(rebuild buildName) + message(STATUS "Starting build ${buildName}.") + execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result) + if (result) + message(FATAL_ERROR "Build ${buildName} failed.") + else() + message(STATUS "Build ${buildName} finished.") + endif() +endmacro() + +macro(require_change) + if (timeAfter VERSION_GREATER timeBefore) + message(STATUS "As expected the file ${mocBasicBin} changed.") + else() + message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} did not change!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n") + endif() +endmacro() + +macro(require_change_not) + if (timeAfter VERSION_GREATER timeBefore) + message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} changed!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n") + else() + message(STATUS "As expected the file ${mocBasicBin} did not change.") + endif() +endmacro() + + # Initial build configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY) try_compile(MOC_RERUN @@ -21,46 +59,44 @@ try_compile(MOC_RERUN OUTPUT_VARIABLE output ) if (NOT MOC_RERUN) - message(SEND_ERROR "Initial build of mocBasic failed. Output: ${output}") + message(FATAL_ERROR "Initial build of mocBasic failed. Output: ${output}") endif() + # Get name of the output binary file(STRINGS "${mocBasicBinDir}/mocBasic.txt" mocBasicList ENCODING UTF-8) list(GET mocBasicList 0 mocBasicBin) -message("Changing the header content for a MOC rerun") -# - Acquire binary timestamps before the build -file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}") +# To avoid a race condition where the binary has the same timestamp +# as a source file and therefore gets rebuild +# - sleep to ensure a timestamp change +# - touch binary to ensure it has a new timestamp +acquire_timestamp(Before) +sleep() +message(STATUS "Touching binary file to ensure a new timestamps") +file(TOUCH_NOCREATE "${mocBasicBin}") +acquire_timestamp(After) +require_change() + + # - Ensure that the timestamp will change -# - Change header file content and rebuild +# - Change header file content # - Rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamp(Before) +sleep() +message(STATUS "Changing the header content for a MOC re-run") configure_file("${mocBasicSrcDir}/test1b.h.in" "${mocBasicBinDir}/test1.h" COPYONLY) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result ) -if (result) - message(SEND_ERROR "Second build of mocBasic failed.") -endif() -# - Acquire binary timestamps after the build -file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}") -# - Test if timestamps changed -if (NOT timeAfter GREATER timeBefore) - message(SEND_ERROR "File (${mocBasicBin}) should have changed!") -endif() +sleep() +rebuild(2) +acquire_timestamp(After) +require_change() -message("Changing nothing for a MOC rerun") -# - Acquire binary timestamps before the build -file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}") # - Ensure that the timestamp would change # - Change nothing # - Rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result ) -if (result) - message(SEND_ERROR "Third build of mocBasic failed.") -endif() -# - Acquire binary timestamps after the build -file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}") -# - Test if timestamps changed -if (timeAfter GREATER timeBefore) - message(SEND_ERROR "File (${mocBasicBin}) should not have changed!") -endif() +acquire_timestamp(Before) +sleep() +message(STATUS "Changing nothing for no MOC re-run") +rebuild(3) +acquire_timestamp(After) +require_change_not() diff --git a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt index b83e994..e1951f1 100644 --- a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt +++ b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt @@ -9,10 +9,53 @@ include("../AutogenCoreTest.cmake") add_executable(dummy dummy.cpp) # Utility variables -set(timeformat "%Y%j%H%M%S") +set(timeformat "%Y.%j.%H.%M%S") set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocPlugin") set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocPlugin") +# Utility macros +macro(sleep) + message(STATUS "Sleeping for a few seconds.") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +endmacro() + +macro(rebuild buildName) + message(STATUS "Starting build ${buildName}.") + execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}" RESULT_VARIABLE result) + if (result) + message(FATAL_ERROR "Build ${buildName} failed.") + else() + message(STATUS "Build ${buildName} finished.") + endif() +endmacro() + +macro(require_change PLG) + if (pl${PLG}After VERSION_GREATER pl${PLG}Before) + message(STATUS "As expected the file ${pl${PLG}File} changed.") + else() + message(SEND_ERROR + "Unexpectedly the file ${pl${PLG}File} did not change!\nTimestamp pre: ${pl${PLG}Before}\nTimestamp aft: ${pl${PLG}After}\n") + endif() +endmacro() + +macro(require_change_not PLG) + if (pl${PLG}After VERSION_GREATER pl${PLG}Before) + message(SEND_ERROR + "Unexpectedly the file ${pl${PLG}File} changed!\nTimestamp pre: ${pl${PLG}Before}\nTimestamp aft: ${pl${PLG}After}\n") + else() + message(STATUS "As expected the file ${pl${PLG}File} did not change.") + endif() +endmacro() + +macro(acquire_timestamps When) + file(TIMESTAMP "${plAFile}" plA${When} "${timeformat}") + file(TIMESTAMP "${plBFile}" plB${When} "${timeformat}") + file(TIMESTAMP "${plCFile}" plC${When} "${timeformat}") + file(TIMESTAMP "${plDFile}" plD${When} "${timeformat}") + file(TIMESTAMP "${plEFile}" plE${When} "${timeformat}") +endmacro() + + # Initial build try_compile(MOC_PLUGIN "${mocPlugBinDir}" @@ -24,83 +67,68 @@ try_compile(MOC_PLUGIN OUTPUT_VARIABLE output ) if (NOT MOC_PLUGIN) - message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}") + message(FATAL_ERROR "Initial build of mocPlugin failed. Output: ${output}") endif() +# Get names of the output binaries find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plEFile "PlugE" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) +# To avoid a race condition where the library has the same timestamp +# as a source file and therefore gets rebuild +# - sleep to ensure a timestamp change +# - rebuild library to ensure it has a new timestamp +sleep() +message(STATUS "Rebuilding library files to ensure new timestamps") +rebuild(1) + + # - Ensure that the timestamp will change. # - Change the json files referenced by Q_PLUGIN_METADATA # - Rebuild -file(TIMESTAMP "${plAFile}" plABefore "${timeformat}") -file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}") -file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") -file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") -file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}") - -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing json files.") configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/StyleE.json") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") - -file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}") -file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}") -file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") -file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") -file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}") - -if (plAAfter GREATER plABefore) - message(SEND_ERROR "file (${plAFile}) should not have changed!") -endif() -if (plBAfter GREATER plBBefore) - message(SEND_ERROR "file (${plBFile}) should not have changed!") -endif() -if (NOT plCAfter GREATER plCBefore) - message(SEND_ERROR "file (${plCFile}) should have changed!") -endif() -if (NOT plDAfter GREATER plDBefore) - message(SEND_ERROR "file (${plDFile}) should have changed!") -endif() -if (NOT plEAfter GREATER plEBefore) - # There's a bug in Ninja on Windows - # https://gitlab.kitware.com/cmake/cmake/issues/16776 - if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) - message(SEND_ERROR "file (${plEFile}) should have changed!") - endif() +sleep() +rebuild(2) +acquire_timestamps(After) +# Test changes +require_change_not(A) +require_change_not(B) +require_change(C) +require_change(D) +# There's a bug in Ninja on Windows: +# https://gitlab.kitware.com/cmake/cmake/issues/16776 +if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) + require_change(E) endif() + # - Ensure that the timestamp will change. # - Change the json files referenced by A_CUSTOM_MACRO # - Rebuild -file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") -file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") -file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}") - -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing json files") configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleE_Custom.json") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") - -file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") -file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") -file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}") - -if (NOT plCAfter GREATER plCBefore) - message(SEND_ERROR "file (${plCFile}) should have changed!") -endif() -if (NOT plDAfter GREATER plDBefore) - message(SEND_ERROR "file (${plDFile}) should have changed!") -endif() -if (NOT plEAfter GREATER plEBefore) - # There's a bug in Ninja on Windows - # https://gitlab.kitware.com/cmake/cmake/issues/16776 - if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) - message(SEND_ERROR "file (${plEFile}) should have changed!") - endif() +sleep() +rebuild(3) +acquire_timestamps(After) +# Test changes +require_change_not(A) +require_change_not(B) +require_change(C) +require_change(D) +# There's a bug in Ninja on Windows +# https://gitlab.kitware.com/cmake/cmake/issues/16776 +if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) + require_change(E) endif() diff --git a/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt b/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt index dcb7a79..33c01ac 100644 --- a/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt +++ b/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt @@ -9,10 +9,23 @@ add_executable(dummy dummy.cpp) # When a .qrc or a file listed in a .qrc file changes, # the target must be rebuilt -set(timeformat "%Y%j%H%M%S") set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/RccConfigChange") set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/RccConfigChange") +# Rebuild macro +macro(rebuild CFG) + message(STATUS "Rebuilding rccConfigChange in ${CFG} configuration.") + execute_process( + COMMAND "${CMAKE_COMMAND}" --build . --config "${CFG}" + WORKING_DIRECTORY "${rccDepBD}" + RESULT_VARIABLE result) + if (result) + message(FATAL_ERROR "${CFG} build of rccConfigChange failed.") + else() + message(STATUS "${CFG} build of rccConfigChange finished.") + endif() +endmacro() + # Initial build try_compile(RCC_DEPENDS "${rccDepBD}" @@ -24,19 +37,11 @@ try_compile(RCC_DEPENDS OUTPUT_VARIABLE output ) if (NOT RCC_DEPENDS) - message(SEND_ERROR "Initial build of rccConfigChange failed. Output: ${output}") + message(FATAL_ERROR "Initial build of rccConfigChange failed. Output: ${output}") endif() -# - Rebuild Release -message("Rebuilding rccConfigChange in Release configuration") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Release WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Release build of rccConfigChange failed.") -endif() +# Rebuild: Release +rebuild(Release) -# - Rebuild Debug -message("Rebuilding rccConfigChange in Debug configuration") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Debug WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Debug build of rccConfigChange failed.") -endif() +# Rebuild: Debug +rebuild(Debug) diff --git a/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt b/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt index 80c5cf0..1301550 100644 --- a/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt +++ b/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt @@ -3,19 +3,63 @@ project(RerunRccDepends) include("../AutogenCoreTest.cmake") # Tests rcc rebuilding when a resource file changes +# When a .qrc or a file listed in a .qrc file changes, +# the target must be rebuilt # Dummy executable to generate a clean target add_executable(dummy dummy.cpp) -# When a .qrc or a file listed in a .qrc file changes, -# the target must be rebuilt -set(timeformat "%Y%j%H%M%S") +# Utility variables +set(timeformat "%Y.%j.%H.%M%S") set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/RccDepends") set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/RccDepends") -# Initial build +# Utility macros +macro(sleep) + message(STATUS "Sleeping for a few seconds.") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +endmacro() + +macro(acquire_timestamps When) + file(TIMESTAMP "${rccDepBinPlain}" rdPlain${When} "${timeformat}") + file(TIMESTAMP "${rccDepBinGenerated}" rdGenerated${When} "${timeformat}") +endmacro() + +macro(rebuild buildName) + message(STATUS "Starting build ${buildName} of rccDepends.") + execute_process( + COMMAND "${CMAKE_COMMAND}" --build . + WORKING_DIRECTORY "${rccDepBD}" + RESULT_VARIABLE result) + if (result) + message(FATAL_ERROR "Build ${buildName} of rccDepends failed.") + else() + message(STATUS "Build ${buildName} of rccDepends finished.") + endif() +endmacro() + +macro(require_change type) + if (rd${type}After VERSION_GREATER rd${type}Before) + message(STATUS "As expected the ${type} .qrc file ${rccDepBin${type}} changed.") + else() + message(SEND_ERROR "Unexpectedly the ${type} .qrc file ${rccDepBin${type}} did not change!\nTimestamp pre: ${rd${type}Before}\nTimestamp aft: ${rd${type}After}\n") + endif() +endmacro() + +macro(require_change_not type) + if (rd${type}After VERSION_GREATER rd${type}Before) + message(SEND_ERROR "Unexpectedly the ${type} .qrc file ${rccDepBin${type}} changed!\nTimestamp pre: ${rd${type}Before}\nTimestamp aft: ${rd${type}After}\n") + else() + message(STATUS "As expected the ${type} .qrc file ${rccDepBin${type}} did not change.") + endif() +endmacro() + + +# Initial configuration configure_file(${rccDepSD}/resPlainA.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY) configure_file(${rccDepSD}/resGenA.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY) + +# Initial build try_compile(RCC_DEPENDS "${rccDepBD}" "${rccDepSD}" @@ -26,113 +70,84 @@ try_compile(RCC_DEPENDS OUTPUT_VARIABLE output ) if (NOT RCC_DEPENDS) - message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}") + message(FATAL_ERROR "Initial build of rccDepends failed. Output: ${output}") endif() # Get name of the output binaries file(STRINGS "${rccDepBD}/targetPlain.txt" targetListPlain ENCODING UTF-8) file(STRINGS "${rccDepBD}/targetGen.txt" targetListGen ENCODING UTF-8) list(GET targetListPlain 0 rccDepBinPlain) -list(GET targetListGen 0 rccDepBinGen) -message("Target that uses a plain .qrc file is:\n ${rccDepBinPlain}") -message("Target that uses a GENERATED .qrc file is:\n ${rccDepBinGen}") +list(GET targetListGen 0 rccDepBinGenerated) +message(STATUS "Target that uses a plain .qrc file is:\n ${rccDepBinPlain}") +message(STATUS "Target that uses a GENERATED .qrc file is:\n ${rccDepBinGenerated}") + +# To avoid a race condition where the binary has the same timestamp +# as a source file and therefore gets rebuild +# - sleep to ensure a timestamp change +# - touch binary to ensure it has a new timestamp +acquire_timestamps(Before) +sleep() +message(STATUS "Touching binary files to ensure new timestamps") +file(TOUCH_NOCREATE "${rccDepBinPlain}" "${rccDepBinGenerated}") +acquire_timestamps(After) +require_change(Plain) +require_change(Generated) -message("Changing a resource files listed in the .qrc file") -# - Acquire binary timestamps before the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}") # - Ensure that the timestamp will change # - Change a resource files listed in the .qrc file # - Rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing a resource file listed in the .qrc file") file(TOUCH "${rccDepBD}/resPlain/input.txt" "${rccDepBD}/resGen/input.txt") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Second build of rccDepends failed.") -endif() -# - Acquire binary timestamps after the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}") +sleep() +rebuild(2) +acquire_timestamps(After) # - Test if timestamps changed -if (NOT rdPlainAfter GREATER rdPlainBefore) - message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!") -endif() -if (NOT rdGenAfter GREATER rdGenBefore) - message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!") -endif() +require_change(Plain) +require_change(Generated) -message("Changing the .qrc file") -# - Acquire binary timestamps before the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}") # - Ensure that the timestamp will change # - Change the .qrc file # - Rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing the .qrc file") configure_file(${rccDepSD}/resPlainB.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY) configure_file(${rccDepSD}/resGenB.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Third build of rccDepends failed.") -endif() -# - Acquire binary timestamps after the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}") +sleep() +rebuild(3) +acquire_timestamps(After) # - Test if timestamps changed -if (NOT rdPlainAfter GREATER rdPlainBefore) - message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!") -endif() -if (NOT rdGenAfter GREATER rdGenBefore) - message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!") -endif() +require_change(Plain) +require_change(Generated) -message("Changing a newly added resource files listed in the .qrc file") -# - Acquire binary timestamps before the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}") # - Ensure that the timestamp will change # - Change a newly added resource files listed in the .qrc file # - Rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing a newly added resource file listed in the .qrc file") file(TOUCH "${rccDepBD}/resPlain/inputAdded.txt" "${rccDepBD}/resGen/inputAdded.txt") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Fourth build of rccDepends failed.") -endif() -# - Acquire binary timestamps after the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}") +sleep() +rebuild(4) +acquire_timestamps(After) # - Test if timestamps changed -if (NOT rdPlainAfter GREATER rdPlainBefore) - message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!") -endif() -if (NOT rdGenAfter GREATER rdGenBefore) - message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!") -endif() +require_change(Plain) +require_change(Generated) -message("Changing nothing in the .qrc file") -# - Acquire binary timestamps before the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}") # - Ensure that the timestamp will change # - Change nothing # - Rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Fifth build of rccDepends failed.") -endif() -# - Acquire binary timestamps after the build -file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}") -file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}") +acquire_timestamps(Before) +sleep() +message(STATUS "Changing nothing in the .qrc file") +rebuild(5) +acquire_timestamps(After) # - Test if timestamps changed -if (rdPlainAfter GREATER rdPlainBefore) - message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should NOT have changed!") -endif() -if (rdGenAfter GREATER rdGenBefore) - message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should NOT have changed!") -endif() +require_change_not(Plain) +require_change_not(Generated) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 1f3e5c3..f2b7ff1 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -284,11 +284,11 @@ function(add_RunCMake_test_try_compile) if(CMAKE_VERSION VERSION_LESS 3.9.20170907 AND "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") # Older CMake versions do not know about MSVC language standards. # Approximate our logic from MSVC-CXX.cmake. - if ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0.24215.1 AND + if ((NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.24215.1 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) OR - CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10.25017) + NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10.25017) set(CMAKE_CXX_STANDARD_DEFAULT 14) - elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) + elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0) set(CMAKE_CXX_STANDARD_DEFAULT "") else() unset(CMAKE_CXX_STANDARD_DEFAULT) diff --git a/Tests/RunCMake/CMakeRoleGlobalProperty/Project.cmake b/Tests/RunCMake/CMakeRoleGlobalProperty/Project.cmake index c0b6a48..22cad2b 100644 --- a/Tests/RunCMake/CMakeRoleGlobalProperty/Project.cmake +++ b/Tests/RunCMake/CMakeRoleGlobalProperty/Project.cmake @@ -1,4 +1,8 @@ get_property(role GLOBAL PROPERTY CMAKE_ROLE) + +file(WRITE "${CMAKE_BINARY_DIR}/test.cmake" "# a") +include("${CMAKE_BINARY_DIR}/test.cmake") + if(NOT role STREQUAL "PROJECT") message(SEND_ERROR "CMAKE_ROLE property is \"${role}\", should be \"PROJECT\"") endif() diff --git a/Tests/RunCMake/CMakeRoleGlobalProperty/RunCMakeTest.cmake b/Tests/RunCMake/CMakeRoleGlobalProperty/RunCMakeTest.cmake index 3cbd51d..7b29c28 100644 --- a/Tests/RunCMake/CMakeRoleGlobalProperty/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakeRoleGlobalProperty/RunCMakeTest.cmake @@ -2,6 +2,9 @@ include(RunCMake) include(RunCTest) run_cmake(Project) +file(WRITE "${RunCMake_BINARY_DIR}/Project-build/test.cmake" "# b") +run_cmake_command(ProjectBuild "${CMAKE_COMMAND}" --build "${RunCMake_BINARY_DIR}/Project-build") + run_cmake_command(Script "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/Script.cmake") run_cmake_command(FindPackage "${CMAKE_COMMAND}" --find-package -DNAME=DummyPackage -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=EXIST "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}") run_ctest(CTest) diff --git a/Tests/RunCMake/ParseImplicitIncludeInfo/ParseImplicitIncludeInfo.cmake b/Tests/RunCMake/ParseImplicitIncludeInfo/ParseImplicitIncludeInfo.cmake index ce8d45b..869fe3d 100644 --- a/Tests/RunCMake/ParseImplicitIncludeInfo/ParseImplicitIncludeInfo.cmake +++ b/Tests/RunCMake/ParseImplicitIncludeInfo/ParseImplicitIncludeInfo.cmake @@ -10,6 +10,7 @@ project(Minimal NONE) # set(targets aix-C-XL-13.1.3 aix-CXX-XL-13.1.3 + aix-C-XLClang-16.1.0.1 aix-CXX-XLClang-16.1.0.1 craype-C-Cray-8.7 craype-CXX-Cray-8.7 craype-Fortran-Cray-8.7 craype-C-GNU-7.3.0 craype-CXX-GNU-7.3.0 craype-Fortran-GNU-7.3.0 craype-C-Intel-18.0.2.20180210 craype-CXX-Intel-18.0.2.20180210 diff --git a/Tests/RunCMake/ParseImplicitIncludeInfo/data/CMakeLists.txt b/Tests/RunCMake/ParseImplicitIncludeInfo/data/CMakeLists.txt index b854e2e..bffe819 100644 --- a/Tests/RunCMake/ParseImplicitIncludeInfo/data/CMakeLists.txt +++ b/Tests/RunCMake/ParseImplicitIncludeInfo/data/CMakeLists.txt @@ -12,6 +12,9 @@ # cmake_minimum_required(VERSION 3.3) +if(POLICY CMP0089) + cmake_policy(SET CMP0089 NEW) +endif() set(lngs C CXX) set(LANGUAGES "${lngs}" CACHE STRING "List of languages to generate inputs for") diff --git a/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-C-XLClang-16.1.0.1.input b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-C-XLClang-16.1.0.1.input new file mode 100644 index 0000000..2f018e6 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-C-XLClang-16.1.0.1.input @@ -0,0 +1,40 @@ +CMAKE_LANG=C +CMAKE_C_COMPILER_ABI= +CMAKE_C_COMPILER_AR= +CMAKE_C_COMPILER_ARCHITECTURE_ID= +CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_C_COMPILER_ID=XLClang +CMAKE_C_COMPILER_LAUNCHER= +CMAKE_C_COMPILER_LOADED=1 +CMAKE_C_COMPILER_RANLIB= +CMAKE_C_COMPILER_TARGET= +CMAKE_C_COMPILER_VERSION=16.1.0.1 +CMAKE_C_COMPILER_VERSION_INTERAL= +Change Dir: /tmp/ii/CMakeFiles/CMakeTmp + +Run Build Command(s):/usr/bin/gmake cmTC_fcf21/fast +/usr/bin/gmake -f CMakeFiles/cmTC_fcf21.dir/build.make CMakeFiles/cmTC_fcf21.dir/build +gmake[1]: Entering directory '/tmp/ii/CMakeFiles/CMakeTmp' +Building C object CMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o +/opt/IBM/xlC/16.1.0/bin/xlclang -V -o CMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o -c /tmp/CMake/Modules/CMakeCCompilerABI.c +export XL_CONFIG=/opt/IBM/xlc/16.1.0/etc/xlc.cfg.72:xlclang +export XL_ASMOBJFILES=/tmp/xlcASuz87id +export "XL_DIS=/opt/IBM/xlc/16.1.0/exe/dis -o "CMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o" "CMakeCCompilerABI.o"" +/opt/IBM/xlC/16.1.0/exe/xlC2entry -qosvar=aix.7.2 -qalias=ansi -qthreaded -D_THREAD_SAFE -Wno-parentheses -Wno-unused-value -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX50 -D_AIX51 -D_AIX52 -D_AIX53 -D_AIX61 -D_AIX71 -D_AIX72 -D_IBMR2 -D_POWER -xc -qasm_as=/bin/as -qc_stdinc=/opt/IBM/xlC/16.1.0/include2:/opt/IBM/xlC/16.1.0/include2/aix:/opt/IBM/xlmass/9.1.0/include:/usr/include -qvac_include_path=/opt/IBM/xlc/16.1.0/include -oCMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o /tmp/CMake/Modules/CMakeCCompilerABI.c /tmp/xlcW0tZ87ia /tmp/xlcW1ub87ib /dev/null /tmp/xlcLu487ieF.lst /dev/null /tmp/xlcW2uj87ic +export XL_BACKEND=/opt/IBM/xlc/16.1.0/exe/xlCcode +export XL_LINKER=/bin/ld +/opt/IBM/xlc/16.1.0/exe/xlCcode -qalias=ansi -qthreaded /tmp/xlcW0tZ87ia /tmp/xlcW1ub87ib CMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o /tmp/xlcLu487ieB.lst /tmp/xlcW2uj87ic +rm /tmp/xlcASuz87id +rm /tmp/xlcLu487ie +rm /tmp/xlcW0tZ87ia +rm /tmp/xlcW1ub87ib +rm /tmp/xlcW2uj87ic +Linking C executable cmTC_fcf21 +/tmp/CMake/bin/cmake -E cmake_link_script CMakeFiles/cmTC_fcf21.dir/link.txt --verbose=1 +/opt/IBM/xlC/16.1.0/bin/xlclang -Wl,-bnoipath -Wl,-brtl -V -Wl,-bexpall CMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o -o cmTC_fcf21 -Wl,-blibpath:/usr/lib:/lib +export XL_CONFIG=/opt/IBM/xlc/16.1.0/etc/xlc.cfg.72:xlclang +/bin/ld -b32 /lib/crt0.o -bpT:0x10000000 -bpD:0x20000000 -bnoipath -brtl -bexpall CMakeFiles/cmTC_fcf21.dir/CMakeCCompilerABI.c.o -o cmTC_fcf21 -blibpath:/usr/lib:/lib -L/opt/IBM/xlmass/9.1.0/lib/aix61 -L/opt/IBM/xlc/16.1.0/lib -lxlopt -lxlipa -lxl -lc -lpthreads +rm /tmp/xlcW0vJG7ia +rm /tmp/xlcW1vNG7ib +rm /tmp/xlcW2vRG7ic +gmake[1]: Leaving directory '/tmp/ii/CMakeFiles/CMakeTmp' diff --git a/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-C-XLClang-16.1.0.1.output b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-C-XLClang-16.1.0.1.output new file mode 100644 index 0000000..85399b7 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-C-XLClang-16.1.0.1.output @@ -0,0 +1 @@ +/opt/IBM/xlC/16.1.0/include2;/opt/IBM/xlC/16.1.0/include2/aix;/opt/IBM/xlmass/9.1.0/include;/usr/include diff --git a/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-CXX-XLClang-16.1.0.1.input b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-CXX-XLClang-16.1.0.1.input new file mode 100644 index 0000000..da16db3 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-CXX-XLClang-16.1.0.1.input @@ -0,0 +1,44 @@ +CMAKE_LANG=CXX +CMAKE_CXX_COMPILER_ABI= +CMAKE_CXX_COMPILER_AR= +CMAKE_CXX_COMPILER_ARCHITECTURE_ID= +CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_CXX_COMPILER_ID=XLClang +CMAKE_CXX_COMPILER_LAUNCHER= +CMAKE_CXX_COMPILER_LOADED=1 +CMAKE_CXX_COMPILER_RANLIB= +CMAKE_CXX_COMPILER_TARGET= +CMAKE_CXX_COMPILER_VERSION=16.1.0.1 +CMAKE_CXX_COMPILER_VERSION_INTERAL= +Change Dir: /tmp/ii/CMakeFiles/CMakeTmp + +Run Build Command(s):/usr/bin/gmake cmTC_b8490/fast +/usr/bin/gmake -f CMakeFiles/cmTC_b8490.dir/build.make CMakeFiles/cmTC_b8490.dir/build +gmake[1]: Entering directory '/tmp/ii/CMakeFiles/CMakeTmp' +Building CXX object CMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o +/opt/IBM/xlC/16.1.0/bin/xlclang++ -x c++ -V -o CMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o -c /tmp/CMake/Modules/CMakeCXXCompilerABI.cpp +export XL_CONFIG=/opt/IBM/xlc/16.1.0/etc/xlc.cfg.72:xlclang++ +export XL_XLCMP_PATH=/opt/IBM/xlc/16.1.0:/opt/IBM/xlC/16.1.0 +export XL_COMPILER=xlc++ +export XL_ASMOBJFILES=/tmp/xlcAS3IXqid +export "XL_DIS=/opt/IBM/xlc/16.1.0/exe/dis -o "CMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o" "CMakeCXXCompilerABI.o"" +/opt/IBM/xlC/16.1.0/exe/xlC2entry -qosvar=aix.7.2 -qalias=ansi -qthreaded -D_THREAD_SAFE -Wno-parentheses -Wno-unused-value -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX50 -D_AIX51 -D_AIX52 -D_AIX53 -D_AIX61 -D_AIX71 -D_AIX72 -D_IBMR2 -D_POWER -xc++ -qasm_as=/bin/as -qcpp_stdinc=/opt/IBM/xlC/16.1.0/include2/c++:/opt/IBM/xlC/16.1.0/include2:/opt/IBM/xlC/16.1.0/include2/aix:/opt/IBM/xlmass/9.1.0/include:/usr/include -qc_stdinc=/opt/IBM/xlC/16.1.0/include2:/opt/IBM/xlC/16.1.0/include2/aix:/opt/IBM/xlmass/9.1.0/include:/usr/include -oCMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o /tmp/CMake/Modules/CMakeCXXCompilerABI.cpp /tmp/xlcW03uXqia /tmp/xlcW137Xqib /dev/null /tmp/xlcL3QXqieF.lst /dev/null /tmp/xlcW23AXqic +export XL_BACKEND=/opt/IBM/xlc/16.1.0/exe/xlCcode +export XL_LINKER=/bin/ld +/opt/IBM/xlc/16.1.0/exe/xlCcode -qalias=ansi -qthreaded /tmp/xlcW03uXqia /tmp/xlcW137Xqib CMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o /tmp/xlcL3QXqieB.lst /tmp/xlcW23AXqic +rm /tmp/xlcAS3IXqid +rm /tmp/xlcL3QXqie +rm /tmp/xlcW03uXqia +rm /tmp/xlcW137Xqib +rm /tmp/xlcW23AXqic +Linking CXX executable cmTC_b8490 +/tmp/CMake/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b8490.dir/link.txt --verbose=1 +/opt/IBM/xlC/16.1.0/bin/xlclang++ -Wl,-bnoipath -Wl,-brtl -V -Wl,-bexpall CMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_b8490 -Wl,-blibpath:/usr/lib:/lib +export XL_CONFIG=/opt/IBM/xlc/16.1.0/etc/xlc.cfg.72:xlclang++ +/bin/ld -b32 /lib/crt0.o /lib/crti.o -bpT:0x10000000 -bpD:0x20000000 -bnoipath -brtl -bexpall CMakeFiles/cmTC_b8490.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_b8490 -blibpath:/usr/lib:/lib -bcdtors:all:0:s -btmplrename -L/opt/IBM/xlmass/9.1.0/lib/aix61 -L/opt/IBM/xlc/16.1.0/lib -lxlopt -lxlipa -lxl -L/opt/IBM/xlC/16.1.0/lib -lc++ -lCcore -lpthreads -lm -lc | +/opt/IBM/xlC/16.1.0/bin/c++filt -S | +/bin/sed '/317.*::virtual-fn-table-ptr$/ s/^\(.*: \)*{*\([^}]*\)\(}*.*\)::virtual-fn-table-ptr$/\1Virtual table for class "\2": Some possible causes are: first non-inline virtual function in "\2" is not defined or the class is a template instantiation and an explicit instantiation definition of the class is missing./' +rm /tmp/xlcW05fS7ia +rm /tmp/xlcW15rS7ib +rm /tmp/xlcW25vS7ic +gmake[1]: Leaving directory '/tmp/ii/CMakeFiles/CMakeTmp' diff --git a/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-CXX-XLClang-16.1.0.1.output b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-CXX-XLClang-16.1.0.1.output new file mode 100644 index 0000000..e462894 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitIncludeInfo/data/aix-CXX-XLClang-16.1.0.1.output @@ -0,0 +1 @@ +/opt/IBM/xlC/16.1.0/include2/c++;/opt/IBM/xlC/16.1.0/include2;/opt/IBM/xlC/16.1.0/include2/aix;/opt/IBM/xlmass/9.1.0/include;/usr/include diff --git a/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy-check.cmake b/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy-check.cmake index 6ab3833..dab1c33 100644 --- a/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy-check.cmake +++ b/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy-check.cmake @@ -40,3 +40,62 @@ if(NOT FoundToolsVersion4) set(RunCMake_TEST_FAILED "Failed to find correct ToolsVersion=\"4.0\" .") return() endif() + +# +# Test solution file deployment items. +# + +set(vcSlnFile "${RunCMake_TEST_BINARY_DIR}/VsCEDebuggerDeploy.sln") +if(NOT EXISTS "${vcSlnFile}") + set(RunCMake_TEST_FAILED "Solution file ${vcSlnFile} does not exist.") + return() +endif() + + +if( NOT ${CMAKE_SYSTEM_NAME} STREQUAL "WindowsCE" ) + set(RunCMake_TEST_FAILED "Test only valid for WindowsCE") + return() +endif() + + +set(FooProjGUID "") +set(FoundFooProj FALSE) +set(InFooProj FALSE) +set(FoundReleaseDeploy FALSE) +set(DeployConfigs Debug MinSizeRel RelWithDebInfo ) + +file(STRINGS "${vcSlnFile}" lines) +foreach(line IN LISTS lines) +#message(STATUS "${line}") + if( (NOT InFooProj ) AND (line MATCHES "^[ \\t]*Project\\(\"{[A-F0-9-]+}\"\\) = \"foo\", \"foo.vcxproj\", \"({[A-F0-9-]+})\"[ \\t]*$")) + # First, identify the GUID for the foo project, and record it. + set(FoundFooProj TRUE) + set(InFooProj TRUE) + set(FooProjGUID ${CMAKE_MATCH_1}) + elseif(InFooProj AND line MATCHES "EndProject") + set(InFooProj FALSE) + elseif((NOT InFooProj) AND line MATCHES "${FooProjGUID}\\.Release.*\\.Deploy\\.0") + # If foo's Release configuration is set to deploy, this is the error. + set(FoundReleaseDeploy TRUE) + endif() + if( line MATCHES "{[A-F0-9-]+}\\.([^\\|]+).*\\.Deploy\\.0" ) + # Check that the other configurations ARE set to deploy. + list( REMOVE_ITEM DeployConfigs ${CMAKE_MATCH_1}) + endif() +endforeach() + +if(FoundReleaseDeploy) + set(RunCMake_TEST_FAILED "Release deployment not inhibited by VS_NO_SOLUTION_DEPLOY_Release.") + return() +endif() + +if(NOT FoundFooProj) + set(RunCMake_TEST_FAILED "Failed to find foo project in the solution.") + return() +endif() + +list(LENGTH DeployConfigs length) +if( length GREATER 0 ) + set(RunCMake_TEST_FAILED "Failed to find Deploy lines for non-Release configurations. (${length})") + return() +endif() diff --git a/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy.cmake b/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy.cmake index 948f14c..611db0a 100644 --- a/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy.cmake +++ b/Tests/RunCMake/VS10ProjectWinCE/VsCEDebuggerDeploy.cmake @@ -4,10 +4,11 @@ set(DEPLOY_DIR "temp\\foodir" ) -add_library(foo foo.cpp) +add_library(foo SHARED foo.cpp) set_target_properties(foo PROPERTIES DEPLOYMENT_ADDITIONAL_FILES "foo.dll|\\foo\\src\\dir\\on\\host|$(RemoteDirectory)|0;bar.dll|\\bar\\src\\dir|$(RemoteDirectory)bardir|0" DEPLOYMENT_REMOTE_DIRECTORY ${DEPLOY_DIR} + VS_NO_SOLUTION_DEPLOY $<CONFIG:Release> ) diff --git a/Tests/RunCMake/cmake_parse_arguments/KeyWordsMissingValues.cmake b/Tests/RunCMake/cmake_parse_arguments/KeyWordsMissingValues.cmake new file mode 100644 index 0000000..561f9c0 --- /dev/null +++ b/Tests/RunCMake/cmake_parse_arguments/KeyWordsMissingValues.cmake @@ -0,0 +1,133 @@ +include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake) + +# No keywords that miss any values, _KEYWORDS_MISSING_VALUES should not be defined +cmake_parse_arguments(PREF "" "P1" "P2" P1 p1 P2 p2_a p2_b) + +TEST(PREF_KEYWORDS_MISSING_VALUES "UNDEFINED") + +# Keyword should even be deleted from the actual scope +set(PREF_KEYWORDS_MISSING_VALUES "What ever") +cmake_parse_arguments(PREF "" "" "") + +TEST(PREF_KEYWORDS_MISSING_VALUES "UNDEFINED") + +# Given missing keywords as only option +cmake_parse_arguments(PREF "" "P1" "P2" P1) + +TEST(PREF_KEYWORDS_MISSING_VALUES "P1") +TEST(PREF_P1 "UNDEFINED") +TEST(PREF_UNPARSED_ARGUMENTS "UNDEFINED") + +# Mixed with unparsed arguments +cmake_parse_arguments(UPREF "" "P1" "P2" A B P2 C P1) +TEST(UPREF_KEYWORDS_MISSING_VALUES "P1") +TEST(UPREF_UNPARSED_ARGUMENTS A B) + +# one_value_keyword followed by option +cmake_parse_arguments(REF "OP" "P1" "" P1 OP) +TEST(REF_KEYWORDS_MISSING_VALUES "P1") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_OP "TRUE") + +# Counter Test +cmake_parse_arguments(REF "OP" "P1" "" P1 p1 OP) +TEST(REF_KEYWORDS_MISSING_VALUES "UNDEFINED") +TEST(REF_P1 "p1") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_OP "TRUE") + +# one_value_keyword followed by a one_value_keyword +cmake_parse_arguments(REF "" "P1;P2" "" P1 P2 p2) +TEST(REF_KEYWORDS_MISSING_VALUES "P1") +TEST(REF_P1 "UNDEFINED") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 "p2") + +# Counter Test +cmake_parse_arguments(REF "" "P1;P2" "" P1 p1 P2 p2) +TEST(REF_KEYWORDS_MISSING_VALUES "UNDEFINED") +TEST(REF_P1 "p1") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 "p2") + +# one_value_keyword followed by a multi_value_keywords +cmake_parse_arguments(REF "" "P1" "P2" P1 P2 p1 p2) +TEST(REF_KEYWORDS_MISSING_VALUES "P1") +TEST(REF_P1 "UNDEFINED") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 p1 p2) + +# Counter Examples +cmake_parse_arguments(REF "" "P1" "P2" P1 p1 P2 p1 p2) +TEST(REF_KEYWORDS_MISSING_VALUES "UNDEFINED") +TEST(REF_P1 "p1") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 p1 p2) + +# multi_value_keywords as only option +cmake_parse_arguments(REF "" "P1" "P2" P2) +TEST(REF_KEYWORDS_MISSING_VALUES "P2") +TEST(REF_P1 "UNDEFINED") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 "UNDEFINED") + +# multi_value_keywords followed by option +cmake_parse_arguments(REF "O1" "" "P1" P1 O1) +TEST(REF_KEYWORDS_MISSING_VALUES "P1") +TEST(REF_P1 "UNDEFINED") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_O1 "TRUE") + +# counter test +cmake_parse_arguments(REF "O1" "" "P1" P1 p1 p2 O1) +TEST(REF_KEYWORDS_MISSING_VALUES "UNDEFINED") +TEST(REF_P1 "p1;p2") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_O1 "TRUE") + +# multi_value_keywords followed by one_value_keyword +cmake_parse_arguments(REF "" "P1" "P2" P2 P1 p1) +TEST(REF_KEYWORDS_MISSING_VALUES "P2") +TEST(REF_P1 "p1") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 "UNDEFINED") + +# counter test +cmake_parse_arguments(REF "" "P1" "P2" P2 p2 P1 p1) +TEST(REF_KEYWORDS_MISSING_VALUES "UNDEFINED") +TEST(REF_P1 "p1") +TEST(REF_UNPARSED_ARGUMENTS "UNDEFINED") +TEST(REF_P2 "p2") + +# one_value_keyword as last argument +cmake_parse_arguments(REF "" "P1" "P2" A P2 p2 P1) +TEST(REF_KEYWORDS_MISSING_VALUES "P1") +TEST(REF_P1 "UNDEFINED") +TEST(REF_UNPARSED_ARGUMENTS "A") +TEST(REF_P2 "p2") + +# multi_value_keywords as last argument +cmake_parse_arguments(REF "" "P1" "P2" P1 p1 P2) +TEST(REF_KEYWORDS_MISSING_VALUES "P2") +TEST(REF_P1 "p1") +TEST(REF_P2 "UNDEFINED") + +# Multiple one_value_keyword and multi_value_keywords at different places +cmake_parse_arguments(REF "O1;O2" "P1" "P2" P1 O1 P2 O2) +TEST(REF_KEYWORDS_MISSING_VALUES P1 P2) +TEST(REF_P1 "UNDEFINED") +TEST(REF_P2 "UNDEFINED") + +# Duplicated missing keywords +cmake_parse_arguments(REF "O1;O2" "P1" "P2" P1 O1 P2 O2 P1 P2) +TEST(REF_KEYWORDS_MISSING_VALUES P1 P2) +TEST(REF_P1 "UNDEFINED") +TEST(REF_P2 "UNDEFINED") + +# make sure keywords that are never used, don't get added to KEYWORDS_MISSING_VALUES +cmake_parse_arguments(REF "O1;O2" "P1" "P2") +TEST(REF_KEYWORDS_MISSING_VALUES "UNDEFINED") +TEST(REF_O1 FALSE) +TEST(REF_O2 FALSE) +TEST(REF_P1 UNDEFINED) +TEST(REF_P2 UNDEFINED) diff --git a/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake b/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake index 1e15b3b..505840d 100644 --- a/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake +++ b/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake @@ -11,3 +11,4 @@ run_cmake(BadArgvN2) run_cmake(BadArgvN3) run_cmake(BadArgvN4) run_cmake(CornerCasesArgvN) +run_cmake(KeyWordsMissingValues) diff --git a/Tests/RunCMake/install/TARGETS-OPTIONAL-stderr.txt b/Tests/RunCMake/install/TARGETS-OPTIONAL-stderr.txt deleted file mode 100644 index 86e3ec0..0000000 --- a/Tests/RunCMake/install/TARGETS-OPTIONAL-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -^WARNING: Target "notall" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it\. CMake does not define behavior for this case\.$ diff --git a/Tests/RunCMake/list/POP_BACK-NoArgs-result.txt b/Tests/RunCMake/list/POP_BACK-NoArgs-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/list/POP_BACK-NoArgs-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/POP_BACK-NoArgs-stderr.txt b/Tests/RunCMake/list/POP_BACK-NoArgs-stderr.txt new file mode 100644 index 0000000..83060b4 --- /dev/null +++ b/Tests/RunCMake/list/POP_BACK-NoArgs-stderr.txt @@ -0,0 +1 @@ +list must be called with at least two arguments diff --git a/Tests/RunCMake/list/POP_BACK-NoArgs.cmake b/Tests/RunCMake/list/POP_BACK-NoArgs.cmake new file mode 100644 index 0000000..518924d --- /dev/null +++ b/Tests/RunCMake/list/POP_BACK-NoArgs.cmake @@ -0,0 +1 @@ +list(POP_FRONT) diff --git a/Tests/RunCMake/list/POP_BACK.cmake b/Tests/RunCMake/list/POP_BACK.cmake new file mode 100644 index 0000000..4794796 --- /dev/null +++ b/Tests/RunCMake/list/POP_BACK.cmake @@ -0,0 +1,79 @@ +cmake_policy(SET CMP0054 NEW) + +function(assert_expected_list_len list_var expected_size) + list(LENGTH ${list_var} _size) + if(NOT _size EQUAL ${expected_size}) + message(FATAL_ERROR "list size expected to be `${expected_size}`, got `${_size}` instead") + endif() +endfunction() + +# Pop from undefined list +list(POP_BACK test) +if(DEFINED test) + message(FATAL_ERROR "`test` expected to be undefined") +endif() + +# Pop from empty list +set(test) +list(POP_BACK test) +if(DEFINED test) + message(FATAL_ERROR "`test` expected to be undefined") +endif() + +# Default pop from 1-item list +list(APPEND test one) +list(POP_BACK test) +assert_expected_list_len(test 0) + +# Pop from 1-item list to var +list(APPEND test one) +list(POP_BACK test one) +assert_expected_list_len(test 0) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() + +unset(one) +unset(two) + +# Pop from 1-item list to vars +list(APPEND test one) +list(POP_BACK test one two) +assert_expected_list_len(test 0) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() +if(DEFINED two) + message(FATAL_ERROR "`two` expected to be undefined") +endif() + +unset(one) +unset(two) + +# Default pop from 2-item list +list(APPEND test one two) +list(POP_BACK test) +assert_expected_list_len(test 1) +if(NOT test STREQUAL "one") + message(FATAL_ERROR "`test` has unexpected value `${test}`") +endif() + +# Pop from 2-item list +list(APPEND test two) +list(POP_BACK test two) +assert_expected_list_len(test 1) +if(NOT DEFINED two) + message(FATAL_ERROR "`two` expected to be defined") +endif() +if(NOT two STREQUAL "two") + message(FATAL_ERROR "`two` has unexpected value `${two}`") +endif() +if(NOT test STREQUAL "one") + message(FATAL_ERROR "`test` has unexpected value `${test}`") +endif() diff --git a/Tests/RunCMake/list/POP_FRONT-NoArgs-result.txt b/Tests/RunCMake/list/POP_FRONT-NoArgs-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/list/POP_FRONT-NoArgs-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/POP_FRONT-NoArgs-stderr.txt b/Tests/RunCMake/list/POP_FRONT-NoArgs-stderr.txt new file mode 100644 index 0000000..83060b4 --- /dev/null +++ b/Tests/RunCMake/list/POP_FRONT-NoArgs-stderr.txt @@ -0,0 +1 @@ +list must be called with at least two arguments diff --git a/Tests/RunCMake/list/POP_FRONT-NoArgs.cmake b/Tests/RunCMake/list/POP_FRONT-NoArgs.cmake new file mode 100644 index 0000000..c5cf837 --- /dev/null +++ b/Tests/RunCMake/list/POP_FRONT-NoArgs.cmake @@ -0,0 +1 @@ +list(POP_BACK) diff --git a/Tests/RunCMake/list/POP_FRONT.cmake b/Tests/RunCMake/list/POP_FRONT.cmake new file mode 100644 index 0000000..a2f8f3c --- /dev/null +++ b/Tests/RunCMake/list/POP_FRONT.cmake @@ -0,0 +1,79 @@ +cmake_policy(SET CMP0054 NEW) + +function(assert_expected_list_len list_var expected_size) + list(LENGTH ${list_var} _size) + if(NOT _size EQUAL ${expected_size}) + message(FATAL_ERROR "list size expected to be `${expected_size}`, got `${_size}` instead") + endif() +endfunction() + +# Pop from undefined list +list(POP_FRONT test) +if(DEFINED test) + message(FATAL_ERROR "`test` expected to be undefined") +endif() + +# Pop from empty list +set(test) +list(POP_FRONT test) +if(DEFINED test) + message(FATAL_ERROR "`test` expected to be undefined") +endif() + +# Default pop from 1-item list +list(APPEND test one) +list(POP_FRONT test) +assert_expected_list_len(test 0) + +# Pop from 1-item list to var +list(APPEND test one) +list(POP_FRONT test one) +assert_expected_list_len(test 0) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() + +unset(one) +unset(two) + +# Pop from 1-item list to vars +list(APPEND test one) +list(POP_FRONT test one two) +assert_expected_list_len(test 0) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() +if(DEFINED two) + message(FATAL_ERROR "`two` expected to be undefined") +endif() + +unset(one) +unset(two) + +# Default pop from 2-item list +list(APPEND test one two) +list(POP_FRONT test) +assert_expected_list_len(test 1) +if(NOT test STREQUAL "two") + message(FATAL_ERROR "`test` has unexpected value `${test}`") +endif() + +# Pop from 2-item list +list(PREPEND test one) +list(POP_FRONT test one) +assert_expected_list_len(test 1) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() +if(NOT test STREQUAL "two") + message(FATAL_ERROR "`test` has unexpected value `${test}`") +endif() diff --git a/Tests/RunCMake/list/PREPEND-NoArgs-result.txt b/Tests/RunCMake/list/PREPEND-NoArgs-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/list/PREPEND-NoArgs-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/PREPEND-NoArgs-stderr.txt b/Tests/RunCMake/list/PREPEND-NoArgs-stderr.txt new file mode 100644 index 0000000..83060b4 --- /dev/null +++ b/Tests/RunCMake/list/PREPEND-NoArgs-stderr.txt @@ -0,0 +1 @@ +list must be called with at least two arguments diff --git a/Tests/RunCMake/list/PREPEND-NoArgs.cmake b/Tests/RunCMake/list/PREPEND-NoArgs.cmake new file mode 100644 index 0000000..8935fa9 --- /dev/null +++ b/Tests/RunCMake/list/PREPEND-NoArgs.cmake @@ -0,0 +1 @@ +list(PREPEND) diff --git a/Tests/RunCMake/list/PREPEND.cmake b/Tests/RunCMake/list/PREPEND.cmake new file mode 100644 index 0000000..17b2921 --- /dev/null +++ b/Tests/RunCMake/list/PREPEND.cmake @@ -0,0 +1,33 @@ +list(PREPEND test) +if(test) + message(FATAL_ERROR "failed") +endif() + +list(PREPEND test satu) +if(NOT test STREQUAL "satu") + message(FATAL_ERROR "failed") +endif() + +list(PREPEND test dua) +if(NOT test STREQUAL "dua;satu") + message(FATAL_ERROR "failed") +endif() + +list(PREPEND test tiga) +if(NOT test STREQUAL "tiga;dua;satu") + message(FATAL_ERROR "failed") +endif() + +# Scope test +function(foo) + list(PREPEND test empat) + if(NOT test STREQUAL "empat;tiga;dua;satu") + message(FATAL_ERROR "failed") + endif() +endfunction() + +foo() + +if(NOT test STREQUAL "tiga;dua;satu") + message(FATAL_ERROR "failed") +endif() diff --git a/Tests/RunCMake/list/REMOVE_DUPLICATES-PreserveOrder.cmake b/Tests/RunCMake/list/REMOVE_DUPLICATES-PreserveOrder.cmake new file mode 100644 index 0000000..91abbd6 --- /dev/null +++ b/Tests/RunCMake/list/REMOVE_DUPLICATES-PreserveOrder.cmake @@ -0,0 +1,5 @@ +set(mylist "b;c;b;a;a;c;b;a;c;b") +list(REMOVE_DUPLICATES mylist) +if(NOT mylist STREQUAL "b;c;a") + message(SEND_ERROR "Expected b;c;a, got ${mylist}") +endif() diff --git a/Tests/RunCMake/list/RunCMakeTest.cmake b/Tests/RunCMake/list/RunCMakeTest.cmake index bf3d22d..b4a91bc 100644 --- a/Tests/RunCMake/list/RunCMakeTest.cmake +++ b/Tests/RunCMake/list/RunCMakeTest.cmake @@ -24,6 +24,8 @@ run_cmake(SUBLIST-TooManyArguments) run_cmake(REMOVE_AT-EmptyList) +run_cmake(REMOVE_DUPLICATES-PreserveOrder) + run_cmake(FILTER-NotList) run_cmake(REMOVE_AT-NotList) run_cmake(REMOVE_DUPLICATES-NotList) @@ -98,3 +100,15 @@ run_cmake(SORT-NoCaseOption) # Successful tests run_cmake(SORT) + +# argument tests +run_cmake(PREPEND-NoArgs) +# Successful tests +run_cmake(PREPEND) + +# argument tests +run_cmake(POP_BACK-NoArgs) +run_cmake(POP_FRONT-NoArgs) +# Successful tests +run_cmake(POP_BACK) +run_cmake(POP_FRONT) diff --git a/Tests/RunCMake/try_compile/CMP0066-stderr.txt b/Tests/RunCMake/try_compile/CMP0066-stderr.txt index b14e290..0b92dcf 100644 --- a/Tests/RunCMake/try_compile/CMP0066-stderr.txt +++ b/Tests/RunCMake/try_compile/CMP0066-stderr.txt @@ -12,4 +12,15 @@ CMake Warning \(dev\) at CMP0066.cmake:[0-9]+ \(try_compile\): test project. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) -This warning is for project developers. Use -Wno-dev to suppress it.$ +This warning is for project developers. Use -Wno-dev to suppress it. +* +CMake Deprecation Warning at CMP0066.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0066 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/try_compile/LinkOptions.cmake b/Tests/RunCMake/try_compile/LinkOptions.cmake index 9b246c4..488cab1 100644 --- a/Tests/RunCMake/try_compile/LinkOptions.cmake +++ b/Tests/RunCMake/try_compile/LinkOptions.cmake @@ -5,7 +5,7 @@ cmake_policy(SET CMP0054 NEW) set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") if (CMAKE_SYSTEM_NAME STREQUAL "Windows") - if (RunCMake_C_COMPILER_ID STREQUAL "MSVC") + if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") if (CMAKE_SIZEOF_VOID_P EQUAL 4) set (undef_flag /INCLUDE:_func) else() diff --git a/Tests/RunCMake/try_run/LinkOptions.cmake b/Tests/RunCMake/try_run/LinkOptions.cmake index 17af2f7..9939a42 100644 --- a/Tests/RunCMake/try_run/LinkOptions.cmake +++ b/Tests/RunCMake/try_run/LinkOptions.cmake @@ -5,7 +5,7 @@ cmake_policy(SET CMP0054 NEW) set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") if (CMAKE_SYSTEM_NAME STREQUAL "Windows") - if (RunCMake_C_COMPILER_ID STREQUAL "MSVC") + if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") if (CMAKE_SIZEOF_VOID_P EQUAL 4) set (undef_flag /INCLUDE:_func) else() diff --git a/Utilities/cmcompress/CMakeLists.txt b/Utilities/cmcompress/CMakeLists.txt deleted file mode 100644 index 8063573..0000000 --- a/Utilities/cmcompress/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -PROJECT(CMCompress) - -ADD_LIBRARY(cmcompress cmcompress.c) - -INSTALL(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR}/cmcompress) diff --git a/Utilities/cmcompress/Copyright.txt b/Utilities/cmcompress/Copyright.txt deleted file mode 100644 index 162332f..0000000 --- a/Utilities/cmcompress/Copyright.txt +++ /dev/null @@ -1,34 +0,0 @@ -Copyright (c) 1985, 1986 The Regents of the University of California. -All rights reserved. - -This code is derived from software contributed to Berkeley by -James A. Woods, derived from original work by Spencer Thomas -and Joseph Orost. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: - This product includes software developed by the University of - California, Berkeley and its contributors. -4. Neither the name of the University nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. diff --git a/Utilities/cmcompress/cmcompress.c b/Utilities/cmcompress/cmcompress.c deleted file mode 100644 index ea845ed..0000000 --- a/Utilities/cmcompress/cmcompress.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (c) 1985, 1986 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * James A. Woods, derived from original work by Spencer Thomas - * and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "cmcompress.h" - -#include <errno.h> -#include <string.h> - -static const char_type magic_header[] = { "\037\235" }; /* 1F 9D */ - -/* Defines for third byte of header */ -#define BIT_MASK 0x1f -#define BLOCK_MASK 0x80 -#define CHECK_GAP 10000 /* ratio check interval */ -/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is - a fourth header byte (for expansion). - */ -#define INIT_BITS 9 /* initial number of bits/code */ - -#ifdef COMPATIBLE /* But wrong! */ -# define MAXCODE(n_bits) (1 << (n_bits) - 1) -#else -# define MAXCODE(n_bits) ((1 << (n_bits)) - 1) -#endif /* COMPATIBLE */ - -#define htabof(i) cdata->htab[i] -#define codetabof(i) cdata->codetab[i] - -/* - * the next two codes should not be changed lightly, as they must not - * lie within the contiguous general code space. - */ -#define FIRST 257 /* first free entry */ -#define CLEAR 256 /* table clear output code */ - -#ifdef DEBUG -static void prratio( FILE *stream, long int num, long int den); -#endif - -int cmcompress_compress_initialize(struct cmcompress_stream* cdata) -{ - cdata->maxbits = BITS; /* user settable max # bits/code */ - cdata->maxmaxcode = 1 << BITS; /* should NEVER generate this code */ - cdata->hsize = HSIZE; /* for dynamic table sizing */ - cdata->free_ent = 0; /* first unused entry */ - cdata->nomagic = 0; /* Use a 3-byte magic number header, unless old file */ - cdata->block_compress = BLOCK_MASK; - cdata->clear_flg = 0; - cdata->ratio = 0; - cdata->checkpoint = CHECK_GAP; - - cdata->input_stream = 0; - cdata->output_stream = 0; - cdata->client_data = 0; - return 1; -} - -static void cl_hash(struct cmcompress_stream* cdata, count_int hsize) /* reset code table */ -{ - register count_int *htab_p = cdata->htab+hsize; - register long i; - register long m1 = -1; - - i = hsize - 16; - do - { /* might use Sys V memset(3) here */ - *(htab_p-16) = m1; - *(htab_p-15) = m1; - *(htab_p-14) = m1; - *(htab_p-13) = m1; - *(htab_p-12) = m1; - *(htab_p-11) = m1; - *(htab_p-10) = m1; - *(htab_p-9) = m1; - *(htab_p-8) = m1; - *(htab_p-7) = m1; - *(htab_p-6) = m1; - *(htab_p-5) = m1; - *(htab_p-4) = m1; - *(htab_p-3) = m1; - *(htab_p-2) = m1; - *(htab_p-1) = m1; - htab_p -= 16; - } - while ((i -= 16) >= 0); - for ( i += 16; i > 0; i-- ) - { - *--htab_p = m1; - } -} - -/*- - * Output the given code. - * Inputs: - * code: A n_bits-bit integer. If == -1, then EOF. This assumes - * that n_bits =< (long)wordsize - 1. - * Outputs: - * Outputs code to the file. - * Assumptions: - * Chars are 8 bits long. - * Algorithm: - * Maintain a BITS character long buffer (so that 8 codes will - * fit in it exactly). Use the VAX insv instruction to insert each - * code in turn. When the buffer fills up empty it and start over. - */ - -static char buf[BITS]; - -#ifndef vax -char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00}; -char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; -#endif /* vax */ - -static int output(struct cmcompress_stream* cdata, code_int code) -{ -#ifdef DEBUG - static int col = 0; -#endif /* DEBUG */ - - /* - * On the VAX, it is important to have the register declarations - * in exactly the order given, or the asm will break. - */ - register int r_off = cdata->offset, bits= cdata->n_bits; - register char * bp = buf; - -#ifdef DEBUG - if ( verbose ) - { - fprintf( stderr, "%5d%c", code, - (col+=6) >= 74 ? (col = 0, '\n') : ' ' ); - } -#endif /* DEBUG */ - if ( code >= 0 ) - { -#if defined(vax) && !defined(__GNUC__) - /* - * VAX and PCC DEPENDENT!! Implementation on other machines is - * below. - * - * Translation: Insert BITS bits from the argument starting at - * cdata->offset bits from the beginning of buf. - */ - 0; /* Work around for pcc -O bug with asm and if stmt */ - asm( "insv 4(ap),r11,r10,(r9)" ); -#else - /* - * byte/bit numbering on the VAX is simulated by the following code - */ - /* - * Get to the first byte. - */ - bp += (r_off >> 3); - r_off &= 7; - /* - * Since code is always >= 8 bits, only need to mask the first - * hunk on the left. - */ - *bp = (char)((*bp & rmask[r_off]) | ((code << r_off) & lmask[r_off])); - bp++; - bits -= (8 - r_off); - code >>= 8 - r_off; - /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ - if ( bits >= 8 ) - { - *bp++ = (char)(code); - code >>= 8; - bits -= 8; - } - /* Last bits. */ - if(bits) - { - *bp = (char)(code); - } -#endif /* vax */ - cdata->offset += cdata->n_bits; - if ( cdata->offset == (cdata->n_bits << 3) ) - { - bp = buf; - bits = cdata->n_bits; - cdata->bytes_out += bits; - do - { - if ( cdata->output_stream(cdata, bp, 1) != 1 ) - { - return 0; - } - bp++; - } - while(--bits); - cdata->offset = 0; - } - - /* - * If the next entry is going to be too big for the code size, - * then increase it, if possible. - */ - if ( cdata->free_ent > cdata->maxcode || (cdata->clear_flg > 0)) - { - /* - * Write the whole buffer, because the input side won't - * discover the size increase until after it has read it. - */ - if ( cdata->offset > 0 ) - { - if ( cdata->output_stream(cdata, buf, cdata->n_bits) != cdata->n_bits ) - { - return 0; - } - cdata->bytes_out += cdata->n_bits; - } - cdata->offset = 0; - - if ( cdata->clear_flg ) - { - cdata->maxcode = MAXCODE (cdata->n_bits = INIT_BITS); - cdata->clear_flg = 0; - } - else - { - cdata->n_bits++; - if ( cdata->n_bits == cdata->maxbits ) - { - cdata->maxcode = cdata->maxmaxcode; - } - else - { - cdata->maxcode = MAXCODE(cdata->n_bits); - } - } -#ifdef DEBUG - if ( debug ) - { - fprintf( stderr, "\nChange to %d bits\n", cdata->n_bits ); - col = 0; - } -#endif /* DEBUG */ - } - } - else - { - /* - * At EOF, write the rest of the buffer. - */ - if ( cdata->offset > 0 ) - { - cdata->offset = (cdata->offset + 7) / 8; - if ( cdata->output_stream(cdata, buf, cdata->offset ) != cdata->offset ) - { - return 0; - } - cdata->bytes_out += cdata->offset; - } - cdata->offset = 0; - (void)fflush( stdout ); - if( ferror( stdout ) ) - { - return 0; - } -#ifdef DEBUG - if ( verbose ) - { - fprintf( stderr, "\n" ); - } -#endif - } - return 1; -} - -/* - * compress stdin to stdout - * - * Algorithm: use open addressing double hashing (no chaining) on the - * prefix code / next character combination. We do a variant of Knuth's - * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime - * secondary probe. Here, the modular division first probe is gives way - * to a faster exclusive-or manipulation. Also do block compression with - * an adaptive reset, whereby the code table is cleared when the compression - * ratio decreases, but after the table fills. The variable-length output - * codes are re-sized at this point, and a special CLEAR code is generated - * for the decompressor. Late addition: construct the table according to - * file size for noticeable speed improvement on small files. Please direct - * questions about this implementation to ames!jaw. - */ - -int cmcompress_compress_start(struct cmcompress_stream* cdata) -{ -#ifndef COMPATIBLE - if (cdata->nomagic == 0) - { - char headLast = (char)(cdata->maxbits | cdata->block_compress); - cdata->output_stream(cdata, (const char*)magic_header, 2); - cdata->output_stream(cdata, &headLast, 1); - if(ferror(stdout)) - { - printf("Error...\n"); - } - } -#endif /* COMPATIBLE */ - - cdata->offset = 0; - cdata->bytes_out = 3; /* includes 3-byte header mojo */ - cdata->out_count = 0; - cdata->clear_flg = 0; - cdata->ratio = 0; - cdata->in_count = 1; - cdata->checkpoint = CHECK_GAP; - cdata->maxcode = MAXCODE(cdata->n_bits = INIT_BITS); - cdata->free_ent = ((cdata->block_compress) ? FIRST : 256 ); - - cdata->first_pass = 1; - - cdata->hshift = 0; - for ( cdata->fcode = (long) cdata->hsize; cdata->fcode < 65536L; cdata->fcode *= 2L ) - { - cdata->hshift++; - } - cdata->hshift = 8 - cdata->hshift; /* set hash code range bound */ - - cdata->hsize_reg = cdata->hsize; - cl_hash(cdata, (count_int) cdata->hsize_reg); /* clear hash table */ - - return 1; -} - -static int cl_block (struct cmcompress_stream* cdata) /* table clear for block compress */ -{ - register long int rat; - - cdata->checkpoint = cdata->in_count + CHECK_GAP; -#ifdef DEBUG - if ( cdata->debug ) - { - fprintf ( stderr, "count: %ld, ratio: ", cdata->in_count ); - prratio ( stderr, cdata->in_count, cdata->bytes_out ); - fprintf ( stderr, "\n"); - } -#endif /* DEBUG */ - - if(cdata->in_count > 0x007fffff) - { /* shift will overflow */ - rat = cdata->bytes_out >> 8; - if(rat == 0) - { /* Don't divide by zero */ - rat = 0x7fffffff; - } - else - { - rat = cdata->in_count / rat; - } - } - else - { - rat = (cdata->in_count << 8) / cdata->bytes_out; /* 8 fractional bits */ - } - if ( rat > cdata->ratio ) - { - cdata->ratio = rat; - } - else - { - cdata->ratio = 0; -#ifdef DEBUG - if(cdata->verbose) - { - dump_tab(); /* dump string table */ - } -#endif - cl_hash (cdata, (count_int) cdata->hsize ); - cdata->free_ent = FIRST; - cdata->clear_flg = 1; - if ( !output (cdata, (code_int) CLEAR ) ) - { - return 0; - } -#ifdef DEBUG - if(cdata->debug) - { - fprintf ( stderr, "clear\n" ); - } -#endif /* DEBUG */ - } - return 1; -} - - -int cmcompress_compress(struct cmcompress_stream* cdata, void* buff, size_t n) -{ - register code_int i; - register int c; - register int disp; - - unsigned char* input_buffer = (unsigned char*)buff; - - size_t cc; - - /*printf("cmcompress_compress(%p, %p, %d)\n", cdata, buff, n);*/ - - if ( cdata->first_pass ) - { - cdata->ent = input_buffer[0]; - ++ input_buffer; - -- n; - cdata->first_pass = 0; - } - - for ( cc = 0; cc < n; ++ cc ) - { - c = input_buffer[cc]; - cdata->in_count++; - cdata->fcode = (long) (((long) c << cdata->maxbits) + cdata->ent); - i = ((c << cdata->hshift) ^ cdata->ent); /* xor hashing */ - - if ( htabof (i) == cdata->fcode ) - { - cdata->ent = codetabof (i); - continue; - } - else if ( (long)htabof (i) < 0 ) /* empty slot */ - { - goto nomatch; - } - disp = (int)(cdata->hsize_reg - i); /* secondary hash (after G. Knott) */ - if ( i == 0 ) - { - disp = 1; - } -probe: - if ( (i -= disp) < 0 ) - { - i += cdata->hsize_reg; - } - - if ( htabof (i) == cdata->fcode ) - { - cdata->ent = codetabof (i); - continue; - } - if ( (long)htabof (i) > 0 ) - { - goto probe; - } -nomatch: - if ( !output(cdata, (code_int) cdata->ent ) ) - { - return 0; - } - cdata->out_count++; - cdata->ent = c; - if ( -#ifdef SIGNED_COMPARE_SLOW - (unsigned) cdata->free_ent < (unsigned) cdata->maxmaxcode -#else - cdata->free_ent < cdata->maxmaxcode -#endif - ) - { - codetabof (i) = (unsigned short)(cdata->free_ent++); /* code -> hashtable */ - htabof (i) = cdata->fcode; - } - else if ( (count_int)cdata->in_count >= cdata->checkpoint && cdata->block_compress ) - { - if ( !cl_block (cdata) ) - { - return 0; - } - } - } - - return 1; -} - -int cmcompress_compress_finalize(struct cmcompress_stream* cdata) -{ - /* - * Put out the final code. - */ - if ( !output(cdata, (code_int)cdata->ent ) ) - { - return 0; - } - cdata->out_count++; - if ( !output(cdata, (code_int)-1 ) ) - { - return 0; - } - - if(cdata->bytes_out > cdata->in_count) /* exit(2) if no savings */ - { - return 0; - } - return 1; -} - - -#if defined(DEBUG) -static void prratio(FILE *stream, long int num, long int den) -{ - register int q; /* Doesn't need to be long */ - - if(num > 214748L) - { /* 2147483647/10000 */ - q = num / (den / 10000L); - } - else - { - q = 10000L * num / den; /* Long calculations, though */ - } - if (q < 0) - { - putc('-', stream); - q = -q; - } - fprintf(stream, "%d.%02d%%", q / 100, q % 100); -} -#endif - diff --git a/Utilities/cmcompress/cmcompress.h b/Utilities/cmcompress/cmcompress.h deleted file mode 100644 index 4cd3a1c..0000000 --- a/Utilities/cmcompress/cmcompress.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 1985, 1986 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * James A. Woods, derived from original work by Spencer Thomas - * and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef cmcompress__h_ -#define cmcompress__h_ - -#include <stdio.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* - * Set USERMEM to the maximum amount of physical user memory available - * in bytes. USERMEM is used to determine the maximum BITS that can be used - * for compression. - * - * SACREDMEM is the amount of physical memory saved for others; compress - * will hog the rest. - */ -#ifndef SACREDMEM -#define SACREDMEM 0 -#endif - -#ifndef USERMEM -# define USERMEM 450000 /* default user memory */ -#endif - -#ifdef pdp11 -# define BITS 12 /* max bits/code for 16-bit machine */ -# define NO_UCHAR /* also if "unsigned char" functions as signed char */ -# undef USERMEM -#endif /* pdp11 */ /* don't forget to compile with -i */ - -#ifdef USERMEM -# if USERMEM >= (433484+SACREDMEM) -# define PBITS 16 -# else -# if USERMEM >= (229600+SACREDMEM) -# define PBITS 15 -# else -# if USERMEM >= (127536+SACREDMEM) -# define PBITS 14 -# else -# if USERMEM >= (73464+SACREDMEM) -# define PBITS 13 -# else -# define PBITS 12 -# endif -# endif -# endif -# endif -# undef USERMEM -#endif /* USERMEM */ - -#ifdef PBITS /* Preferred BITS for this memory size */ -# ifndef BITS -# define BITS PBITS -# endif /* BITS */ -#endif /* PBITS */ - -#if BITS == 16 -# define HSIZE 69001 /* 95% occupancy */ -#endif -#if BITS == 15 -# define HSIZE 35023 /* 94% occupancy */ -#endif -#if BITS == 14 -# define HSIZE 18013 /* 91% occupancy */ -#endif -#if BITS == 13 -# define HSIZE 9001 /* 91% occupancy */ -#endif -#if BITS <= 12 -# define HSIZE 5003 /* 80% occupancy */ -#endif - - /* - * a code_int must be able to hold 2**BITS values of type int, and also -1 - */ -#if BITS > 15 - typedef long int code_int; -#else - typedef int code_int; -#endif - -#ifdef SIGNED_COMPARE_SLOW - typedef unsigned long int count_int; - typedef unsigned short int count_short; -#else - typedef long int count_int; -#endif - -#ifdef NO_UCHAR - typedef char char_type; -#else - typedef unsigned char char_type; -#endif /* UCHAR */ - - - - struct cmcompress_stream - { - int n_bits; /* number of bits/code */ - int maxbits; /* user settable max # bits/code */ - code_int maxcode; /* maximum code, given n_bits */ - code_int maxmaxcode; /* should NEVER generate this code */ - - count_int htab [HSIZE]; - unsigned short codetab [HSIZE]; - - code_int hsize; /* for dynamic table sizing */ - code_int free_ent; /* first unused entry */ - int nomagic; /* Use a 3-byte magic number header, unless old file */ - - /* - * block compression parameters -- after all codes are used up, - * and compression rate changes, start over. - */ - int block_compress; - int clear_flg; - long int ratio; - count_int checkpoint; - -#ifdef DEBUG - int debug; - int verbose; -#endif - - /* compress internals */ - int offset; - long int in_count; /* length of input */ - long int bytes_out; /* length of compressed output */ - long int out_count; /* # of codes output (for debugging) */ - - /* internals */ - code_int ent; - code_int hsize_reg; - int hshift; - - long fcode; - int first_pass; - - /* For input and output */ - int (*input_stream)(void*); - int (*output_stream)(void*, const char*,int); - void* client_data; - }; - - int cmcompress_compress_initialize(struct cmcompress_stream* cdata); - int cmcompress_compress_start(struct cmcompress_stream* cdata); - int cmcompress_compress(struct cmcompress_stream* cdata, void* buff, size_t n); - int cmcompress_compress_finalize(struct cmcompress_stream* cdata); - -#ifdef __cplusplus -} -#endif - - -#endif /* cmcompress__h_ */ diff --git a/Utilities/cmcompress/compress.c.original b/Utilities/cmcompress/compress.c.original deleted file mode 100644 index 5062bda..0000000 --- a/Utilities/cmcompress/compress.c.original +++ /dev/null @@ -1,1308 +0,0 @@ -/* - * Copyright (c) 1985, 1986 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * James A. Woods, derived from original work by Spencer Thomas - * and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1985, 1986 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)compress.c 5.19 (Berkeley) 3/18/91"; -#endif /* not lint */ - -/* - * compress.c - File compression ala IEEE Computer, June 1984. - * - * Authors: Spencer W. Thomas (decvax!utah-cs!thomas) - * Jim McKie (decvax!mcvax!jim) - * Steve Davies (decvax!vax135!petsd!peora!srd) - * Ken Turkowski (decvax!decwrl!turtlevax!ken) - * James A. Woods (decvax!ihnp4!ames!jaw) - * Joe Orost (decvax!vax135!petsd!joe) - */ - -#include <sys/param.h> -#include <sys/stat.h> -#include <signal.h> -#include <utime.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <ctype.h> -#include <stdlib.h> -#include <string.h> - -/* - * Set USERMEM to the maximum amount of physical user memory available - * in bytes. USERMEM is used to determine the maximum BITS that can be used - * for compression. - * - * SACREDMEM is the amount of physical memory saved for others; compress - * will hog the rest. - */ -#ifndef SACREDMEM -#define SACREDMEM 0 -#endif - -#ifndef USERMEM -# define USERMEM 450000 /* default user memory */ -#endif - -#ifdef pdp11 -# define BITS 12 /* max bits/code for 16-bit machine */ -# define NO_UCHAR /* also if "unsigned char" functions as signed char */ -# undef USERMEM -#endif /* pdp11 */ /* don't forget to compile with -i */ - -#ifdef USERMEM -# if USERMEM >= (433484+SACREDMEM) -# define PBITS 16 -# else -# if USERMEM >= (229600+SACREDMEM) -# define PBITS 15 -# else -# if USERMEM >= (127536+SACREDMEM) -# define PBITS 14 -# else -# if USERMEM >= (73464+SACREDMEM) -# define PBITS 13 -# else -# define PBITS 12 -# endif -# endif -# endif -# endif -# undef USERMEM -#endif /* USERMEM */ - -#ifdef PBITS /* Preferred BITS for this memory size */ -# ifndef BITS -# define BITS PBITS -# endif BITS -#endif /* PBITS */ - -#if BITS == 16 -# define HSIZE 69001 /* 95% occupancy */ -#endif -#if BITS == 15 -# define HSIZE 35023 /* 94% occupancy */ -#endif -#if BITS == 14 -# define HSIZE 18013 /* 91% occupancy */ -#endif -#if BITS == 13 -# define HSIZE 9001 /* 91% occupancy */ -#endif -#if BITS <= 12 -# define HSIZE 5003 /* 80% occupancy */ -#endif - -/* - * a code_int must be able to hold 2**BITS values of type int, and also -1 - */ -#if BITS > 15 -typedef long int code_int; -#else -typedef int code_int; -#endif - -#ifdef SIGNED_COMPARE_SLOW -typedef unsigned long int count_int; -typedef unsigned short int count_short; -#else -typedef long int count_int; -#endif - -#ifdef NO_UCHAR - typedef char char_type; -#else - typedef unsigned char char_type; -#endif /* UCHAR */ -char_type magic_header[] = { "\037\235" }; /* 1F 9D */ - -/* Defines for third byte of header */ -#define BIT_MASK 0x1f -#define BLOCK_MASK 0x80 -/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is - a fourth header byte (for expansion). -*/ -#define INIT_BITS 9 /* initial number of bits/code */ - -int n_bits; /* number of bits/code */ -int maxbits = BITS; /* user settable max # bits/code */ -code_int maxcode; /* maximum code, given n_bits */ -code_int maxmaxcode = 1 << BITS; /* should NEVER generate this code */ -#ifdef COMPATIBLE /* But wrong! */ -# define MAXCODE(n_bits) (1 << (n_bits) - 1) -#else -# define MAXCODE(n_bits) ((1 << (n_bits)) - 1) -#endif /* COMPATIBLE */ - -count_int htab [HSIZE]; -unsigned short codetab [HSIZE]; - -#define htabof(i) htab[i] -#define codetabof(i) codetab[i] -code_int hsize = HSIZE; /* for dynamic table sizing */ -count_int fsize; - -/* - * To save much memory, we overlay the table used by compress() with those - * used by decompress(). The tab_prefix table is the same size and type - * as the codetab. The tab_suffix table needs 2**BITS characters. We - * get this from the beginning of htab. The output stack uses the rest - * of htab, and contains characters. There is plenty of room for any - * possible stack (stack used to be 8000 characters). - */ - -#define tab_prefixof(i) codetabof(i) -# define tab_suffixof(i) ((char_type *)(htab))[i] -# define de_stack ((char_type *)&tab_suffixof(1<<BITS)) - -code_int free_ent = 0; /* first unused entry */ -int exit_stat = 0; /* per-file status */ -int perm_stat = 0; /* permanent status */ - -code_int getcode(); - -int nomagic = 0; /* Use a 3-byte magic number header, unless old file */ -int zcat_flg = 0; /* Write output on stdout, suppress messages */ -int precious = 1; /* Don't unlink output file on interrupt */ -int quiet = 1; /* don't tell me about compression */ - -/* - * block compression parameters -- after all codes are used up, - * and compression rate changes, start over. - */ -int block_compress = BLOCK_MASK; -int clear_flg = 0; -long int ratio = 0; -#define CHECK_GAP 10000 /* ratio check interval */ -count_int checkpoint = CHECK_GAP; -/* - * the next two codes should not be changed lightly, as they must not - * lie within the contiguous general code space. - */ -#define FIRST 257 /* first free entry */ -#define CLEAR 256 /* table clear output code */ - -int force = 0; -char ofname [100]; -#ifdef DEBUG -int debug, verbose; -#endif -sig_t oldint; -int bgnd_flag; - -int do_decomp = 0; - -/*- - * Algorithm from "A Technique for High Performance Data Compression", - * Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19. - * - * Usage: compress [-dfvc] [-b bits] [file ...] - * Inputs: - * -d: If given, decompression is done instead. - * - * -c: Write output on stdout, don't remove original. - * - * -b: Parameter limits the max number of bits/code. - * - * -f: Forces output file to be generated, even if one already - * exists, and even if no space is saved by compressing. - * If -f is not used, the user will be prompted if stdin is - * a tty, otherwise, the output file will not be overwritten. - * - * -v: Write compression statistics - * - * file ...: Files to be compressed. If none specified, stdin - * is used. - * Outputs: - * file.Z: Compressed form of file with same mode, owner, and utimes - * or stdout (if stdin used as input) - * - * Assumptions: - * When filenames are given, replaces with the compressed version - * (.Z suffix) only if the file decreases in size. - * Algorithm: - * Modified Lempel-Ziv method (LZW). Basically finds common - * substrings and replaces them with a variable size code. This is - * deterministic, and can be done on the fly. Thus, the decompression - * procedure needs no input table, but tracks the way the table was built. - */ - -main(argc, argv) - int argc; - char **argv; -{ - extern int optind; - extern char *optarg; - struct stat statbuf; - int ch, overwrite; - char **filelist, **fileptr, *cp, tempname[MAXPATHLEN]; - void onintr(), oops(); - - /* This bg check only works for sh. */ - if ((oldint = signal(SIGINT, SIG_IGN)) != SIG_IGN) { - (void)signal(SIGINT, onintr); - (void)signal(SIGSEGV, oops); /* XXX */ - } - bgnd_flag = oldint != SIG_DFL; - -#ifdef COMPATIBLE - nomagic = 1; /* Original didn't have a magic number */ -#endif - - if (cp = rindex(argv[0], '/')) - ++cp; - else - cp = argv[0]; - if (strcmp(cp, "uncompress") == 0) - do_decomp = 1; - else if(strcmp(cp, "zcat") == 0) { - do_decomp = 1; - zcat_flg = 1; - } - - /* - * -b maxbits => maxbits. - * -C => generate output compatible with compress 2.0. - * -c => cat all output to stdout - * -D => debug - * -d => do_decomp - * -f => force overwrite of output file - * -n => no header: useful to uncompress old files - * -V => print Version; debug verbose - * -v => unquiet - */ - - overwrite = 0; -#ifdef DEBUG - while ((ch = getopt(argc, argv, "b:CcDdfnVv")) != EOF) -#else - while ((ch = getopt(argc, argv, "b:Ccdfnv")) != EOF) -#endif - switch(ch) { - case 'b': - maxbits = atoi(optarg); - break; - case 'C': - block_compress = 0; - break; - case 'c': - zcat_flg = 1; - break; -#ifdef DEBUG - case 'D': - debug = 1; - break; -#endif - case 'd': - do_decomp = 1; - break; - case 'f': - overwrite = 1; - force = 1; - break; - case 'n': - nomagic = 1; - break; - case 'q': - quiet = 1; - break; -#ifdef DEBUG - case 'V': - verbose = 1; - break; -#endif - case 'v': - quiet = 0; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (maxbits < INIT_BITS) - maxbits = INIT_BITS; - if (maxbits > BITS) - maxbits = BITS; - maxmaxcode = 1 << maxbits; - - /* Build useless input file list. */ - filelist = fileptr = (char **)(malloc(argc * sizeof(*argv))); - while (*argv) - *fileptr++ = *argv++; - *fileptr = NULL; - - if (*filelist != NULL) { - for (fileptr = filelist; *fileptr; fileptr++) { - exit_stat = 0; - if (do_decomp) { /* DECOMPRESSION */ - /* Check for .Z suffix */ - if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") != 0) { - /* No .Z: tack one on */ - strcpy(tempname, *fileptr); - strcat(tempname, ".Z"); - *fileptr = tempname; - } - /* Open input file */ - if ((freopen(*fileptr, "r", stdin)) == NULL) { - perror(*fileptr); - perm_stat = 1; - continue; - } - /* Check the magic number */ - if (nomagic == 0) { - if ((getchar() != (magic_header[0] & 0xFF)) - || (getchar() != (magic_header[1] & 0xFF))) { - fprintf(stderr, "%s: not in compressed format\n", - *fileptr); - continue; - } - maxbits = getchar(); /* set -b from file */ - block_compress = maxbits & BLOCK_MASK; - maxbits &= BIT_MASK; - maxmaxcode = 1 << maxbits; - if(maxbits > BITS) { - fprintf(stderr, - "%s: compressed with %d bits, can only handle %d bits\n", - *fileptr, maxbits, BITS); - continue; - } - } - /* Generate output filename */ - strcpy(ofname, *fileptr); - ofname[strlen(*fileptr) - 2] = '\0'; /* Strip off .Z */ - } else { /* COMPRESSION */ - if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") == 0) { - fprintf(stderr, "%s: already has .Z suffix -- no change\n", - *fileptr); - continue; - } - /* Open input file */ - if ((freopen(*fileptr, "r", stdin)) == NULL) { - perror(*fileptr); - perm_stat = 1; - continue; - } - stat ( *fileptr, &statbuf ); - fsize = (long) statbuf.st_size; - /* - * tune hash table size for small files -- ad hoc, - * but the sizes match earlier #defines, which - * serve as upper bounds on the number of output codes. - */ - hsize = HSIZE; - if ( fsize < (1 << 12) ) - hsize = MIN ( 5003, HSIZE ); - else if ( fsize < (1 << 13) ) - hsize = MIN ( 9001, HSIZE ); - else if ( fsize < (1 << 14) ) - hsize = MIN ( 18013, HSIZE ); - else if ( fsize < (1 << 15) ) - hsize = MIN ( 35023, HSIZE ); - else if ( fsize < 47000 ) - hsize = MIN ( 50021, HSIZE ); - - /* Generate output filename */ - strcpy(ofname, *fileptr); - strcat(ofname, ".Z"); - } - /* Check for overwrite of existing file */ - if (overwrite == 0 && zcat_flg == 0) { - if (stat(ofname, &statbuf) == 0) { - char response[2]; - response[0] = 'n'; - fprintf(stderr, "%s already exists;", ofname); - if (bgnd_flag == 0 && isatty(2)) { - fprintf(stderr, " do you wish to overwrite %s (y or n)? ", - ofname); - fflush(stderr); - read(2, response, 2); - while (response[1] != '\n') { - if (read(2, response+1, 1) < 0) { /* Ack! */ - perror("stderr"); break; - } - } - } - if (response[0] != 'y') { - fprintf(stderr, "\tnot overwritten\n"); - continue; - } - } - } - if(zcat_flg == 0) { /* Open output file */ - if (freopen(ofname, "w", stdout) == NULL) { - perror(ofname); - perm_stat = 1; - continue; - } - precious = 0; - if(!quiet) - fprintf(stderr, "%s: ", *fileptr); - } - - /* Actually do the compression/decompression */ - if (do_decomp == 0) compress(); -#ifndef DEBUG - else decompress(); -#else - else if (debug == 0) decompress(); - else printcodes(); - if (verbose) dump_tab(); -#endif /* DEBUG */ - if(zcat_flg == 0) { - copystat(*fileptr, ofname); /* Copy stats */ - precious = 1; - if((exit_stat == 1) || (!quiet)) - putc('\n', stderr); - } - } - } else { /* Standard input */ - if (do_decomp == 0) { - compress(); -#ifdef DEBUG - if(verbose) dump_tab(); -#endif /* DEBUG */ - if(!quiet) - putc('\n', stderr); - } else { - /* Check the magic number */ - if (nomagic == 0) { - if ((getchar()!=(magic_header[0] & 0xFF)) - || (getchar()!=(magic_header[1] & 0xFF))) { - fprintf(stderr, "stdin: not in compressed format\n"); - exit(1); - } - maxbits = getchar(); /* set -b from file */ - block_compress = maxbits & BLOCK_MASK; - maxbits &= BIT_MASK; - maxmaxcode = 1 << maxbits; - fsize = 100000; /* assume stdin large for USERMEM */ - if(maxbits > BITS) { - fprintf(stderr, - "stdin: compressed with %d bits, can only handle %d bits\n", - maxbits, BITS); - exit(1); - } - } -#ifndef DEBUG - decompress(); -#else - if (debug == 0) decompress(); - else printcodes(); - if (verbose) dump_tab(); -#endif /* DEBUG */ - } - } - exit(perm_stat ? perm_stat : exit_stat); -} - -static int offset; -long int in_count = 1; /* length of input */ -long int bytes_out; /* length of compressed output */ -long int out_count = 0; /* # of codes output (for debugging) */ - -/* - * compress stdin to stdout - * - * Algorithm: use open addressing double hashing (no chaining) on the - * prefix code / next character combination. We do a variant of Knuth's - * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime - * secondary probe. Here, the modular division first probe is gives way - * to a faster exclusive-or manipulation. Also do block compression with - * an adaptive reset, whereby the code table is cleared when the compression - * ratio decreases, but after the table fills. The variable-length output - * codes are re-sized at this point, and a special CLEAR code is generated - * for the decompressor. Late addition: construct the table according to - * file size for noticeable speed improvement on small files. Please direct - * questions about this implementation to ames!jaw. - */ - -compress() -{ - register long fcode; - register code_int i = 0; - register int c; - register code_int ent; - register int disp; - register code_int hsize_reg; - register int hshift; - -#ifndef COMPATIBLE - if (nomagic == 0) { - putchar(magic_header[0]); - putchar(magic_header[1]); - putchar((char)(maxbits | block_compress)); - if(ferror(stdout)) - writeerr(); - } -#endif /* COMPATIBLE */ - - offset = 0; - bytes_out = 3; /* includes 3-byte header mojo */ - out_count = 0; - clear_flg = 0; - ratio = 0; - in_count = 1; - checkpoint = CHECK_GAP; - maxcode = MAXCODE(n_bits = INIT_BITS); - free_ent = ((block_compress) ? FIRST : 256 ); - - ent = getchar (); - - hshift = 0; - for ( fcode = (long) hsize; fcode < 65536L; fcode *= 2L ) - hshift++; - hshift = 8 - hshift; /* set hash code range bound */ - - hsize_reg = hsize; - cl_hash( (count_int) hsize_reg); /* clear hash table */ - -#ifdef SIGNED_COMPARE_SLOW - while ( (c = getchar()) != (unsigned) EOF ) { -#else - while ( (c = getchar()) != EOF ) { -#endif - in_count++; - fcode = (long) (((long) c << maxbits) + ent); - i = ((c << hshift) ^ ent); /* xor hashing */ - - if ( htabof (i) == fcode ) { - ent = codetabof (i); - continue; - } else if ( (long)htabof (i) < 0 ) /* empty slot */ - goto nomatch; - disp = hsize_reg - i; /* secondary hash (after G. Knott) */ - if ( i == 0 ) - disp = 1; -probe: - if ( (i -= disp) < 0 ) - i += hsize_reg; - - if ( htabof (i) == fcode ) { - ent = codetabof (i); - continue; - } - if ( (long)htabof (i) > 0 ) - goto probe; -nomatch: - output ( (code_int) ent ); - out_count++; - ent = c; -#ifdef SIGNED_COMPARE_SLOW - if ( (unsigned) free_ent < (unsigned) maxmaxcode) { -#else - if ( free_ent < maxmaxcode ) { -#endif - codetabof (i) = free_ent++; /* code -> hashtable */ - htabof (i) = fcode; - } - else if ( (count_int)in_count >= checkpoint && block_compress ) - cl_block (); - } - /* - * Put out the final code. - */ - output( (code_int)ent ); - out_count++; - output( (code_int)-1 ); - - /* - * Print out stats on stderr - */ - if(zcat_flg == 0 && !quiet) { -#ifdef DEBUG - fprintf( stderr, - "%ld chars in, %ld codes (%ld bytes) out, compression factor: ", - in_count, out_count, bytes_out ); - prratio( stderr, in_count, bytes_out ); - fprintf( stderr, "\n"); - fprintf( stderr, "\tCompression as in compact: " ); - prratio( stderr, in_count-bytes_out, in_count ); - fprintf( stderr, "\n"); - fprintf( stderr, "\tLargest code (of last block) was %d (%d bits)\n", - free_ent - 1, n_bits ); -#else /* !DEBUG */ - fprintf( stderr, "Compression: " ); - prratio( stderr, in_count-bytes_out, in_count ); -#endif /* DEBUG */ - } - if(bytes_out > in_count) /* exit(2) if no savings */ - exit_stat = 2; - return; -} - -/*- - * Output the given code. - * Inputs: - * code: A n_bits-bit integer. If == -1, then EOF. This assumes - * that n_bits =< (long)wordsize - 1. - * Outputs: - * Outputs code to the file. - * Assumptions: - * Chars are 8 bits long. - * Algorithm: - * Maintain a BITS character long buffer (so that 8 codes will - * fit in it exactly). Use the VAX insv instruction to insert each - * code in turn. When the buffer fills up empty it and start over. - */ - -static char buf[BITS]; - -#ifndef vax -char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00}; -char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; -#endif /* vax */ - -output( code ) -code_int code; -{ -#ifdef DEBUG - static int col = 0; -#endif /* DEBUG */ - - /* - * On the VAX, it is important to have the register declarations - * in exactly the order given, or the asm will break. - */ - register int r_off = offset, bits= n_bits; - register char * bp = buf; - -#ifdef DEBUG - if ( verbose ) - fprintf( stderr, "%5d%c", code, - (col+=6) >= 74 ? (col = 0, '\n') : ' ' ); -#endif /* DEBUG */ - if ( code >= 0 ) { -#if defined(vax) && !defined(__GNUC__) - /* - * VAX and PCC DEPENDENT!! Implementation on other machines is - * below. - * - * Translation: Insert BITS bits from the argument starting at - * offset bits from the beginning of buf. - */ - 0; /* Work around for pcc -O bug with asm and if stmt */ - asm( "insv 4(ap),r11,r10,(r9)" ); -#else -/* - * byte/bit numbering on the VAX is simulated by the following code - */ - /* - * Get to the first byte. - */ - bp += (r_off >> 3); - r_off &= 7; - /* - * Since code is always >= 8 bits, only need to mask the first - * hunk on the left. - */ - *bp = (*bp & rmask[r_off]) | (code << r_off) & lmask[r_off]; - bp++; - bits -= (8 - r_off); - code >>= 8 - r_off; - /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ - if ( bits >= 8 ) { - *bp++ = code; - code >>= 8; - bits -= 8; - } - /* Last bits. */ - if(bits) - *bp = code; -#endif /* vax */ - offset += n_bits; - if ( offset == (n_bits << 3) ) { - bp = buf; - bits = n_bits; - bytes_out += bits; - do { - putchar(*bp++); - if (ferror(stdout)) - writeerr(); - } while(--bits); - offset = 0; - } - - /* - * If the next entry is going to be too big for the code size, - * then increase it, if possible. - */ - if ( free_ent > maxcode || (clear_flg > 0)) - { - /* - * Write the whole buffer, because the input side won't - * discover the size increase until after it has read it. - */ - if ( offset > 0 ) { - if( fwrite( buf, 1, n_bits, stdout ) != n_bits) - writeerr(); - bytes_out += n_bits; - } - offset = 0; - - if ( clear_flg ) { - maxcode = MAXCODE (n_bits = INIT_BITS); - clear_flg = 0; - } - else { - n_bits++; - if ( n_bits == maxbits ) - maxcode = maxmaxcode; - else - maxcode = MAXCODE(n_bits); - } -#ifdef DEBUG - if ( debug ) { - fprintf( stderr, "\nChange to %d bits\n", n_bits ); - col = 0; - } -#endif /* DEBUG */ - } - } else { - /* - * At EOF, write the rest of the buffer. - */ - if ( offset > 0 ) { - offset = (offset + 7) / 8; - if( fwrite( buf, 1, offset, stdout ) != offset ) - writeerr(); - bytes_out += offset; - } - offset = 0; - (void)fflush( stdout ); - if( ferror( stdout ) ) - writeerr(); -#ifdef DEBUG - if ( verbose ) - fprintf( stderr, "\n" ); -#endif - } -} - -/* - * Decompress stdin to stdout. This routine adapts to the codes in the - * file building the "string" table on-the-fly; requiring no table to - * be stored in the compressed file. The tables used herein are shared - * with those of the compress() routine. See the definitions above. - */ - -decompress() { - register char_type *stackp; - register int finchar; - register code_int code, oldcode, incode; - int n, nwritten, offset; /* Variables for buffered write */ - char buff[BUFSIZ]; /* Buffer for buffered write */ - - - /* - * As above, initialize the first 256 entries in the table. - */ - maxcode = MAXCODE(n_bits = INIT_BITS); - for ( code = 255; code >= 0; code-- ) { - tab_prefixof(code) = 0; - tab_suffixof(code) = (char_type)code; - } - free_ent = ((block_compress) ? FIRST : 256 ); - - finchar = oldcode = getcode(); - if(oldcode == -1) /* EOF already? */ - return; /* Get out of here */ - - /* first code must be 8 bits = char */ - n=0; - buff[n++] = (char)finchar; - - stackp = de_stack; - - while ( (code = getcode()) > -1 ) { - - if ( (code == CLEAR) && block_compress ) { - for ( code = 255; code >= 0; code-- ) - tab_prefixof(code) = 0; - clear_flg = 1; - free_ent = FIRST - 1; - if ( (code = getcode ()) == -1 ) /* O, untimely death! */ - break; - } - incode = code; - /* - * Special case for KwKwK string. - */ - if ( code >= free_ent ) { - *stackp++ = finchar; - code = oldcode; - } - - /* - * Generate output characters in reverse order - */ -#ifdef SIGNED_COMPARE_SLOW - while ( ((unsigned long)code) >= ((unsigned long)256) ) { -#else - while ( code >= 256 ) { -#endif - *stackp++ = tab_suffixof(code); - code = tab_prefixof(code); - } - *stackp++ = finchar = tab_suffixof(code); - - /* - * And put them out in forward order - */ - do { - /* - * About 60% of the time is spent in the putchar() call - * that appeared here. It was originally - * putchar ( *--stackp ); - * If we buffer the writes ourselves, we can go faster (about - * 30%). - * - * At this point, the next line is the next *big* time - * sink in the code. It takes up about 10% of the time. - */ - buff[n++] = *--stackp; - if (n == BUFSIZ) { - offset = 0; - do { - nwritten = write(fileno(stdout), &buff[offset], n); - if (nwritten < 0) - writeerr(); - offset += nwritten; - } while ((n -= nwritten) > 0); - } - } while ( stackp > de_stack ); - - /* - * Generate the new entry. - */ - if ( (code=free_ent) < maxmaxcode ) { - tab_prefixof(code) = (unsigned short)oldcode; - tab_suffixof(code) = finchar; - free_ent = code+1; - } - /* - * Remember previous code. - */ - oldcode = incode; - } - /* - * Flush the stuff remaining in our buffer... - */ - offset = 0; - while (n > 0) { - nwritten = write(fileno(stdout), &buff[offset], n); - if (nwritten < 0) - writeerr(); - offset += nwritten; - n -= nwritten; - } -} - -/*- - * Read one code from the standard input. If EOF, return -1. - * Inputs: - * stdin - * Outputs: - * code or -1 is returned. - */ -code_int -getcode() { - /* - * On the VAX, it is important to have the register declarations - * in exactly the order given, or the asm will break. - */ - register code_int code; - static int offset = 0, size = 0; - static char_type buf[BITS]; - register int r_off, bits; - register char_type *bp = buf; - - if ( clear_flg > 0 || offset >= size || free_ent > maxcode ) { - /* - * If the next entry will be too big for the current code - * size, then we must increase the size. This implies reading - * a new buffer full, too. - */ - if ( free_ent > maxcode ) { - n_bits++; - if ( n_bits == maxbits ) - maxcode = maxmaxcode; /* won't get any bigger now */ - else - maxcode = MAXCODE(n_bits); - } - if ( clear_flg > 0) { - maxcode = MAXCODE (n_bits = INIT_BITS); - clear_flg = 0; - } - size = fread( buf, 1, n_bits, stdin ); - if ( size <= 0 ) - return -1; /* end of file */ - offset = 0; - /* Round size down to integral number of codes */ - size = (size << 3) - (n_bits - 1); - } - r_off = offset; - bits = n_bits; -#ifdef vax - asm( "extzv r10,r9,(r8),r11" ); -#else /* not a vax */ - /* - * Get to the first byte. - */ - bp += (r_off >> 3); - r_off &= 7; - /* Get first part (low order bits) */ -#ifdef NO_UCHAR - code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff; -#else - code = (*bp++ >> r_off); -#endif /* NO_UCHAR */ - bits -= (8 - r_off); - r_off = 8 - r_off; /* now, offset into code word */ - /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ - if ( bits >= 8 ) { -#ifdef NO_UCHAR - code |= (*bp++ & 0xff) << r_off; -#else - code |= *bp++ << r_off; -#endif /* NO_UCHAR */ - r_off += 8; - bits -= 8; - } - /* high order bits. */ - code |= (*bp & rmask[bits]) << r_off; -#endif /* vax */ - offset += n_bits; - - return code; -} - -#ifdef DEBUG -printcodes() -{ - /* - * Just print out codes from input file. For debugging. - */ - code_int code; - int col = 0, bits; - - bits = n_bits = INIT_BITS; - maxcode = MAXCODE(n_bits); - free_ent = ((block_compress) ? FIRST : 256 ); - while ( ( code = getcode() ) >= 0 ) { - if ( (code == CLEAR) && block_compress ) { - free_ent = FIRST - 1; - clear_flg = 1; - } - else if ( free_ent < maxmaxcode ) - free_ent++; - if ( bits != n_bits ) { - fprintf(stderr, "\nChange to %d bits\n", n_bits ); - bits = n_bits; - col = 0; - } - fprintf(stderr, "%5d%c", code, (col+=6) >= 74 ? (col = 0, '\n') : ' ' ); - } - putc( '\n', stderr ); - exit( 0 ); -} - -code_int sorttab[1<<BITS]; /* sorted pointers into htab */ - -dump_tab() /* dump string table */ -{ - register int i, first; - register ent; -#define STACK_SIZE 15000 - int stack_top = STACK_SIZE; - register c; - - if(do_decomp == 0) { /* compressing */ - register int flag = 1; - - for(i=0; i<hsize; i++) { /* build sort pointers */ - if((long)htabof(i) >= 0) { - sorttab[codetabof(i)] = i; - } - } - first = block_compress ? FIRST : 256; - for(i = first; i < free_ent; i++) { - fprintf(stderr, "%5d: \"", i); - de_stack[--stack_top] = '\n'; - de_stack[--stack_top] = '"'; - stack_top = in_stack((htabof(sorttab[i])>>maxbits)&0xff, - stack_top); - for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1); - ent > 256; - ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) { - stack_top = in_stack(htabof(sorttab[ent]) >> maxbits, - stack_top); - } - stack_top = in_stack(ent, stack_top); - fwrite( &de_stack[stack_top], 1, STACK_SIZE-stack_top, stderr); - stack_top = STACK_SIZE; - } - } else if(!debug) { /* decompressing */ - - for ( i = 0; i < free_ent; i++ ) { - ent = i; - c = tab_suffixof(ent); - if ( isascii(c) && isprint(c) ) - fprintf( stderr, "%5d: %5d/'%c' \"", - ent, tab_prefixof(ent), c ); - else - fprintf( stderr, "%5d: %5d/\\%03o \"", - ent, tab_prefixof(ent), c ); - de_stack[--stack_top] = '\n'; - de_stack[--stack_top] = '"'; - for ( ; ent != NULL; - ent = (ent >= FIRST ? tab_prefixof(ent) : NULL) ) { - stack_top = in_stack(tab_suffixof(ent), stack_top); - } - fwrite( &de_stack[stack_top], 1, STACK_SIZE - stack_top, stderr ); - stack_top = STACK_SIZE; - } - } -} - -int -in_stack(c, stack_top) - register c, stack_top; -{ - if ( (isascii(c) && isprint(c) && c != '\\') || c == ' ' ) { - de_stack[--stack_top] = c; - } else { - switch( c ) { - case '\n': de_stack[--stack_top] = 'n'; break; - case '\t': de_stack[--stack_top] = 't'; break; - case '\b': de_stack[--stack_top] = 'b'; break; - case '\f': de_stack[--stack_top] = 'f'; break; - case '\r': de_stack[--stack_top] = 'r'; break; - case '\\': de_stack[--stack_top] = '\\'; break; - default: - de_stack[--stack_top] = '0' + c % 8; - de_stack[--stack_top] = '0' + (c / 8) % 8; - de_stack[--stack_top] = '0' + c / 64; - break; - } - de_stack[--stack_top] = '\\'; - } - return stack_top; -} -#endif /* DEBUG */ - -writeerr() -{ - (void)fprintf(stderr, "compress: %s: %s\n", - ofname[0] ? ofname : "stdout", strerror(errno)); - (void)unlink(ofname); - exit(1); -} - -copystat(ifname, ofname) -char *ifname, *ofname; -{ - struct stat statbuf; - int mode; - struct utimbuf tp; - - fclose(stdout); - if (stat(ifname, &statbuf)) { /* Get stat on input file */ - perror(ifname); - return; - } - if ((statbuf.st_mode & S_IFMT/*0170000*/) != S_IFREG/*0100000*/) { - if(quiet) - fprintf(stderr, "%s: ", ifname); - fprintf(stderr, " -- not a regular file: unchanged"); - exit_stat = 1; - perm_stat = 1; - } else if (statbuf.st_nlink > 1) { - if(quiet) - fprintf(stderr, "%s: ", ifname); - fprintf(stderr, " -- has %d other links: unchanged", - statbuf.st_nlink - 1); - exit_stat = 1; - perm_stat = 1; - } else if (exit_stat == 2 && (!force)) { /* No compression: remove file.Z */ - if(!quiet) - fprintf(stderr, " -- file unchanged"); - } else { /* ***** Successful Compression ***** */ - exit_stat = 0; - mode = statbuf.st_mode & 07777; - if (chmod(ofname, mode)) /* Copy modes */ - perror(ofname); - chown(ofname, statbuf.st_uid, statbuf.st_gid); /* Copy ownership */ - tp.actime = statbuf.st_atime; - tp.modtime = statbuf.st_mtime; - utime(ofname, &tp); /* Update last accessed and modified times */ - if (unlink(ifname)) /* Remove input file */ - perror(ifname); - if(!quiet) - fprintf(stderr, " -- replaced with %s", ofname); - return; /* Successful return */ - } - - /* Unsuccessful return -- one of the tests failed */ - if (unlink(ofname)) - perror(ofname); -} - -void -onintr ( ) -{ - if (!precious) - unlink ( ofname ); - exit ( 1 ); -} - -void -oops ( ) /* wild pointer -- assume bad input */ -{ - if ( do_decomp ) - fprintf ( stderr, "uncompress: corrupt input\n" ); - unlink ( ofname ); - exit ( 1 ); -} - -cl_block () /* table clear for block compress */ -{ - register long int rat; - - checkpoint = in_count + CHECK_GAP; -#ifdef DEBUG - if ( debug ) { - fprintf ( stderr, "count: %ld, ratio: ", in_count ); - prratio ( stderr, in_count, bytes_out ); - fprintf ( stderr, "\n"); - } -#endif /* DEBUG */ - - if(in_count > 0x007fffff) { /* shift will overflow */ - rat = bytes_out >> 8; - if(rat == 0) { /* Don't divide by zero */ - rat = 0x7fffffff; - } else { - rat = in_count / rat; - } - } else { - rat = (in_count << 8) / bytes_out; /* 8 fractional bits */ - } - if ( rat > ratio ) { - ratio = rat; - } else { - ratio = 0; -#ifdef DEBUG - if(verbose) - dump_tab(); /* dump string table */ -#endif - cl_hash ( (count_int) hsize ); - free_ent = FIRST; - clear_flg = 1; - output ( (code_int) CLEAR ); -#ifdef DEBUG - if(debug) - fprintf ( stderr, "clear\n" ); -#endif /* DEBUG */ - } -} - -cl_hash(hsize) /* reset code table */ - register count_int hsize; -{ - register count_int *htab_p = htab+hsize; - register long i; - register long m1 = -1; - - i = hsize - 16; - do { /* might use Sys V memset(3) here */ - *(htab_p-16) = m1; - *(htab_p-15) = m1; - *(htab_p-14) = m1; - *(htab_p-13) = m1; - *(htab_p-12) = m1; - *(htab_p-11) = m1; - *(htab_p-10) = m1; - *(htab_p-9) = m1; - *(htab_p-8) = m1; - *(htab_p-7) = m1; - *(htab_p-6) = m1; - *(htab_p-5) = m1; - *(htab_p-4) = m1; - *(htab_p-3) = m1; - *(htab_p-2) = m1; - *(htab_p-1) = m1; - htab_p -= 16; - } while ((i -= 16) >= 0); - for ( i += 16; i > 0; i-- ) - *--htab_p = m1; -} - -prratio(stream, num, den) -FILE *stream; -long int num, den; -{ - register int q; /* Doesn't need to be long */ - - if(num > 214748L) { /* 2147483647/10000 */ - q = num / (den / 10000L); - } else { - q = 10000L * num / den; /* Long calculations, though */ - } - if (q < 0) { - putc('-', stream); - q = -q; - } - fprintf(stream, "%d.%02d%%", q / 100, q % 100); -} - -usage() -{ - (void)fprintf(stderr, -#ifdef DEBUG - "compress [-CDVcdfnv] [-b maxbits] [file ...]\n"); -#else - "compress [-Ccdfnv] [-b maxbits] [file ...]\n"); -#endif - exit(1); -} diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt index 1c96497..8dc3b2c 100644 --- a/Utilities/cmcurl/CMakeLists.txt +++ b/Utilities/cmcurl/CMakeLists.txt @@ -77,7 +77,7 @@ endif(APPLE) # Disable warnings to avoid changing 3rd party code. if(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") diff --git a/Utilities/cmexpat/CMakeLists.txt b/Utilities/cmexpat/CMakeLists.txt index 470fcba..13eb56d 100644 --- a/Utilities/cmexpat/CMakeLists.txt +++ b/Utilities/cmexpat/CMakeLists.txt @@ -1,6 +1,6 @@ # Disable warnings to avoid changing 3rd party code. IF(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") diff --git a/Utilities/cmjsoncpp/CMakeLists.txt b/Utilities/cmjsoncpp/CMakeLists.txt index ef370cc..764be8d 100644 --- a/Utilities/cmjsoncpp/CMakeLists.txt +++ b/Utilities/cmjsoncpp/CMakeLists.txt @@ -2,7 +2,7 @@ project(JsonCpp CXX) # Disable warnings to avoid changing 3rd party code. if(CMAKE_CXX_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "PathScale") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -woffall") diff --git a/Utilities/cmjsoncpp/include/json/config.h b/Utilities/cmjsoncpp/include/json/config.h index eb52e71..34f7314 100644 --- a/Utilities/cmjsoncpp/include/json/config.h +++ b/Utilities/cmjsoncpp/include/json/config.h @@ -5,13 +5,14 @@ #ifndef JSON_CONFIG_H_INCLUDED #define JSON_CONFIG_H_INCLUDED -#include <stddef.h> -#include <string> //typedef String -#include <stdint.h> //typedef int64_t, uint64_t // Include KWSys Large File Support configuration. #include <cmsys/Configure.h> +#include <stddef.h> +#include <string> //typedef String +#include <stdint.h> //typedef int64_t, uint64_t + #if defined(_MSC_VER) # pragma warning(push,1) #endif diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index d7af6e2..53b3a83 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -60,7 +60,7 @@ SET(CMAKE_REQUIRED_FLAGS) # Disable warnings to avoid changing 3rd party code. IF(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") diff --git a/Utilities/cmliblzma/CMakeLists.txt b/Utilities/cmliblzma/CMakeLists.txt index e9f8826..b443fd6 100644 --- a/Utilities/cmliblzma/CMakeLists.txt +++ b/Utilities/cmliblzma/CMakeLists.txt @@ -183,7 +183,7 @@ INCLUDE_DIRECTORIES( # Disable warnings to avoid changing 3rd party code. IF(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") diff --git a/Utilities/cmlibrhash/CMakeLists.txt b/Utilities/cmlibrhash/CMakeLists.txt index aa28055..6067b7d 100644 --- a/Utilities/cmlibrhash/CMakeLists.txt +++ b/Utilities/cmlibrhash/CMakeLists.txt @@ -2,7 +2,7 @@ project(librhash C) # Disable warnings to avoid changing 3rd party code. if(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") diff --git a/Utilities/cmlibuv/CMakeLists.txt b/Utilities/cmlibuv/CMakeLists.txt index a62c516..2e781f1 100644 --- a/Utilities/cmlibuv/CMakeLists.txt +++ b/Utilities/cmlibuv/CMakeLists.txt @@ -2,7 +2,7 @@ project(libuv C) # Disable warnings to avoid changing 3rd party code. if(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") diff --git a/Utilities/cmlibuv/src/unix/atomic-ops.h b/Utilities/cmlibuv/src/unix/atomic-ops.h index 7cac1f9..be741dc 100644 --- a/Utilities/cmlibuv/src/unix/atomic-ops.h +++ b/Utilities/cmlibuv/src/unix/atomic-ops.h @@ -37,7 +37,7 @@ UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)) { : "r" (newval), "0" (oldval) : "memory"); return out; -#elif defined(_AIX) && defined(__xlC__) +#elif defined(_AIX) && (defined(__xlC__) || defined(__ibmxl__)) const int out = (*(volatile int*) ptr); __compare_and_swap(ptr, &oldval, newval); return out; @@ -63,7 +63,7 @@ UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)) { : "r" (newval), "0" (oldval) : "memory"); return out; -#elif defined(_AIX) && defined(__xlC__) +#elif defined(_AIX) && (defined(__xlC__) || defined(__ibmxl__)) const long out = (*(volatile int*) ptr); # if defined(__64BIT__) __compare_and_swaplp(ptr, &oldval, newval); diff --git a/Utilities/cmzlib/CMakeLists.txt b/Utilities/cmzlib/CMakeLists.txt index 0be48f1..888c3ff 100644 --- a/Utilities/cmzlib/CMakeLists.txt +++ b/Utilities/cmzlib/CMakeLists.txt @@ -2,7 +2,7 @@ PROJECT(CMZLIB) # Disable warnings to avoid changing 3rd party code. if(CMAKE_C_COMPILER_ID MATCHES - "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") |