diff options
170 files changed, 2028 insertions, 1503 deletions
diff --git a/.clang-tidy b/.clang-tidy index e8d39ce..8d79b0c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,12 +10,13 @@ modernize-*,\ -modernize-deprecated-headers,\ -modernize-pass-by-value,\ -modernize-raw-string-literal,\ --modernize-replace-auto-ptr,\ +-modernize-return-braced-init-list,\ -modernize-use-auto,\ -modernize-use-default-member-init,\ -modernize-use-emplace,\ -modernize-use-equals-default,\ -modernize-use-equals-delete,\ +-modernize-use-noexcept,\ -modernize-use-transparent-functors,\ -modernize-use-using,\ performance-*,\ diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake index a0aacb4..dc9f0ba 100644 --- a/CMakeCPack.cmake +++ b/CMakeCPack.cmake @@ -245,5 +245,23 @@ configure_file("${CMake_SOURCE_DIR}/CMakeCPackOptions.cmake.in" "${CMake_BINARY_DIR}/CMakeCPackOptions.cmake" @ONLY) set(CPACK_PROJECT_CONFIG_FILE "${CMake_BINARY_DIR}/CMakeCPackOptions.cmake") +set(CPACK_SOURCE_IGNORE_FILES + # Files specific to version control. + "/\\\\.git/" + "/\\\\.gitattributes$" + "/\\\\.github/" + "/\\\\.gitignore$" + "/\\\\.hooks-config$" + + # Cygwin package build. + "/\\\\.build/" + + # Temporary files. + "\\\\.swp$" + "\\\\.#" + "/#" + "~$" + ) + # include CPack model once all variables are set include(CPack) diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in index ad0c245..a08c97d 100644 --- a/CMakeCPackOptions.cmake.in +++ b/CMakeCPackOptions.cmake.in @@ -208,12 +208,6 @@ if(CPACK_GENERATOR MATCHES "IFW") endif() -if(CPACK_GENERATOR MATCHES "CygwinSource") - # when packaging source make sure the .build directory is not included - set(CPACK_SOURCE_IGNORE_FILES - "/CVS/" "/\\.build/" "/\\.svn/" "\\.swp$" "\\.#" "/#" "~$") -endif() - if("${CPACK_GENERATOR}" STREQUAL "PackageMaker") if(CMAKE_PACKAGE_QTGUI) set(CPACK_PACKAGE_DEFAULT_LOCATION "/Applications") diff --git a/CMakeLists.txt b/CMakeLists.txt index c578ec3..f14f62f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,6 +250,12 @@ if(CMake_RUN_CLANG_TIDY) message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!") endif() set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + + # provide definitions for targets that require a rebuild once .clang-tidy changes + file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1) + set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}") + unset(clang_tidy_sha1) + endif() configure_file(.clang-tidy .clang-tidy COPYONLY) diff --git a/Copyright.txt b/Copyright.txt index 978be0a..3c92a81 100644 --- a/Copyright.txt +++ b/Copyright.txt @@ -76,6 +76,7 @@ The following individuals and institutions are among the Contributors: * Nicolas Bock <nicolasbock@gmail.com> * Nicolas Despres <nicolas.despres@gmail.com> * Nikita Krupen'ko <krnekit@gmail.com> +* NVIDIA Corporation <www.nvidia.com> * OpenGamma Ltd. <opengamma.com> * Per Øyvind Karlsen <peroyvind@mandriva.org> * Peter Collingbourne <peter@pcc.me.uk> diff --git a/Help/dev/source.rst b/Help/dev/source.rst index b40a884..d0c19eb 100644 --- a/Help/dev/source.rst +++ b/Help/dev/source.rst @@ -26,19 +26,9 @@ C++ Subset Permitted CMake requires compiling as C++11 or above. However, in order to support building on older toolchains some constructs need to be handled with care: -* Do not use ``CM_AUTO_PTR`` or ``std::auto_ptr``. +* Do not use ``std::auto_ptr``. - The ``std::auto_ptr`` template is deprecated in C++11. The ``CM_AUTO_PTR`` - macro remains leftover from C++98 support until its uses can be ported to - ``std::unique_ptr``. Do not add new uses of the macro. - -* Use ``CM_EQ_DELETE;`` instead of ``= delete;``. - - Older C++11 compilers do not support deleting functions. Using - ``CM_EQ_DELETE`` will delete the functions if the compiler supports it and - give them no implementation otherwise. Calling such a function will lead - to compiler errors if the compiler supports *deleted* functions and linker - errors otherwise. + The ``std::auto_ptr`` template is deprecated in C++11. Use ``std::unique_ptr``. * Use ``CM_DISABLE_COPY(Class)`` to mark classes as non-copyable. diff --git a/Help/envvar/ASM_DIALECT.rst b/Help/envvar/ASM_DIALECT.rst new file mode 100644 index 0000000..ec48f71 --- /dev/null +++ b/Help/envvar/ASM_DIALECT.rst @@ -0,0 +1,11 @@ +ASM<DIALECT> +------------ + +Preferred executable for compiling a specific dialect of assembly language +files. ``ASM<DIALECT>`` can be ``ASM``, ``ASM_NASM``, ``ASM_MASM`` or +``ASM-ATT``. Will only be used by CMake on the first configuration to determine +``ASM<DIALECT>`` compiler, after which the value for ``ASM<DIALECT>`` is stored +in the cache as +:variable:`CMAKE_ASM<DIALECT>_COMPILER <CMAKE_<LANG>_COMPILER>`. For subsequent +configuration runs, the environment variable will be ignored in favor of +:variable:`CMAKE_ASM<DIALECT>_COMPILER <CMAKE_<LANG>_COMPILER>`. diff --git a/Help/envvar/ASM_DIALECTFLAGS.rst b/Help/envvar/ASM_DIALECTFLAGS.rst new file mode 100644 index 0000000..4ed02fe --- /dev/null +++ b/Help/envvar/ASM_DIALECTFLAGS.rst @@ -0,0 +1,11 @@ +ASM<DIALECT>FLAGS +----------------- + +Default compilation flags to be used when compiling a specific dialect of an +assembly language. ``ASM<DIALECT>FLAGS`` can be ``ASMFLAGS``, ``ASM_NASMFLAGS``, +``ASM_MASMFLAGS`` or ``ASM-ATTFLAGS``. Will only be used by CMake on the +first configuration to determine ``ASM<DIALECT>`` default compilation flags, after +which the value for ``ASM<DIALECT>FLAGS`` is stored in the cache as +:variable:`CMAKE_ASM<DIALECT>_FLAGS <CMAKE_<LANG>_FLAGS>`. For any configuration +run (including the first), the environment variable will be ignored if the +:variable:`CMAKE_ASM<DIALECT>_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/envvar/CC.rst b/Help/envvar/CC.rst new file mode 100644 index 0000000..7e68110 --- /dev/null +++ b/Help/envvar/CC.rst @@ -0,0 +1,9 @@ +CC +-- + +Preferred executable for compiling ``C`` language files. Will only be used by +CMake on the first configuration to determine ``C`` compiler, after which the +value for ``CC`` is stored in the cache as +:variable:`CMAKE_C_COMPILER <CMAKE_<LANG>_COMPILER>`. For any configuration run +(including the first), the environment variable will be ignored if the +:variable:`CMAKE_C_COMPILER <CMAKE_<LANG>_COMPILER>` variable is defined. diff --git a/Help/envvar/CFLAGS.rst b/Help/envvar/CFLAGS.rst new file mode 100644 index 0000000..60b2cd3 --- /dev/null +++ b/Help/envvar/CFLAGS.rst @@ -0,0 +1,9 @@ +CFLAGS +------ + +Default compilation flags to be used when compiling ``C`` files. Will only be +used by CMake on the first configuration to determine ``CC`` default compilation +flags, after which the value for ``CFLAGS`` is stored in the cache +as :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>`. For any configuration run +(including the first), the environment variable will be ignored if the +:variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/envvar/CMAKE_CONFIG_TYPE.rst b/Help/envvar/CMAKE_CONFIG_TYPE.rst new file mode 100644 index 0000000..1306b47 --- /dev/null +++ b/Help/envvar/CMAKE_CONFIG_TYPE.rst @@ -0,0 +1,5 @@ +CMAKE_CONFIG_TYPE +----------------- + +The default build configuration for :ref:`Build Tool Mode` and +``ctest`` build handler when there is no explicit configuration given. diff --git a/Help/envvar/CMAKE_MSVCIDE_RUN_PATH.rst b/Help/envvar/CMAKE_MSVCIDE_RUN_PATH.rst new file mode 100644 index 0000000..54d5f9e --- /dev/null +++ b/Help/envvar/CMAKE_MSVCIDE_RUN_PATH.rst @@ -0,0 +1,8 @@ +CMAKE_MSVCIDE_RUN_PATH +---------------------- + +Extra PATH locations for custom commands when using +:generator:`Visual Studio 9 2008` (or above) generators. + +The ``CMAKE_MSVCIDE_RUN_PATH`` environment variable sets the default value for +the :variable:`CMAKE_MSVCIDE_RUN_PATH` variable if not already explicitly set. diff --git a/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst b/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst new file mode 100644 index 0000000..8bbf993 --- /dev/null +++ b/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst @@ -0,0 +1,8 @@ +CMAKE_OSX_ARCHITECTURES +----------------------- + +Target specific architectures for OS X. + +The ``CMAKE_OSX_ARCHITECTURES`` environment variable sets the default value for +the :variable:`CMAKE_OSX_ARCHITECTURES` variable. See +:prop_tgt:`OSX_ARCHITECTURES` for more information. diff --git a/Help/envvar/CSFLAGS.rst b/Help/envvar/CSFLAGS.rst new file mode 100644 index 0000000..251ddc5 --- /dev/null +++ b/Help/envvar/CSFLAGS.rst @@ -0,0 +1,9 @@ +CSFLAGS +------- + +Preferred executable for compiling ``CSharp`` language files. Will only be +used by CMake on the first configuration to determine ``CSharp`` default +compilation flags, after which the value for ``CSFLAGS`` is stored in the cache +as :variable:`CMAKE_CSharp_FLAGS <CMAKE_<LANG>_FLAGS>`. For any configuration +run (including the first), the environment variable will be ignored if the +:variable:`CMAKE_CSharp_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/envvar/CTEST_INTERACTIVE_DEBUG_MODE.rst b/Help/envvar/CTEST_INTERACTIVE_DEBUG_MODE.rst new file mode 100644 index 0000000..25ed14f --- /dev/null +++ b/Help/envvar/CTEST_INTERACTIVE_DEBUG_MODE.rst @@ -0,0 +1,5 @@ +CTEST_INTERACTIVE_DEBUG_MODE +---------------------------- + +Environment variable that will exist and be set to ``1`` when a test executed +by CTest is run in interactive mode. diff --git a/Help/envvar/CTEST_OUTPUT_ON_FAILURE.rst b/Help/envvar/CTEST_OUTPUT_ON_FAILURE.rst new file mode 100644 index 0000000..1fcf42b --- /dev/null +++ b/Help/envvar/CTEST_OUTPUT_ON_FAILURE.rst @@ -0,0 +1,7 @@ +CTEST_OUTPUT_ON_FAILURE +----------------------- + +Boolean environment variable that controls if the output should be logged for +failed tests. Set the value to 1, True, or ON to enable output on failure. +See :manual:`ctest(1)` for more information on controlling output of failed +tests. diff --git a/Help/envvar/CTEST_PARALLEL_LEVEL.rst b/Help/envvar/CTEST_PARALLEL_LEVEL.rst new file mode 100644 index 0000000..c767a01 --- /dev/null +++ b/Help/envvar/CTEST_PARALLEL_LEVEL.rst @@ -0,0 +1,5 @@ +CTEST_PARALLEL_LEVEL +-------------------- + +Specify the number of tests for CTest to run in parallel. See :manual:`ctest(1)` +for more information on parallel test execution. diff --git a/Help/envvar/CTEST_USE_LAUNCHERS_DEFAULT.rst b/Help/envvar/CTEST_USE_LAUNCHERS_DEFAULT.rst new file mode 100644 index 0000000..8d8eea5 --- /dev/null +++ b/Help/envvar/CTEST_USE_LAUNCHERS_DEFAULT.rst @@ -0,0 +1,4 @@ +CTEST_USE_LAUNCHERS_DEFAULT +--------------------------- + +Initializes the :variable:`CTEST_USE_LAUNCHERS` variable if not already defined. diff --git a/Help/envvar/CUDACXX.rst b/Help/envvar/CUDACXX.rst new file mode 100644 index 0000000..8a5fd4b --- /dev/null +++ b/Help/envvar/CUDACXX.rst @@ -0,0 +1,9 @@ +CUDACXX +------- + +Preferred executable for compiling ``CUDA`` language files. Will only be used by +CMake on the first configuration to determine ``CUDA`` compiler, after which the +value for ``CUDA`` is stored in the cache as +:variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>`. For any configuration +run (including the first), the environment variable will be ignored if the +:variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>` variable is defined. diff --git a/Help/envvar/CUDAFLAGS.rst b/Help/envvar/CUDAFLAGS.rst new file mode 100644 index 0000000..3dff49f --- /dev/null +++ b/Help/envvar/CUDAFLAGS.rst @@ -0,0 +1,9 @@ +CUDAFLAGS +--------- + +Default compilation flags to be used when compiling ``CUDA`` files. Will only be +used by CMake on the first configuration to determine ``CUDA`` default +compilation flags, after which the value for ``CUDAFLAGS`` is stored in the +cache as :variable:`CMAKE_CUDA_FLAGS <CMAKE_<LANG>_FLAGS>`. For any configuration +run (including the first), the environment variable will be ignored if +the :variable:`CMAKE_CUDA_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/envvar/CUDAHOSTCXX.rst b/Help/envvar/CUDAHOSTCXX.rst new file mode 100644 index 0000000..f0f94f6 --- /dev/null +++ b/Help/envvar/CUDAHOSTCXX.rst @@ -0,0 +1,9 @@ +CUDAHOSTCXX +----------- + +Preferred executable for compiling host code when compiling ``CUDA`` +language files. Will only be used by CMake on the first configuration to +determine ``CUDA`` host compiler, after which the value for ``CUDAHOSTCXX`` is +stored in the cache as :variable:`CMAKE_CUDA_HOST_COMPILER`. For any +configuration run (including the first), the environment variable will be +ignored if the :variable:`CMAKE_CUDA_HOST_COMPILER` variable is defined. diff --git a/Help/envvar/CXX.rst b/Help/envvar/CXX.rst new file mode 100644 index 0000000..3b1e445 --- /dev/null +++ b/Help/envvar/CXX.rst @@ -0,0 +1,9 @@ +CXX +--- + +Preferred executable for compiling ``CXX`` language files. Will only be used by +CMake on the first configuration to determine ``CXX`` compiler, after which the +value for ``CXX`` is stored in the cache as +:variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>`. For any configuration +run (including the first), the environment variable will be ignored if the +:variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>` variable is defined. diff --git a/Help/envvar/CXXFLAGS.rst b/Help/envvar/CXXFLAGS.rst new file mode 100644 index 0000000..8b58abd --- /dev/null +++ b/Help/envvar/CXXFLAGS.rst @@ -0,0 +1,9 @@ +CXXFLAGS +-------- + +Default compilation flags to be used when compiling ``CXX`` (C++) files. Will +only be used by CMake on the first configuration to determine ``CXX`` default +compilation flags, after which the value for ``CXXFLAGS`` is stored in the cache +as :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>`. For any configuration run ( +including the first), the environment variable will be ignored if +the :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/envvar/DASHBOARD_TEST_FROM_CTEST.rst b/Help/envvar/DASHBOARD_TEST_FROM_CTEST.rst new file mode 100644 index 0000000..fab1c0c --- /dev/null +++ b/Help/envvar/DASHBOARD_TEST_FROM_CTEST.rst @@ -0,0 +1,5 @@ +DASHBOARD_TEST_FROM_CTEST +------------------------- + +Environment variable that will exist when a test executed by CTest is run +in non-interactive mode. The value will be equal to :variable:`CMAKE_VERSION`. diff --git a/Help/envvar/FC.rst b/Help/envvar/FC.rst new file mode 100644 index 0000000..7d293fd --- /dev/null +++ b/Help/envvar/FC.rst @@ -0,0 +1,10 @@ +FC +-- + +Preferred executable for compiling ``Fortran`` language files. Will only be used +by CMake on the first configuration to determine ``Fortran`` compiler, after +which the value for ``Fortran`` is stored in the cache as +:variable:`CMAKE_Fortran_COMPILER <CMAKE_<LANG>_COMPILER>`. For any +configuration run (including the first), the environment variable will be +ignored if the :variable:`CMAKE_Fortran_COMPILER <CMAKE_<LANG>_COMPILER>` +variable is defined. diff --git a/Help/envvar/FFLAGS.rst b/Help/envvar/FFLAGS.rst new file mode 100644 index 0000000..19d6169 --- /dev/null +++ b/Help/envvar/FFLAGS.rst @@ -0,0 +1,9 @@ +FFLAGS +------ + +Default compilation flags to be used when compiling ``Fortran`` files. Will only +be used by CMake on the first configuration to determine ``Fortran`` default +compilation flags, after which the value for ``FFLAGS`` is stored in the cache +as :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>`. For any configuration +run (including the first), the environment variable will be ignored if +the :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/envvar/LDFLAGS.rst b/Help/envvar/LDFLAGS.rst new file mode 100644 index 0000000..52da99c --- /dev/null +++ b/Help/envvar/LDFLAGS.rst @@ -0,0 +1,10 @@ +LDFLAGS +------- + +Will only be used by CMake on the first configuration to determine the default +linker flags, after which the value for ``LDFLAGS`` is stored in the cache +as :variable:`CMAKE_EXE_LINKER_FLAGS_INIT`, +:variable:`CMAKE_SHARED_LINKER_FLAGS_INIT`, and +:variable:`CMAKE_MODULE_LINKER_FLAGS_INIT`. For any configuration run +(including the first), the environment variable will be ignored if the +equivalent ``CMAKE_<TYPE>_LINKER_FLAGS_INIT`` variable is defined. diff --git a/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst b/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst new file mode 100644 index 0000000..e6051b4 --- /dev/null +++ b/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst @@ -0,0 +1,8 @@ +MACOSX_DEPLOYMENT_TARGET +------------------------ + +Specify the minimum version of OS X on which the target binaries are +to be deployed. + +The ``MACOSX_DEPLOYMENT_TARGET`` environment variable sets the default value for +the :variable:`CMAKE_OSX_DEPLOYMENT_TARGET` variable. diff --git a/Help/envvar/RC.rst b/Help/envvar/RC.rst new file mode 100644 index 0000000..6c2db19 --- /dev/null +++ b/Help/envvar/RC.rst @@ -0,0 +1,9 @@ +RC +-- + +Preferred executable for compiling ``resource`` files. Will only be used by CMake +on the first configuration to determine ``resource`` compiler, after which the +value for ``RC`` is stored in the cache as +:variable:`CMAKE_RC_COMPILER <CMAKE_<LANG>_COMPILER>`. For any configuration run +(including the first), the environment variable will be ignored if the +:variable:`CMAKE_RC_COMPILER <CMAKE_<LANG>_COMPILER>` variable is defined. diff --git a/Help/envvar/RCFLAGS.rst b/Help/envvar/RCFLAGS.rst new file mode 100644 index 0000000..4f2f31c --- /dev/null +++ b/Help/envvar/RCFLAGS.rst @@ -0,0 +1,9 @@ +RCFLAGS +------- + +Default compilation flags to be used when compiling ``resource`` files. Will +only be used by CMake on the first configuration to determine ``resource`` +default compilation flags, after which the value for ``RCFLAGS`` is stored in +the cache as :variable:`CMAKE_RC_FLAGS <CMAKE_<LANG>_FLAGS>`. For any +configuration run (including the first), the environment variable will be ignored +if the :variable:`CMAKE_RC_FLAGS <CMAKE_<LANG>_FLAGS>` variable is defined. diff --git a/Help/index.rst b/Help/index.rst index 97cd107..3dccdda 100644 --- a/Help/index.rst +++ b/Help/index.rst @@ -40,6 +40,7 @@ Reference Manuals /manual/cmake-qt.7 /manual/cmake-toolchains.7 /manual/cmake-variables.7 + /manual/cmake-env-variables.7 .. only:: html or text diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst new file mode 100644 index 0000000..fed129e --- /dev/null +++ b/Help/manual/cmake-env-variables.7.rst @@ -0,0 +1,54 @@ +.. cmake-manual-description: CMake Environment Variables Reference + +cmake-env-variables(7) +********************** + +.. only:: html + + .. contents:: + +Environment Variables that Control the Build +============================================ + +.. toctree:: + :maxdepth: 1 + + /envvar/CMAKE_CONFIG_TYPE + /envvar/CMAKE_MSVCIDE_RUN_PATH + /envvar/CMAKE_OSX_ARCHITECTURES + /envvar/LDFLAGS + /envvar/MACOSX_DEPLOYMENT_TARGET + +Environment Variables for Languages +=================================== + +.. toctree:: + :maxdepth: 1 + + /envvar/ASM_DIALECT + /envvar/ASM_DIALECTFLAGS + /envvar/CC + /envvar/CFLAGS + /envvar/CSFLAGS + /envvar/CUDACXX + /envvar/CUDAFLAGS + /envvar/CUDAHOSTCXX + /envvar/CXX + /envvar/CXXFLAGS + /envvar/FC + /envvar/FFLAGS + /envvar/RC + /envvar/RCFLAGS + +Environment Variables for CTest +=============================== + +.. toctree:: + :maxdepth: 1 + + /envvar/CMAKE_CONFIG_TYPE + /envvar/CTEST_INTERACTIVE_DEBUG_MODE + /envvar/CTEST_OUTPUT_ON_FAILURE + /envvar/CTEST_PARALLEL_LEVEL + /envvar/CTEST_USE_LAUNCHERS_DEFAULT + /envvar/DASHBOARD_TEST_FROM_CTEST diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst index 7052e0a..cafeae1 100644 --- a/Help/manual/cmake-qt.7.rst +++ b/Help/manual/cmake-qt.7.rst @@ -59,9 +59,10 @@ The :prop_tgt:`AUTOMOC` target property controls whether :manual:`cmake(1)` inspects the C++ files in the target to determine if they require ``moc`` to be run, and to create rules to execute ``moc`` at the appropriate time. -If a ``Q_OBJECT`` or ``Q_GADGET`` macro is found in a header file, ``moc`` -will be run on the file. The result will be put into a file named according -to ``moc_<basename>.cpp``. If the macro is found in a C++ implementation +If a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` is found in a header file, +``moc`` will be run on the file. The result will be put into a file named +according to ``moc_<basename>.cpp``. +If the macro is found in a C++ implementation file, the moc output will be put into a file named according to ``<basename>.moc``, following the Qt conventions. The ``<basename>.moc`` must be included by the user in the C++ implementation file with a preprocessor @@ -73,8 +74,8 @@ automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. * This differs from CMake 3.7 and below; see their documentation for details. -* For multi configuration generators, the include directory is - ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. +* For :prop_gbl:`multi configuration generators <GENERATOR_IS_MULTI_CONFIG>`, + the include directory is ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. @@ -95,9 +96,7 @@ following targets by setting the :variable:`CMAKE_AUTOMOC` variable. The options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS` variable may be populated to pre-set the options for all following targets. -The appearance of the strings ``Q_OBJECT`` or ``Q_GADGET`` in a source file -determines if it needs to be ``moc`` processed. To search for additional -strings, list them in :prop_tgt:`AUTOMOC_MACRO_NAMES`. +Additional macro names to search for can be added to :prop_tgt:`AUTOMOC_MACRO_NAMES`. Additional ``moc`` dependency file names can be extracted from source code by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`. @@ -133,8 +132,8 @@ automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. * This differs from CMake 3.7 and below; see their documentation for details. -* For multi configuration generators, the include directory is - ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. +* For :prop_gbl:`multi configuration generators <GENERATOR_IS_MULTI_CONFIG>`, + the include directory is ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 1b4873d..cba81e5 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -367,6 +367,7 @@ Variables for Languages /variable/CMAKE_COMPILER_IS_GNUCC /variable/CMAKE_COMPILER_IS_GNUCXX /variable/CMAKE_COMPILER_IS_GNUG77 + /variable/CMAKE_CUDA_HOST_COMPILER /variable/CMAKE_CUDA_EXTENSIONS /variable/CMAKE_CUDA_STANDARD /variable/CMAKE_CUDA_STANDARD_REQUIRED diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 6eef6c6..6a21683 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -138,6 +138,8 @@ Options .. include:: OPTIONS_HELP.txt +.. _`Build Tool Mode`: + Build Tool Mode =============== diff --git a/Help/policy/CMP0071.rst b/Help/policy/CMP0071.rst index 61f14dc..ee33aa1 100644 --- a/Help/policy/CMP0071.rst +++ b/Help/policy/CMP0071.rst @@ -4,16 +4,15 @@ CMP0071 Let :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` process :prop_sf:`GENERATED` files. -CMake 3.10 and newer process regular *and* :prop_sf:`GENERATED` source files -in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`. -In CMake 3.9 and lower, only regular source files were processed in -:prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`, -:prop_sf:`GENERATED` source files were ignored. +Since version 3.10, CMake processes **regular** and :prop_sf:`GENERATED` +source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`. +In earlier CMake versions, only **regular** source files were processed. +:prop_sf:`GENERATED` source files were ignored silently. -This policy affects how :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` process -source files that are :prop_sf:`GENERATED`. +This policy affects how source files that are :prop_sf:`GENERATED` +get treated in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`. -The ``OLD`` behavior for this policy is to *ignore* :prop_sf:`GENERATED` +The ``OLD`` behavior for this policy is to ignore :prop_sf:`GENERATED` source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`. The ``NEW`` behavior for this policy is to process :prop_sf:`GENERATED` @@ -21,10 +20,19 @@ source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` just like regular source files. .. note:: - To exclude source files from :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` - processing, the boolean source file properties - :prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC` and :prop_sf:`SKIP_AUTOGEN` - can be set accordingly. + + To silence the CMP0071 warning source files can be excluded from + :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` processing by setting the + source file properties :prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC` or + :prop_sf:`SKIP_AUTOGEN`. + +Source skip example:: + + # ... + set_property(SOURCE /path/to/file1.h PROPERTY SKIP_AUTOMOC ON) + set_property(SOURCE /path/to/file2.h PROPERTY SKIP_AUTOUIC ON) + set_property(SOURCE /path/to/file3.h PROPERTY SKIP_AUTOGEN ON) + # ... This policy was introduced in CMake version 3.10. CMake version |release| warns when the policy is not set and uses ``OLD`` behavior. diff --git a/Help/prop_sf/SKIP_AUTOGEN.rst b/Help/prop_sf/SKIP_AUTOGEN.rst index 6bf2409..f31185a 100644 --- a/Help/prop_sf/SKIP_AUTOGEN.rst +++ b/Help/prop_sf/SKIP_AUTOGEN.rst @@ -4,5 +4,14 @@ SKIP_AUTOGEN Exclude the source file from :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` processing (for Qt projects). -For finer control see :prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC` and -:prop_sf:`SKIP_AUTORCC`. +For finer exclusion control see :prop_sf:`SKIP_AUTOMOC`, +:prop_sf:`SKIP_AUTOUIC` and :prop_sf:`SKIP_AUTORCC`. + +EXAMPLE +^^^^^^^ + +.. code-block:: cmake + + # ... + set_property(SOURCE file.h PROPERTY SKIP_AUTOGEN ON) + # ... diff --git a/Help/prop_sf/SKIP_AUTOMOC.rst b/Help/prop_sf/SKIP_AUTOMOC.rst index 2245ca6..a929448 100644 --- a/Help/prop_sf/SKIP_AUTOMOC.rst +++ b/Help/prop_sf/SKIP_AUTOMOC.rst @@ -3,4 +3,13 @@ SKIP_AUTOMOC Exclude the source file from :prop_tgt:`AUTOMOC` processing (for Qt projects). -For broader control see :prop_sf:`SKIP_AUTOGEN` +For broader exclusion control see :prop_sf:`SKIP_AUTOGEN`. + +EXAMPLE +^^^^^^^ + +.. code-block:: cmake + + # ... + set_property(SOURCE file.h PROPERTY SKIP_AUTOMOC ON) + # ... diff --git a/Help/prop_sf/SKIP_AUTORCC.rst b/Help/prop_sf/SKIP_AUTORCC.rst index 394d8f8..bccccfc 100644 --- a/Help/prop_sf/SKIP_AUTORCC.rst +++ b/Help/prop_sf/SKIP_AUTORCC.rst @@ -3,4 +3,13 @@ SKIP_AUTORCC Exclude the source file from :prop_tgt:`AUTORCC` processing (for Qt projects). -For broader control see :prop_sf:`SKIP_AUTOGEN` +For broader exclusion control see :prop_sf:`SKIP_AUTOGEN`. + +EXAMPLE +^^^^^^^ + +.. code-block:: cmake + + # ... + set_property(SOURCE file.qrc PROPERTY SKIP_AUTORCC ON) + # ... diff --git a/Help/prop_sf/SKIP_AUTOUIC.rst b/Help/prop_sf/SKIP_AUTOUIC.rst index 50f78ef..4eda726 100644 --- a/Help/prop_sf/SKIP_AUTOUIC.rst +++ b/Help/prop_sf/SKIP_AUTOUIC.rst @@ -3,4 +3,13 @@ SKIP_AUTOUIC Exclude the source file from :prop_tgt:`AUTOUIC` processing (for Qt projects). -For broader control see :prop_sf:`SKIP_AUTOGEN` +For broader exclusion control see :prop_sf:`SKIP_AUTOGEN`. + +EXAMPLE +^^^^^^^ + +.. code-block:: cmake + + # ... + set_property(SOURCE file.h PROPERTY SKIP_AUTOUIC ON) + # ... diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst index 61813be68..641ac09 100644 --- a/Help/prop_tgt/AUTOMOC.rst +++ b/Help/prop_tgt/AUTOMOC.rst @@ -12,25 +12,26 @@ When this property is set ``ON``, CMake will scan the header and source files at build time and invoke moc accordingly. * If an ``#include`` statement like ``#include "moc_<basename>.cpp"`` is found, - the ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in an otherwise empty - line of the ``<basename>.h(xx)`` header file. ``moc`` is run on the header + a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` is expected to appear in the + ``<basename>.h(xx)`` header file. ``moc`` is run on the header file to generate ``moc_<basename>.cpp`` in the ``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. This allows the compiler to find the included ``moc_<basename>.cpp`` file regardless of the location the original source. - * For multi configuration generators, the include directory is - ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. + * For :prop_gbl:`multi configuration generators <GENERATOR_IS_MULTI_CONFIG>`, + the include directory is ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. * If an ``#include`` statement like ``#include "<basename>.moc"`` is found, - then ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in the current source - file and ``moc`` is run on the source file itself. + a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` is expected to appear in the + source file and ``moc`` is run on the source file itself. * Header files that are not included by an ``#include "moc_<basename>.cpp"`` - statement are nonetheless scanned for ``Q_OBJECT`` or ``Q_GADGET`` macros. + statement are nonetheless scanned for a macro out of + :prop_tgt:`AUTOMOC_MACRO_NAMES`. The resulting ``moc_<basename>.cpp`` files are generated in custom directories and automatically included in a generated ``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp`` file, @@ -44,8 +45,9 @@ source files at build time and invoke moc accordingly. * Additionally, header files with the same base name as a source file, (like ``<basename>.h``) or ``_p`` appended to the base name (like - ``<basename>_p.h``), are parsed for ``Q_OBJECT`` or ``Q_GADGET`` macros, - and if found, ``moc`` is also executed on those files. + ``<basename>_p.h``), are scanned for a macro out of + :prop_tgt:`AUTOMOC_MACRO_NAMES`, and if found, ``moc`` + is also executed on those files. * ``AUTOMOC`` always checks multiple header alternative extensions, such as ``hpp``, ``hxx``, etc. when searching for headers. @@ -69,9 +71,7 @@ automoc targets together in an IDE, e.g. in MSVS. The global property :prop_gbl:`AUTOGEN_SOURCE_GROUP` can be used to group files generated by :prop_tgt:`AUTOMOC` together in an IDE, e.g. in MSVS. -The appearance of the strings ``Q_OBJECT`` or ``Q_GADGET`` in a source file -determines if it needs to be ``moc`` processed. To search for additional -strings, list them in :prop_tgt:`AUTOMOC_MACRO_NAMES`. +Additional macro names to search for can be added to :prop_tgt:`AUTOMOC_MACRO_NAMES`. Additional ``moc`` dependency file names can be extracted from source code by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`. diff --git a/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst b/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst index 0639bc8..0535fde 100644 --- a/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst +++ b/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst @@ -1,20 +1,23 @@ AUTOMOC_MACRO_NAMES ------------------- -Additional macro names used by :prop_tgt:`AUTOMOC` -to determine if a C++ file needs to be processed by ``moc``. +A :ref:`;-list <CMake Language Lists>` list of macro names used by +:prop_tgt:`AUTOMOC` to determine if a C++ file needs to be processed by ``moc``. This property is only used if the :prop_tgt:`AUTOMOC` property is ``ON`` for this target. -CMake searches for the strings ``Q_OBJECT`` and ``Q_GADGET`` to -determine if a file needs to be processed by ``moc``. -:prop_tgt:`AUTOMOC_MACRO_NAMES` allows to add additional strings to the -search list. This is useful for cases where the ``Q_OBJECT`` or ``Q_GADGET`` -macro is hidden inside another macro. +When running :prop_tgt:`AUTOMOC`, CMake searches for the strings listed in +:prop_tgt:`AUTOMOC_MACRO_NAMES` in C++ source and header files. +If any of the strings is found + +- as the first non space string on a new line or +- as the first non space string after a ``{`` on a new line, + +then the file will be processed by ``moc``. By default :prop_tgt:`AUTOMOC_MACRO_NAMES` is initialized from -:variable:`CMAKE_AUTOMOC_MACRO_NAMES`, which is empty by default. +:variable:`CMAKE_AUTOMOC_MACRO_NAMES`. See the :manual:`cmake-qt(7)` manual for more information on using CMake with Qt. @@ -25,4 +28,4 @@ In this case the the ``Q_OBJECT`` macro is hidden inside an other macro called ``CUSTOM_MACRO``. To let CMake know that source files, that contain ``CUSTOM_MACRO``, need to be ``moc`` processed, we call:: - set_property(TARGET tgt PROPERTY AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") + set_property(TARGET tgt APPEND PROPERTY AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst index 2fc2167..1791384 100644 --- a/Help/prop_tgt/AUTOUIC.rst +++ b/Help/prop_tgt/AUTOUIC.rst @@ -17,8 +17,8 @@ optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target. ``<AUTOGEN_BUILD_DIR>/include``, which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. -* For multi configuration generators, the include directory is - ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. +* For :prop_gbl:`multi configuration generators <GENERATOR_IS_MULTI_CONFIG>`, + the include directory is ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. diff --git a/Help/release/dev/FindOpenGL-glvnd.rst b/Help/release/dev/FindOpenGL-glvnd.rst new file mode 100644 index 0000000..b3c8d53 --- /dev/null +++ b/Help/release/dev/FindOpenGL-glvnd.rst @@ -0,0 +1,4 @@ +FindOpenGL-glvnd +---------------- + +* The :module:`FindOpenGL` module gained support for GLVND on Linux. diff --git a/Help/release/dev/autogen-macro-names.rst b/Help/release/dev/autogen-macro-names.rst index 736dd3a..6471295 100644 --- a/Help/release/dev/autogen-macro-names.rst +++ b/Help/release/dev/autogen-macro-names.rst @@ -1,12 +1,14 @@ autogen-macro-names ------------------- -* When using :prop_tgt:`AUTOMOC`, CMake searches for the strings ``Q_OBJECT`` - and ``Q_OBJECT`` in a source file to determine if it needs to be ``moc`` - processed. The new variable :variable:`CMAKE_AUTOMOC_MACRO_NAMES` allows to - register additional strings (macro names) so search for. +* When using :prop_tgt:`AUTOMOC`, CMake searches for the strings ``Q_OBJECT``, + ``Q_GADGET`` or ``Q_NAMESPACE`` in a source file to determine if it needs + to be ``moc`` processed. The new variable + :variable:`CMAKE_AUTOMOC_MACRO_NAMES` allows to register additional + strings (macro names) so search for. -* When using :prop_tgt:`AUTOMOC`, CMake searches for the strings ``Q_OBJECT`` - and ``Q_OBJECT`` in a source file to determine if it needs to be ``moc`` - processed. The new target property :prop_tgt:`AUTOMOC_MACRO_NAMES` allows to - register additional strings (macro names) so search for. +* When using :prop_tgt:`AUTOMOC`, CMake searches for the strings ``Q_OBJECT``, + ``Q_GADGET`` or ``Q_NAMESPACE`` in a source file to determine if it needs + to be ``moc`` processed. The new target property + :prop_tgt:`AUTOMOC_MACRO_NAMES` allows to register additional strings + (macro names) so search for. diff --git a/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst b/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst index 7ed3445..5b79c40 100644 --- a/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst +++ b/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst @@ -1,14 +1,15 @@ CMAKE_AUTOMOC_MACRO_NAMES ---------------------------- -Additional macro names used by :variable:`CMAKE_AUTOMOC` -to determine if a C++ file needs to be processed by ``moc``. +A :ref:`;-list <CMake Language Lists>` list of macro names used by +:variable:`CMAKE_AUTOMOC` to determine if a C++ file needs to be +processed by ``moc``. This variable is used to initialize the :prop_tgt:`AUTOMOC_MACRO_NAMES` property on all the targets. See that target property for additional information. -By default it is empty. +The default value is ``Q_OBJECT;Q_GADGET;Q_NAMESPACE``. Example ------- @@ -16,4 +17,4 @@ Let CMake know that source files that contain ``CUSTOM_MACRO`` must be ``moc`` processed as well:: set(CMAKE_AUTOMOC ON) - set(CMAKE_AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") + list(APPEND CMAKE_AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") diff --git a/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst b/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst new file mode 100644 index 0000000..72e8e66 --- /dev/null +++ b/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst @@ -0,0 +1,7 @@ +CMAKE_CUDA_HOST_COMPILER +------------------------ + +Executable to use when compiling host code when compiling ``CUDA`` language +files. Maps to the nvcc -ccbin option. Will only be used by CMake on the first +configuration to determine a valid host compiler for ``CUDA``. After a valid +host compiler has been found, this value is read-only. diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index 484dc93..7f4b398 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -1,3 +1,5 @@ +# Meta +set(AM_MULTI_CONFIG @_multi_config@) # Directories and files set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") @@ -16,7 +18,7 @@ set(AM_QT_RCC_EXECUTABLE @_qt_rcc_executable@) # MOC settings set(AM_MOC_SKIP @_moc_skip@) set(AM_MOC_DEFINITIONS @_moc_compile_defs@) -set(AM_MOC_INCLUDES @_moc_incs@) +set(AM_MOC_INCLUDES @_moc_include_dirs@) set(AM_MOC_OPTIONS @_moc_options@) set(AM_MOC_RELAXED_MODE @_moc_relaxed_mode@) set(AM_MOC_MACRO_NAMES @_moc_macro_names@) diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index 9c38f6e..3951b2c 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -23,6 +23,7 @@ set(CMAKE_DL_LIBS "dl") set(CMAKE_FIND_LIBRARY_PREFIXES "lib") set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a") +set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE") # basically all general purpose OSs support shared libs set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake index af83fb7..59bee41 100644 --- a/Modules/FindOpenGL.cmake +++ b/Modules/FindOpenGL.cmake @@ -7,15 +7,28 @@ # # FindModule for OpenGL and GLU. # +# Optional COMPONENTS +# ^^^^^^^^^^^^^^^^^^^ +# +# This module respects several optional COMPONENTS: ``EGL``, ``GLX``, and +# ``OpenGL``. There are corresponding import targets for each of these flags. +# # IMPORTED Targets # ^^^^^^^^^^^^^^^^ # # This module defines the :prop_tgt:`IMPORTED` targets: # # ``OpenGL::GL`` -# Defined if the system has OpenGL. +# Defined to the platform-specific OpenGL libraries if the system has OpenGL. +# ``OpenGL::OpenGL`` +# Defined to libOpenGL if the system is GLVND-based. +# ``OpenGL::GL`` # ``OpenGL::GLU`` # Defined if the system has GLU. +# ``OpenGL::GLX`` +# Defined if the system has GLX. +# ``OpenGL::EGL`` +# Defined if the system has EGL. # # Result Variables # ^^^^^^^^^^^^^^^^ @@ -23,40 +36,87 @@ # This module sets the following variables: # # ``OPENGL_FOUND`` -# True, if the system has OpenGL. +# True, if the system has OpenGL and all components are found. # ``OPENGL_XMESA_FOUND`` # True, if the system has XMESA. # ``OPENGL_GLU_FOUND`` # True, if the system has GLU. +# ``OpenGL_OpenGL_FOUND`` +# True, if the system has an OpenGL library. +# ``OpenGL_GLX_FOUND`` +# True, if the system has GLX. +# ``OpenGL_EGL_FOUND`` +# True, if the system has EGL. # ``OPENGL_INCLUDE_DIR`` # Path to the OpenGL include directory. +# ``OPENGL_EGL_INCLUDE_DIRS`` +# Path to the EGL include directory. # ``OPENGL_LIBRARIES`` -# Paths to the OpenGL and GLU libraries. +# Paths to the OpenGL library, windowing system libraries, and GLU libraries. +# On Linux, this assumes glX and is never correct for EGL-based targets. +# Clients are encouraged to use the ``OpenGL::*`` import targets instead. # -# If you want to use just GL you can use these values: +# Cache variables +# ^^^^^^^^^^^^^^^ # -# ``OPENGL_gl_LIBRARY`` -# Path to the OpenGL library. +# The following cache variables may also be set: +# +# ``OPENGL_egl_LIBRARY`` +# Path to the EGL library. # ``OPENGL_glu_LIBRARY`` # Path to the GLU library. +# ``OPENGL_glx_LIBRARY`` +# Path to the GLVND 'GLX' library. +# ``OPENGL_opengl_LIBRARY`` +# Path to the GLVND 'OpenGL' library +# ``OPENGL_gl_LIBRARY`` +# Path to the OpenGL library. New code should prefer the ``OpenGL::*`` import +# targets. +# +# Linux-specific +# ^^^^^^^^^^^^^^ # -# OSX Specific -# ^^^^^^^^^^^^ +# Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates +# context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and +# contexts are defined in "libGLX" or "libEGL". GLVND is currently the only way +# to get OpenGL 3+ functionality via EGL in a manner portable across vendors. # -# On OSX default to using the framework version of OpenGL. People will -# have to change the cache values of OPENGL_glu_LIBRARY and +# On Linux systems FindOpenGL defaults to using GLVND if available. Users can +# utilize GLVND explicitly with targets ``OpenGL::OpenGL``, ``OpenGL::GLX``, and +# ``OpenGL::EGL``. Additionally, when GLVND is available the ``OpenGL::GL`` +# target is equivalent to ``OpenGL::OpenGL OpenGL::GLX``. When the system is +# not GLVND-based, ``OpenGL::GL`` expands to libGL as it has historically done. +# Thus, for non-EGL-based Linux targets, the ``OpenGL::GL`` target is most +# portable. +# +# For EGL targets the client must rely on GLVND support on the user's system. +# Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets. Using GLES* +# libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this +# module does not currently support that; contributions welcome. +# +# ``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of +# GLVND. For non-GLVND Linux and other systems these are left undefined. +# +# macOS-Specific +# ^^^^^^^^^^^^^^ +# +# On OSX FindOpenGL defaults to using the framework version of OpenGL. People +# will have to change the cache values of OPENGL_glu_LIBRARY and # OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX. - set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) -if (CYGWIN) +# Provide OPENGL_USE_<C> variables for each component. +foreach(component ${OpenGL_FIND_COMPONENTS}) + string(TOUPPER ${component} _COMPONENT) + set(OPENGL_USE_${_COMPONENT} 1) +endforeach() +if (CYGWIN) find_path(OPENGL_INCLUDE_DIR GL/gl.h ) list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) find_library(OPENGL_gl_LIBRARY opengl32 ) - find_library(OPENGL_glu_LIBRARY glu32 ) elseif (WIN32) @@ -70,7 +130,6 @@ elseif (WIN32) endif() elseif (APPLE) - # The OpenGL.framework provides both gl and glu find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X") find_library(OPENGL_glu_LIBRARY OpenGL DOC @@ -104,15 +163,14 @@ else() # fail since the compiler finds the Mesa headers but NVidia's library. # Make sure the NVIDIA directory comes BEFORE the others. # - Atanas Georgiev <atanas@cs.columbia.edu> - find_path(OPENGL_INCLUDE_DIR GL/gl.h /usr/share/doc/NVIDIA_GLX-1.0/include /usr/openwin/share/include /opt/graphics/OpenGL/include /usr/X11R6/include ${_OPENGL_INCLUDE_PATH} ) - list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) - + find_path(OPENGL_GLX_INCLUDE_DIR GL/glx.h ${_OPENGL_INCLUDE_PATH}) + find_path(OPENGL_EGL_INCLUDE_DIR EGL/egl.h ${_OPENGL_INCLUDE_PATH}) find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h /usr/share/doc/NVIDIA_GLX-1.0/include /usr/openwin/share/include @@ -126,6 +184,90 @@ else() /usr/shlib /usr/X11R6/lib ${_OPENGL_LIB_PATH} ) + # Search for the GLVND libraries. We do this regardless of COMPONENTS; we'll + # take into account the COMPONENTS logic later. + find_library(OPENGL_opengl_LIBRARY + NAMES OpenGL + PATHS /usr/X11R6/lib + ${_OPENGL_LIB_PATH} + ) + + find_library(OPENGL_glx_LIBRARY + NAMES GLX + PATHS /usr/X11R6/lib + ${_OPENGL_LIB_PATH} + ) + + find_library(OPENGL_egl_LIBRARY + NAMES EGL + PATHS ${_OPENGL_LIB_PATH} + ) + + find_library(OPENGL_glu_LIBRARY + NAMES GLU MesaGLU + PATHS ${OPENGL_gl_LIBRARY} + /opt/graphics/OpenGL/lib + /usr/openwin/lib + /usr/shlib /usr/X11R6/lib + ) + + # FPHSA cannot handle "this OR that is required", so we conditionally set what + # it must look for. First clear any previous config we might have done: + set(_OpenGL_REQUIRED_VARS) + + # now we append the libraries as appropriate. The complicated logic + # basically comes down to "use libOpenGL when we can, and add in specific + # context mechanisms when requested, or we need them to preserve the previous + # default where glx is always available." + if((NOT OPENGL_USE_EGL AND + NOT OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY) OR + ( OPENGL_USE_EGL)) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY) + endif() + + # GLVND GLX library. Preferred when available. + if((NOT OPENGL_USE_OPENGL AND + NOT OPENGL_USE_GLX AND + NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + ( OPENGL_USE_GLX AND + NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY) OR + (OPENGL_USE_GLX AND OPENGL_USE_EGL)) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_glx_LIBRARY) + endif() + + # GLVND EGL library. + if(OPENGL_USE_EGL) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_egl_LIBRARY) + endif() + + # Old-style "libGL" library: used as a fallback when GLVND isn't available. + if((NOT OPENGL_USE_EGL AND + NOT OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY AND + OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + OPENGL_gl_LIBRARY)) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) + endif() + + # We always need the 'gl.h' include dir. + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) unset(_OPENGL_INCLUDE_PATH) unset(_OPENGL_LIB_PATH) @@ -137,42 +279,99 @@ else() /usr/openwin/lib /usr/shlib /usr/X11R6/lib ) - endif () -if(OPENGL_gl_LIBRARY) +if(OPENGL_xmesa_INCLUDE_DIR) + set( OPENGL_XMESA_FOUND "YES" ) +else() + set( OPENGL_XMESA_FOUND "NO" ) +endif() - if(OPENGL_xmesa_INCLUDE_DIR) - set( OPENGL_XMESA_FOUND "YES" ) - else() - set( OPENGL_XMESA_FOUND "NO" ) - endif() +if(OPENGL_glu_LIBRARY) + set( OPENGL_GLU_FOUND "YES" ) +else() + set( OPENGL_GLU_FOUND "NO" ) +endif() - set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES}) - if(OPENGL_glu_LIBRARY) - set( OPENGL_GLU_FOUND "YES" ) - if(NOT "${OPENGL_glu_LIBRARY}" STREQUAL "${OPENGL_gl_LIBRARY}") - set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} ) - endif() - else() - set( OPENGL_GLU_FOUND "NO" ) - endif() +# OpenGL_OpenGL_FOUND is a bit unique in that it is okay if /either/ libOpenGL +# or libGL is found. +# Using libGL with libEGL is never okay, though; we handle that case later. +if(NOT OPENGL_opengl_LIBRARY AND NOT OPENGL_gl_LIBRARY) + set(OpenGL_OpenGL_FOUND FALSE) +else() + set(OpenGL_OpenGL_FOUND TRUE) +endif() - # This deprecated setting is for backward compatibility with CMake1.4 - set (OPENGL_LIBRARY ${OPENGL_LIBRARIES}) +if(OPENGL_glx_LIBRARY AND OPENGL_GLX_INCLUDE_DIR) + set(OpenGL_GLX_FOUND TRUE) +else() + set(OpenGL_GLX_FOUND FALSE) +endif() +if(OPENGL_egl_LIBRARY AND OPENGL_EGL_INCLUDE_DIR) + set(OpenGL_EGL_FOUND TRUE) +else() + set(OpenGL_EGL_FOUND FALSE) endif() -# This deprecated setting is for backward compatibility with CMake1.4 -set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR}) +# User-visible names should be plural. +if(OPENGL_EGL_INCLUDE_DIR) + set(OPENGL_EGL_INCLUDE_DIRS ${OPENGL_EGL_INCLUDE_DIR}) +endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS}) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS} + HANDLE_COMPONENTS) unset(_OpenGL_REQUIRED_VARS) # OpenGL:: targets if(OPENGL_FOUND) - if(NOT TARGET OpenGL::GL) + # ::OpenGL is a GLVND library, and thus Linux-only: we don't bother checking + # for a framework version of this library. + if(OPENGL_opengl_LIBRARY AND NOT TARGET OpenGL::OpenGL) + if(IS_ABSOLUTE "${OPENGL_opengl_LIBRARY}") + add_library(OpenGL::OpenGL UNKNOWN IMPORTED) + set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LOCATION + "${OPENGL_opengl_LIBRARY}") + else() + add_library(OpenGL::OpenGL INTERFACE IMPORTED) + set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LIBNAME + "${OPENGL_opengl_LIBRARY}") + endif() + set_target_properties(OpenGL::OpenGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_INCLUDE_DIR}") + endif() + + # ::GLX is a GLVND library, and thus Linux-only: we don't bother checking + # for a framework version of this library. + if(OpenGL_GLX_FOUND AND NOT TARGET OpenGL::GLX) + if(IS_ABSOLUTE "${OPENGL_glx_LIBRARY}") + add_library(OpenGL::GLX UNKNOWN IMPORTED) + set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LOCATION + "${OPENGL_glx_LIBRARY}") + else() + add_library(OpenGL::GLX INTERFACE IMPORTED) + set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LIBNAME + "${OPENGL_glx_LIBRARY}") + endif() + set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_LINK_LIBRARIES + OpenGL::OpenGL) + set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_GLX_INCLUDE_DIR}") + endif() + + if(TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX AND NOT TARGET OpenGL::GL) + # if GLVND with GLX is available, make ::GL a synonym for 'OpenGL::OpenGL + # OpenGL::GLX'. + add_library(OpenGL::GL INTERFACE IMPORTED) + set_target_properties(OpenGL::GL PROPERTIES INTERFACE_LINK_LIBRARIES + OpenGL::OpenGL) + set_property(TARGET OpenGL::GL APPEND PROPERTY INTERFACE_LINK_LIBRARIES + OpenGL::GLX) + set_target_properties(OpenGL::GL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_INCLUDE_DIR}") + + elseif(NOT TARGET OpenGL::GL) if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}") add_library(OpenGL::GL UNKNOWN IMPORTED) if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$") @@ -195,6 +394,28 @@ if(OPENGL_FOUND) INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}") endif() + # ::EGL is a GLVND library, and thus Linux-only: we don't bother checking + # for a framework version of this library. + # Note we test for OpenGL::OpenGL as a target. When this module is updated to + # support GLES, we would additionally want to check for the hypothetical GLES + # target and enable EGL if either ::GLES or ::OpenGL is created. + if(TARGET OpenGL::OpenGL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL) + if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}") + add_library(OpenGL::EGL UNKNOWN IMPORTED) + set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION + "${OPENGL_egl_LIBRARY}") + else() + add_library(OpenGL::EGL INTERFACE IMPORTED) + set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LIBNAME + "${OPENGL_egl_LIBRARY}") + endif() + set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES + OpenGL::OpenGL) + # Note that EGL's include directory is different from OpenGL/GLX's! + set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_EGL_INCLUDE_DIR}") + endif() + if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU) if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}") add_library(OpenGL::GLU UNKNOWN IMPORTED) @@ -217,11 +438,31 @@ if(OPENGL_FOUND) set_target_properties(OpenGL::GLU PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL) endif() + + # OPENGL_LIBRARIES mirrors OpenGL::GL's logic ... + set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY}) + if(TARGET OpenGL::GLX AND TARGET OpenGL::OpenGL) + set(OPENGL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY}) + endif() + # ... and also includes GLU, if available. + if(TARGET OpenGL::GLU) + list(APPEND OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY}) + endif() endif() +# This deprecated setting is for backward compatibility with CMake1.4 +set(OPENGL_LIBRARY ${OPENGL_LIBRARIES}) +# This deprecated setting is for backward compatibility with CMake1.4 +set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR}) + mark_as_advanced( OPENGL_INCLUDE_DIR OPENGL_xmesa_INCLUDE_DIR + OPENGL_egl_LIBRARY OPENGL_glu_LIBRARY + OPENGL_glx_LIBRARY OPENGL_gl_LIBRARY + OPENGL_opengl_LIBRARY + OPENGL_EGL_INCLUDE_DIR + OPENGL_GLX_INCLUDE_DIR ) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index 4e52cb3..b81dd76 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -659,7 +659,6 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa if(NOT EXISTS "${target}") message("warning: target '${target}' does not exist...") - set(${prerequisites_var} "" PARENT_SCOPE) return() endif() diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 9cd7b84..a4dd918 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -587,7 +587,6 @@ set(SRCS cmWriteFileCommand.cxx cmWriteFileCommand.h - cm_auto_ptr.hxx cm_get_date.h cm_get_date.c cm_utf8.h @@ -780,6 +779,8 @@ if(WIN32 AND NOT UNIX) target_link_libraries(CMakeLib rpcrt4 crypt32) endif() +target_compile_definitions(CMakeLib PUBLIC ${CLANG_TIDY_DEFINITIONS}) + # # CTestLib # diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 8d78b2c..b0647f6 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 9) -set(CMake_VERSION_PATCH 20170926) +set(CMake_VERSION_PATCH 20170929) #set(CMake_VERSION_RC 1) diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx index bbf2a50..f47ca7a 100644 --- a/Source/CPack/cmCPackBundleGenerator.cxx +++ b/Source/CPack/cmCPackBundleGenerator.cxx @@ -213,8 +213,7 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir) cmSystemTools::ExpandListArgument(sign_files, relFiles); // sign the files supplied by the user, ie. frameworks. - for (std::vector<std::string>::iterator it = relFiles.begin(); - it != relFiles.end(); ++it) { + for (auto const& file : relFiles) { std::ostringstream temp_sign_file_cmd; temp_sign_file_cmd << this->GetOption("CPACK_COMMAND_CODESIGN"); temp_sign_file_cmd << " " << sign_parameter << " -s \"" @@ -223,11 +222,11 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir) temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID"); temp_sign_file_cmd << " \""; temp_sign_file_cmd << bundle_path; - temp_sign_file_cmd << *it << "\""; + temp_sign_file_cmd << file << "\""; if (!this->RunCommand(temp_sign_file_cmd, &output)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error signing file:" << bundle_path << *it << std::endl + "Error signing file:" << bundle_path << file << std::endl << output << std::endl); return 0; diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 88204c8..45c7fc6 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -136,17 +136,17 @@ int cmCPackDragNDropGenerator::InitializeInternal() "CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl); return 0; } - for (size_t i = 0; i < languages.size(); ++i) { - std::string license = slaDirectory + "/" + languages[i] + ".license.txt"; + for (auto const& language : languages) { + std::string license = slaDirectory + "/" + language + ".license.txt"; if (!singleLicense && !cmSystemTools::FileExists(license)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing license file " - << languages[i] << ".license.txt" << std::endl); + << language << ".license.txt" << std::endl); return 0; } - std::string menu = slaDirectory + "/" + languages[i] + ".menu.txt"; + std::string menu = slaDirectory + "/" + language + ".menu.txt"; if (!cmSystemTools::FileExists(menu)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing menu file " - << languages[i] << ".menu.txt" << std::endl); + << language << ".menu.txt" << std::endl); return 0; } } @@ -185,19 +185,19 @@ int cmCPackDragNDropGenerator::PackageFiles() // loop to create dmg files packageFileNames.clear(); - for (size_t i = 0; i < package_files.size(); i++) { + for (auto const& package_file : package_files) { std::string full_package_name = std::string(toplevel) + std::string("/"); - if (package_files[i] == "ALL_IN_ONE") { + if (package_file == "ALL_IN_ONE") { full_package_name += this->GetOption("CPACK_PACKAGE_FILE_NAME"); } else { - full_package_name += package_files[i]; + full_package_name += package_file; } full_package_name += std::string(GetOutputExtension()); packageFileNames.push_back(full_package_name); std::string src_dir = toplevel; src_dir += "/"; - src_dir += package_files[i]; + src_dir += package_file; if (0 == this->CreateDMG(src_dir, full_package_name)) { return 0; @@ -226,14 +226,14 @@ bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target, cmsys::ofstream fout(target.str().c_str(), std::ios::out | std::ios::binary); if (!fout) { return false; - } else { - // Seek to desired size - 1 byte - fout.seekp(size - 1, std::ios::beg); - char byte = 0; - // Write one byte to ensure file grows - fout.write(&byte, 1); } + // Seek to desired size - 1 byte + fout.seekp(size - 1, std::ios::beg); + char byte = 0; + // Write one byte to ensure file grows + fout.write(&byte, 1); + return true; } @@ -561,7 +561,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, cmCPackLogger(cmCPackLog::LOG_ERROR, languages[i] << " is not a recognized language" << std::endl); } - char* iso_language_cstr = (char*)malloc(65); + char* iso_language_cstr = static_cast<char*>(malloc(65)); CFStringGetCString(iso_language, iso_language_cstr, 64, kCFStringEncodingMacRoman); LangCode lang = 0; @@ -769,7 +769,8 @@ std::string cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix( bool cmCPackDragNDropGenerator::WriteLicense( cmGeneratedFileStream& outputStream, int licenseNumber, - std::string licenseLanguage, std::string licenseFile, std::string* error) + std::string licenseLanguage, const std::string& licenseFile, + std::string* error) { if (!licenseFile.empty() && !singleLicense) { licenseNumber = 5002; @@ -795,8 +796,8 @@ bool cmCPackDragNDropGenerator::WriteLicense( if (!this->BreakLongLine(line, lines, error)) { return false; } - for (size_t i = 0; i < lines.size(); ++i) { - outputStream << " \"" << lines[i] << "\"\n"; + for (auto const& l : lines) { + outputStream << " \"" << l << "\"\n"; } } outputStream << " \"\\n\"\n"; @@ -865,10 +866,11 @@ bool cmCPackDragNDropGenerator::BreakLongLine(const std::string& line, size_t line_length = max_line_length; if (i + line_length > line.size()) { line_length = line.size() - i; - } else + } else { while (line_length > 0 && line[i + line_length - 1] != ' ') { line_length = line_length - 1; } + } if (line_length == 0) { *error = "Please make sure there are no words " diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h index 8565c68..d8c5c83 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.h +++ b/Source/CPack/cmCPackDragNDropGenerator.h @@ -45,8 +45,8 @@ private: bool singleLicense; bool WriteLicense(cmGeneratedFileStream& outputStream, int licenseNumber, - std::string licenseLanguage, std::string licenseFile, - std::string* error); + std::string licenseLanguage, + const std::string& licenseFile, std::string* error); bool BreakLongLine(const std::string& line, std::vector<std::string>& lines, std::string* error); void EscapeQuotesAndBackslashes(std::string& line); diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index f56b5fa..ecb5adb 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -6,6 +6,7 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" #include <algorithm> +#include <memory> // IWYU pragma: keep #include <utility> #include "cmCPackComponentGroup.h" @@ -17,7 +18,6 @@ #include "cmStateSnapshot.h" #include "cmWorkingDirectory.h" #include "cmXMLSafe.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__HAIKU__) @@ -156,7 +156,7 @@ int cmCPackGenerator::PrepareNames() } const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM"); if (algoSignature) { - if (cmCryptoHash::New(algoSignature).get() == nullptr) { + if (!cmCryptoHash::New(algoSignature)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: " << algoSignature << std::endl); return 0; @@ -610,8 +610,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( cm.AddCMakePaths(); cm.SetProgressCallback(cmCPackGeneratorProgress, this); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf( - new cmMakefile(&gg, cm.GetCurrentSnapshot())); + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); if (!installSubDirectory.empty() && installSubDirectory != "/" && installSubDirectory != ".") { tempInstallDirectory += installSubDirectory; @@ -657,11 +656,11 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( if (this->GetOption("CPACK_INSTALL_PREFIX")) { dir += this->GetOption("CPACK_INSTALL_PREFIX"); } - mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); cmCPackLogger( cmCPackLog::LOG_DEBUG, - "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)" + "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf.AddDefinition)" << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" @@ -698,8 +697,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( return 0; } } else { - mf->AddDefinition("CMAKE_INSTALL_PREFIX", - tempInstallDirectory.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", + tempInstallDirectory.c_str()); if (!cmsys::SystemTools::MakeDirectory( tempInstallDirectory.c_str())) { @@ -710,7 +709,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Using non-DESTDIR install... (mf->AddDefinition)" + "- Using non-DESTDIR install... (mf.AddDefinition)" << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" @@ -718,19 +717,19 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } if (!buildConfig.empty()) { - mf->AddDefinition("BUILD_TYPE", buildConfig.c_str()); + mf.AddDefinition("BUILD_TYPE", buildConfig.c_str()); } std::string installComponentLowerCase = cmSystemTools::LowerCase(installComponent); if (installComponentLowerCase != "all") { - mf->AddDefinition("CMAKE_INSTALL_COMPONENT", - installComponent.c_str()); + mf.AddDefinition("CMAKE_INSTALL_COMPONENT", + installComponent.c_str()); } // strip on TRUE, ON, 1, one or several file names, but not on // FALSE, OFF, 0 and an empty string if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES"))) { - mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); + mf.AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); } // Remember the list of files before installation // of the current component (if we are in component install) @@ -750,7 +749,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION // then forward request to cmake_install.cmake script if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION")) { - mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); + mf.AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); } // If current CPack generator does support // ABSOLUTE INSTALL DESTINATION or CPack has been asked for @@ -758,18 +757,17 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // as soon as it occurs (before installing file) if (!SupportsAbsoluteDestination() || this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION")) { - mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", - "1"); + mf.AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); } // do installation - int res = mf->ReadListFile(installFile.c_str()); + int res = mf.ReadListFile(installFile.c_str()); // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES // to CPack (may be used by generators like CPack RPM or DEB) // in order to transparently handle ABSOLUTE PATH - if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { - mf->AddDefinition( + if (mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { + mf.AddDefinition( "CPACK_ABSOLUTE_DESTINATION_FILES", - mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); + mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); } // Now rebuild the list of files after installation @@ -803,12 +801,12 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } } - if (nullptr != mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { + if (nullptr != mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { if (!absoluteDestFiles.empty()) { absoluteDestFiles += ";"; } absoluteDestFiles += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles << std::endl); @@ -822,13 +820,13 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( this->GetOption(absoluteDestFileComponent); absoluteDestFilesListComponent += ";"; absoluteDestFilesListComponent += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); this->SetOption(absoluteDestFileComponent, absoluteDestFilesListComponent.c_str()); } else { this->SetOption( absoluteDestFileComponent, - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); } } } @@ -964,7 +962,7 @@ int cmCPackGenerator::DoPackage() /* Prepare checksum algorithm*/ const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM"); - CM_AUTO_PTR<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : ""); + std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : ""); /* * Copy the generated packages to final destination @@ -997,7 +995,7 @@ int cmCPackGenerator::DoPackage() << packageFileName << " generated." << std::endl); /* Generate checksum file */ - if (crypto.get() != nullptr) { + if (crypto) { std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); hashFile += "/" + filename; hashFile += "." + cmSystemTools::LowerCase(algo); diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx index 321b6a7..4f5b2a0 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -42,9 +42,9 @@ std::string cmCPackPKGGenerator::GetPackageName( out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-" << component.Name << ".pkg"; return out.str(); - } else { - return component.ArchiveFile + ".pkg"; } + + return component.ArchiveFile + ".pkg"; } void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 6624b16..0299279 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -275,8 +275,9 @@ int cmCPackPackageMakerGenerator::PackageFiles() if (this->PackageMakerVersion > 2.0) { pkgCmd << " -v"; } - if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) + if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) { return 0; + } } else { // We have built the package in place. Generate the // distribution.dist file to describe it for the installer. diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx index ed4463c..6a6dc82 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.cxx +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -190,7 +190,7 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directory: " << scriptDir << std::endl); - return 0; + return false; } // if preflight, postflight, or postupgrade are set diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index cc51c60..addb54e 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -5,6 +5,7 @@ #include "cmsys/Encoding.hxx" #include <iostream> #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stddef.h> #include <string> @@ -24,7 +25,6 @@ #include "cmMakefile.h" #include "cmStateSnapshot.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" static const char* cmDocumentationName[][2] = { @@ -192,10 +192,9 @@ int main(int argc, char const* const* argv) cminst.SetHomeOutputDirectory(""); cminst.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator cmgg(&cminst); - CM_AUTO_PTR<cmMakefile> globalMF( - new cmMakefile(&cmgg, cminst.GetCurrentSnapshot())); + cmMakefile globalMF(&cmgg, cminst.GetCurrentSnapshot()); #if defined(__CYGWIN__) - globalMF->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0"); + globalMF.AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0"); #endif bool cpackConfigFileSpecified = true; @@ -225,16 +224,16 @@ int main(int argc, char const* const* argv) // find out which system cpack is running on, so it can setup the search // paths, so FIND_XXX() commands can be used in scripts std::string systemFile = - globalMF->GetModulesFile("CMakeDetermineSystem.cmake"); - if (!globalMF->ReadListFile(systemFile.c_str())) { + globalMF.GetModulesFile("CMakeDetermineSystem.cmake"); + if (!globalMF.ReadListFile(systemFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error reading CMakeDetermineSystem.cmake" << std::endl); return 1; } systemFile = - globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake"); - if (!globalMF->ReadListFile(systemFile.c_str())) { + globalMF.GetModulesFile("CMakeSystemSpecificInformation.cmake"); + if (!globalMF.ReadListFile(systemFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error reading CMakeSystemSpecificInformation.cmake" << std::endl); @@ -242,7 +241,7 @@ int main(int argc, char const* const* argv) } if (!cpackBuildConfig.empty()) { - globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); + globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); } if (cmSystemTools::FileExists(cpackConfigFile.c_str())) { @@ -250,7 +249,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack configuration file: " << cpackConfigFile << std::endl); - if (!globalMF->ReadListFile(cpackConfigFile.c_str())) { + if (!globalMF.ReadListFile(cpackConfigFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Problem reading CPack config file: \"" << cpackConfigFile << "\"" << std::endl); @@ -264,45 +263,44 @@ int main(int argc, char const* const* argv) } if (!generator.empty()) { - globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str()); + globalMF.AddDefinition("CPACK_GENERATOR", generator.c_str()); } if (!cpackProjectName.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str()); } if (!cpackProjectVersion.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_VERSION", - cpackProjectVersion.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_VERSION", + cpackProjectVersion.c_str()); } if (!cpackProjectVendor.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_VENDOR", - cpackProjectVendor.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_VENDOR", + cpackProjectVendor.c_str()); } // if this is not empty it has been set on the command line // go for it. Command line override values set in config file. if (!cpackProjectDirectory.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", + cpackProjectDirectory.c_str()); } // The value has not been set on the command line else { // get a default value (current working directory) cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory(); // use default value iff no value has been provided by the config file - if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY")) { - globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory.c_str()); + if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) { + globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", + cpackProjectDirectory.c_str()); } } for (auto const& cd : definitions.Map) { - globalMF->AddDefinition(cd.first, cd.second.c_str()); + globalMF.AddDefinition(cd.first, cd.second.c_str()); } - const char* cpackModulesPath = - globalMF->GetDefinition("CPACK_MODULE_PATH"); + const char* cpackModulesPath = globalMF.GetDefinition("CPACK_MODULE_PATH"); if (cpackModulesPath) { - globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath); + globalMF.AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath); } - const char* genList = globalMF->GetDefinition("CPACK_GENERATOR"); + const char* genList = globalMF.GetDefinition("CPACK_GENERATOR"); if (!genList) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack generator not specified" << std::endl); @@ -310,8 +308,8 @@ int main(int argc, char const* const* argv) std::vector<std::string> generatorsVector; cmSystemTools::ExpandListArgument(genList, generatorsVector); for (std::string const& gen : generatorsVector) { - cmMakefile::ScopePushPop raii(globalMF.get()); - cmMakefile* mf = globalMF.get(); + cmMakefile::ScopePushPop raii(&globalMF); + cmMakefile* mf = &globalMF; cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Specified generator: " << gen << std::endl); if (parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME")) { diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 1da42d4..f4fc769 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -769,6 +769,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, } std::vector<const char*> argv; + argv.reserve(args.size() + 1); for (std::string const& arg : args) { argv.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 7fe74af..8cb795e 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -214,6 +214,7 @@ bool cmCTestGIT::UpdateByCustom(std::string const& custom) std::vector<std::string> git_custom_command; cmSystemTools::ExpandListArgument(custom, git_custom_command, true); std::vector<char const*> git_custom; + git_custom.reserve(git_custom_command.size() + 1); for (std::string const& i : git_custom_command) { git_custom.push_back(i.c_str()); } diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 453ae99..a1249f5 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -6,6 +6,7 @@ #include "cmsys/Process.h" #include "cmsys/RegularExpression.hxx" #include <iostream> +#include <memory> // IWYU pragma: keep #include <stdlib.h> #include <string.h> @@ -17,7 +18,6 @@ #include "cmStateSnapshot.h" #include "cmSystemTools.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #ifdef _WIN32 @@ -626,12 +626,12 @@ void cmCTestLaunch::LoadConfig() cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); std::string fname = this->LogDir; fname += "CTestLaunchConfig.cmake"; if (cmSystemTools::FileExists(fname.c_str()) && - mf->ReadListFile(fname.c_str())) { - this->SourceDir = mf->GetSafeDefinition("CTEST_SOURCE_DIRECTORY"); + mf.ReadListFile(fname.c_str())) { + this->SourceDir = mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY"); cmSystemTools::ConvertToUnixSlashes(this->SourceDir); } } diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index 11f6a00..fdf8932 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -464,6 +464,7 @@ bool cmCTestP4::UpdateCustom(const std::string& custom) cmSystemTools::ExpandListArgument(custom, p4_custom_command, true); std::vector<char const*> p4_custom; + p4_custom.reserve(p4_custom_command.size() + 1); for (std::string const& i : p4_custom_command) { p4_custom.push_back(i.c_str()); } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 5896014..c7ed927 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -8,6 +8,7 @@ #include <functional> #include <iomanip> #include <iterator> +#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <stdio.h> @@ -28,7 +29,6 @@ #include "cmSystemTools.h" #include "cmWorkingDirectory.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" #include "cm_utf8.h" #include "cmake.h" #include "cmsys/FStream.hxx" @@ -1636,9 +1636,9 @@ void cmCTestTestHandler::GetListOfTests() cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); - mf->AddDefinition("CTEST_CONFIGURATION_TYPE", - this->CTest->GetConfigType().c_str()); + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + mf.AddDefinition("CTEST_CONFIGURATION_TYPE", + this->CTest->GetConfigType().c_str()); // Add handler for ADD_TEST cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand; @@ -1678,7 +1678,7 @@ void cmCTestTestHandler::GetListOfTests() return; } - if (!mf->ReadListFile(testFilename)) { + if (!mf.ReadListFile(testFilename)) { return; } if (cmSystemTools::GetErrorOccuredFlag()) { diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx index 7173439..786ed5e 100644 --- a/Source/CTest/cmCTestUpdateHandler.cxx +++ b/Source/CTest/cmCTestUpdateHandler.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCTestUpdateHandler.h" +#include "cmAlgorithms.h" #include "cmCLocaleEnvironmentScope.h" #include "cmCTest.h" #include "cmCTestBZR.h" @@ -16,7 +17,7 @@ #include "cmVersion.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" +#include <memory> // IWYU pragma: keep #include <sstream> static const char* cmCTestUpdateHandlerUpdateStrings[] = { @@ -134,28 +135,28 @@ int cmCTestUpdateHandler::ProcessHandler() , this->Quiet); // Create an object to interact with the VCS tool. - CM_AUTO_PTR<cmCTestVC> vc; + std::unique_ptr<cmCTestVC> vc; switch (this->UpdateType) { case e_CVS: - vc.reset(new cmCTestCVS(this->CTest, ofs)); + vc = cm::make_unique<cmCTestCVS>(this->CTest, ofs); break; case e_SVN: - vc.reset(new cmCTestSVN(this->CTest, ofs)); + vc = cm::make_unique<cmCTestSVN>(this->CTest, ofs); break; case e_BZR: - vc.reset(new cmCTestBZR(this->CTest, ofs)); + vc = cm::make_unique<cmCTestBZR>(this->CTest, ofs); break; case e_GIT: - vc.reset(new cmCTestGIT(this->CTest, ofs)); + vc = cm::make_unique<cmCTestGIT>(this->CTest, ofs); break; case e_HG: - vc.reset(new cmCTestHG(this->CTest, ofs)); + vc = cm::make_unique<cmCTestHG>(this->CTest, ofs); break; case e_P4: - vc.reset(new cmCTestP4(this->CTest, ofs)); + vc = cm::make_unique<cmCTestP4>(this->CTest, ofs); break; default: - vc.reset(new cmCTestVC(this->CTest, ofs)); + vc = cm::make_unique<cmCTestVC>(this->CTest, ofs); break; } vc->SetCommandLineTool(this->UpdateCommand); diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index 7e09ef0..fd7f37a 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -56,6 +56,7 @@ bool cmCTestVC::InitialCheckout(const char* command) // Construct the initial checkout command line. std::vector<std::string> args = cmSystemTools::ParseArguments(command); std::vector<char const*> vc_co; + vc_co.reserve(args.size() + 1); for (std::string const& arg : args) { vc_co.push_back(arg.c_str()); } diff --git a/Source/Checks/cm_cxx_auto_ptr.cxx b/Source/Checks/cm_cxx_auto_ptr.cxx deleted file mode 100644 index d3100fd..0000000 --- a/Source/Checks/cm_cxx_auto_ptr.cxx +++ /dev/null @@ -1,18 +0,0 @@ -#include <memory> - -std::auto_ptr<int> get_auto_ptr() -{ - std::auto_ptr<int> ptr; - ptr = std::auto_ptr<int>(new int(0)); - return ptr; -} - -int use_auto_ptr(std::auto_ptr<int> ptr) -{ - return *ptr; -} - -int main() -{ - return use_auto_ptr(get_auto_ptr()); -} diff --git a/Source/Checks/cm_cxx_eq_delete.cxx b/Source/Checks/cm_cxx_eq_delete.cxx deleted file mode 100644 index 809e4cf..0000000 --- a/Source/Checks/cm_cxx_eq_delete.cxx +++ /dev/null @@ -1,14 +0,0 @@ -struct Foo -{ - Foo() {} - ~Foo() {} - Foo(Foo const&) = delete; - Foo& operator=(Foo const&) = delete; - int test() const { return 0; } -}; - -int main() -{ - Foo const foo; - return foo.test(); -} diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index 2c39cbe..a30a5e6 100644 --- a/Source/Checks/cm_cxx_features.cmake +++ b/Source/Checks/cm_cxx_features.cmake @@ -41,8 +41,6 @@ function(cm_check_cxx_feature name) endif() endfunction() -cm_check_cxx_feature(auto_ptr) -cm_check_cxx_feature(eq_delete) cm_check_cxx_feature(fallthrough) if(NOT CMake_HAVE_CXX_FALLTHROUGH) cm_check_cxx_feature(gnu_fallthrough) diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index f79e72a..dbd024d 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -17,6 +17,7 @@ #include "cmVersion.h" #include "cmake.h" +#include <algorithm> #include <stdio.h> #include <string.h> @@ -353,11 +354,9 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) char secondLine[512] = ""; char thirdLine[512] = ""; if (process) { - const char* clearLine = - " "; - strcpy(firstLine, clearLine); - strcpy(secondLine, clearLine); - strcpy(thirdLine, clearLine); + memset(firstLine, ' ', 68); + memset(secondLine, ' ', 68); + memset(thirdLine, ' ', 68); } else { if (this->OkToGenerate) { sprintf(firstLine, @@ -380,7 +379,7 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) char fmt[512] = "Press [enter] to edit option Press [d] to delete an entry"; if (process) { - strcpy(fmt, " "); + memset(fmt, ' ', 27); } printw(fmt_s, fmt); curses_move(y - 3, 0); @@ -456,41 +455,27 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) // Join the key, help string and pad with spaces // (or truncate) as necessary char bar[cmCursesMainForm::MAX_WIDTH]; - size_t i, curFieldLen = strlen(curField); + size_t curFieldLen = strlen(curField); size_t helpLen = strlen(help); - size_t width; - if (x < cmCursesMainForm::MAX_WIDTH) { - width = x; - } else { - width = cmCursesMainForm::MAX_WIDTH; - } + size_t width = std::min<size_t>(x, cmCursesMainForm::MAX_WIDTH); if (message) { curField = message; curFieldLen = strlen(message); + strncpy(bar, curField, width); if (curFieldLen < width) { - strcpy(bar, curField); - for (i = curFieldLen; i < width; ++i) { - bar[i] = ' '; - } - } else { - strncpy(bar, curField, width); + memset(bar + curFieldLen, ' ', width - curFieldLen); } } else { - if (curFieldLen >= width) { - strncpy(bar, curField, width); - } else { - strcpy(bar, curField); + strncpy(bar, curField, width); + if (curFieldLen < width) { bar[curFieldLen] = ':'; bar[curFieldLen + 1] = ' '; - if (curFieldLen + helpLen + 2 >= width) { - strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2); - } else { - strcpy(bar + curFieldLen + 2, help); - for (i = curFieldLen + helpLen + 2; i < width; ++i) { - bar[i] = ' '; - } + strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2); + if (curFieldLen + helpLen + 2 < width) { + memset(bar + curFieldLen + helpLen + 2, ' ', + width - curFieldLen + helpLen + 2); } } } @@ -503,9 +488,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) char vertmp[128]; sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion()); size_t sideSpace = (width - strlen(vertmp)); - for (i = 0; i < sideSpace; i++) { - version[i] = ' '; - } + memset(version, ' ', sideSpace); sprintf(version + sideSpace, "%s", vertmp); version[width] = '\0'; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index ba50986..4ea1493 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -15,6 +15,7 @@ #include <ctype.h> #include <iostream> #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -50,7 +51,6 @@ #include "cmVersion.h" #include "cmVersionConfig.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__BEOS__) || defined(__HAIKU__) @@ -421,9 +421,8 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); - if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), - mf.get())) { + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), &mf)) { cmCTestOptionalLog( this, DEBUG, "Cannot find custom configuration file tree" << std::endl, quiet); @@ -970,6 +969,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, } std::vector<const char*> argv; + argv.reserve(args.size() + 1); for (std::string const& a : args) { argv.push_back(a.c_str()); } @@ -1123,9 +1123,9 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, *log << "* Run internal CTest" << std::endl; } - CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv; + std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv; if (modifyEnv) { - saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); + saveEnv = cm::make_unique<cmSystemTools::SaveRestoreEnvironment>(); cmSystemTools::AppendEnv(*environment); } @@ -1150,9 +1150,9 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, output->clear(); } - CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv; + std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv; if (modifyEnv) { - saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); + saveEnv = cm::make_unique<cmSystemTools::SaveRestoreEnvironment>(); cmSystemTools::AppendEnv(*environment); } @@ -2570,6 +2570,7 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args, const char* dir, double timeout, Encoding encoding) { std::vector<const char*> argv; + argv.reserve(args.size() + 1); for (std::string const& a : args) { argv.push_back(a.c_str()); } diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index bd4077f..1189606 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -194,6 +194,7 @@ std::string cmCommonTargetGenerator::GetManifests() this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName); std::vector<std::string> manifests; + manifests.reserve(manifest_srcs.size()); for (cmSourceFile const* manifest_src : manifest_srcs) { manifests.push_back(this->LocalCommonGenerator->ConvertToOutputFormat( this->LocalCommonGenerator->ConvertToRelativePath( diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in index 9d11fff..9a78aca 100644 --- a/Source/cmConfigure.cmake.h.in +++ b/Source/cmConfigure.cmake.h.in @@ -19,22 +19,13 @@ #cmakedefine HAVE_UNSETENV #cmakedefine CMAKE_USE_ELF_PARSER #cmakedefine CMAKE_USE_MACH_PARSER -#cmakedefine CMake_HAVE_CXX_AUTO_PTR -#cmakedefine CMake_HAVE_CXX_EQ_DELETE #cmakedefine CMake_HAVE_CXX_FALLTHROUGH #cmakedefine CMake_HAVE_CXX_GNU_FALLTHROUGH #cmakedefine CMake_HAVE_CXX_ATTRIBUTE_FALLTHROUGH #cmakedefine CMake_HAVE_CXX_MAKE_UNIQUE -#cmakedefine CMake_HAVE_CXX_UNIQUE_PTR #define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@" #define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@" -#ifdef CMake_HAVE_CXX_EQ_DELETE -#define CM_EQ_DELETE = delete -#else -#define CM_EQ_DELETE -#endif - #if defined(CMake_HAVE_CXX_FALLTHROUGH) #define CM_FALLTHROUGH [[fallthrough]] #elif defined(CMake_HAVE_CXX_GNU_FALLTHROUGH) @@ -46,7 +37,7 @@ #endif #define CM_DISABLE_COPY(Class) \ - Class(Class const&) CM_EQ_DELETE; \ - Class& operator=(Class const&) CM_EQ_DELETE; + Class(Class const&) = delete; \ + Class& operator=(Class const&) = delete; #endif diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx index 965f55b..d914eb1 100644 --- a/Source/cmCryptoHash.cxx +++ b/Source/cmCryptoHash.cxx @@ -2,11 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCryptoHash.h" +#include "cmAlgorithms.h" #include "cm_kwiml.h" #include "cm_rhash.h" #include "cmsys/FStream.hxx" #include <string.h> +#include <memory> // IWYU pragma: keep + static unsigned int const cmCryptoHashAlgoToId[] = { /* clang-format needs this comment to break after the opening brace */ RHASH_MD5, // @@ -43,39 +46,39 @@ cmCryptoHash::~cmCryptoHash() rhash_free(this->CTX); } -CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo) +std::unique_ptr<cmCryptoHash> cmCryptoHash::New(const char* algo) { if (strcmp(algo, "MD5") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoMD5)); + return cm::make_unique<cmCryptoHash>(AlgoMD5); } if (strcmp(algo, "SHA1") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA1)); + return cm::make_unique<cmCryptoHash>(AlgoSHA1); } if (strcmp(algo, "SHA224") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA224)); + return cm::make_unique<cmCryptoHash>(AlgoSHA224); } if (strcmp(algo, "SHA256") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA256)); + return cm::make_unique<cmCryptoHash>(AlgoSHA256); } if (strcmp(algo, "SHA384") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA384)); + return cm::make_unique<cmCryptoHash>(AlgoSHA384); } if (strcmp(algo, "SHA512") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA512)); + return cm::make_unique<cmCryptoHash>(AlgoSHA512); } if (strcmp(algo, "SHA3_224") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_224)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_224); } if (strcmp(algo, "SHA3_256") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_256)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_256); } if (strcmp(algo, "SHA3_384") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_384)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_384); } if (strcmp(algo, "SHA3_512") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_512)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_512); } - return CM_AUTO_PTR<cmCryptoHash>(nullptr); + return std::unique_ptr<cmCryptoHash>(nullptr); } bool cmCryptoHash::IntFromHexDigit(char input, char& output) diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h index 9c13968..1f2a1b5 100644 --- a/Source/cmCryptoHash.h +++ b/Source/cmCryptoHash.h @@ -5,12 +5,11 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <memory> // IWYU pragma: keep #include <stddef.h> #include <string> #include <vector> -#include "cm_auto_ptr.hxx" - /** * @brief Abstract base class for cryptographic hash generators */ @@ -42,7 +41,7 @@ public: /// SHA3_224, SHA3_256, SHA3_384, SHA3_512 /// @return A valid auto pointer if algo is supported or /// an invalid/NULL pointer otherwise - static CM_AUTO_PTR<cmCryptoHash> New(const char* algo); + static std::unique_ptr<cmCryptoHash> New(const char* algo); /// @brief Converts a hex character to its binary value (4 bits) /// @arg input Hex character [0-9a-fA-F]. diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index ff62a60..3d816d5 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -11,8 +11,8 @@ #include "cmOutputConverter.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" +#include <memory> // IWYU pragma: keep #include <stddef.h> cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, @@ -29,7 +29,8 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, for (cmCustomCommandLine const& cmdline : cmdlines) { cmCustomCommandLine argv; for (std::string const& clarg : cmdline) { - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = this->GE->Parse(clarg); + std::unique_ptr<cmCompiledGeneratorExpression> cge = + this->GE->Parse(clarg); std::string parsed_arg = cge->Evaluate(this->LG, this->Config); if (this->CC.GetCommandExpandLists()) { std::vector<std::string> ExpandedArg; @@ -44,7 +45,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, std::vector<std::string> depends = this->CC.GetDepends(); for (std::string const& d : depends) { - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = this->GE->Parse(d); + std::unique_ptr<cmCompiledGeneratorExpression> cge = this->GE->Parse(d); std::vector<std::string> result; cmSystemTools::ExpandListArgument(cge->Evaluate(this->LG, this->Config), result); diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 2d6d8f9..76374b2 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -2,10 +2,10 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmELF.h" -#include "cm_auto_ptr.hxx" #include "cm_kwiml.h" #include "cmsys/FStream.hxx" #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stddef.h> #include <utility> @@ -108,7 +108,7 @@ public: }; // Construct and take ownership of the file stream object. - cmELFInternal(cmELF* external, CM_AUTO_PTR<cmsys::ifstream>& fin, + cmELFInternal(cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, ByteOrderType order) : External(external) , Stream(*fin.release()) @@ -231,7 +231,7 @@ public: typedef typename Types::tagtype tagtype; // Construct with a stream and byte swap indicator. - cmELFInternalImpl(cmELF* external, CM_AUTO_PTR<cmsys::ifstream>& fin, + cmELFInternalImpl(cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, ByteOrderType order); // Return the number of sections as specified by the ELF header. @@ -424,9 +424,8 @@ private: }; template <class Types> -cmELFInternalImpl<Types>::cmELFInternalImpl(cmELF* external, - CM_AUTO_PTR<cmsys::ifstream>& fin, - ByteOrderType order) +cmELFInternalImpl<Types>::cmELFInternalImpl( + cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, ByteOrderType order) : cmELFInternal(external, fin, order) { // Read the main header. @@ -682,7 +681,7 @@ cmELF::cmELF(const char* fname) : Internal(nullptr) { // Try to open the file. - CM_AUTO_PTR<cmsys::ifstream> fin(new cmsys::ifstream(fname)); + std::unique_ptr<cmsys::ifstream> fin(new cmsys::ifstream(fname)); // Quit now if the file could not be opened. if (!fin.get() || !*fin) { diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index b5b7214..5e2cd53 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -3,6 +3,7 @@ #include "cmExportBuildAndroidMKGenerator.h" #include <algorithm> +#include <memory> // IWYU pragma: keep #include <sstream> #include <utility> @@ -15,7 +16,6 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator() @@ -126,7 +126,7 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( // evaluate any generator expressions with the current // build type of the makefile cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(lib); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(lib); std::string evaluated = cge->Evaluate(target->GetLocalGenerator(), config); bool relpath = false; diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index e729632..7f0cb97 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -17,9 +17,9 @@ #include "cmTargetExport.h" #include "cmake.h" -#include "cm_auto_ptr.hxx" #include "cmsys/FStream.hxx" #include <assert.h> +#include <memory> // IWYU pragma: keep #include <sstream> #include <string.h> #include <utility> @@ -65,18 +65,17 @@ const char* cmExportFileGenerator::GetMainExportFileName() const bool cmExportFileGenerator::GenerateImportFile() { // Open the output file to generate it. - CM_AUTO_PTR<cmsys::ofstream> foutPtr; + std::unique_ptr<cmsys::ofstream> foutPtr; if (this->AppendMode) { // Open for append. - CM_AUTO_PTR<cmsys::ofstream> ap( - new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app)); - foutPtr = ap; + foutPtr = cm::make_unique<cmsys::ofstream>(this->MainImportFile.c_str(), + std::ios::app); } else { // Generate atomically and with copy-if-different. - CM_AUTO_PTR<cmGeneratedFileStream> ap( + std::unique_ptr<cmGeneratedFileStream> ap( new cmGeneratedFileStream(this->MainImportFile.c_str(), true)); ap->SetCopyIfDifferent(true); - foutPtr = ap; + foutPtr = std::move(ap); } if (!foutPtr.get() || !*foutPtr) { std::string se = cmSystemTools::GetLastSystemError(); @@ -372,7 +371,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( std::string dirs = cmGeneratorExpression::Preprocess( tei->InterfaceIncludeDirectories, preprocessRule, true); this->ReplaceInstallPrefix(dirs); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(dirs); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs); std::string exportDirs = cge->Evaluate(target->GetLocalGenerator(), "", false, target); diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx index cf12d33..50f8cb0 100644 --- a/Source/cmExportLibraryDependenciesCommand.cxx +++ b/Source/cmExportLibraryDependenciesCommand.cxx @@ -4,8 +4,10 @@ #include "cmsys/FStream.hxx" #include <map> +#include <memory> // IWYU pragma: keep #include <utility> +#include "cmAlgorithms.h" #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -13,7 +15,6 @@ #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTargetLinkLibraryType.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" class cmExecutionStatus; @@ -47,16 +48,15 @@ void cmExportLibraryDependenciesCommand::FinalPass() void cmExportLibraryDependenciesCommand::ConstFinalPass() const { // Use copy-if-different if not appending. - CM_AUTO_PTR<cmsys::ofstream> foutPtr; + std::unique_ptr<cmsys::ofstream> foutPtr; if (this->Append) { - CM_AUTO_PTR<cmsys::ofstream> ap( - new cmsys::ofstream(this->Filename.c_str(), std::ios::app)); - foutPtr = ap; + foutPtr = + cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), std::ios::app); } else { - CM_AUTO_PTR<cmGeneratedFileStream> ap( + std::unique_ptr<cmGeneratedFileStream> ap( new cmGeneratedFileStream(this->Filename.c_str(), true)); ap->SetCopyIfDifferent(true); - foutPtr = ap; + foutPtr = std::move(ap); } std::ostream& fout = *foutPtr; diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index 3e3fea1..1fb9cf8 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -11,9 +11,9 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include <map> +#include <memory> // IWYU pragma: keep #include <utility> cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator( @@ -65,7 +65,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets( cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName, nullptr, nullptr); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop); cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE, cmTarget::VisibilityNormal, tgt->Target->GetMakefile()); diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 98c5733..fdd5f0c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -10,6 +10,7 @@ #include "cmsys/String.hxx" #include <algorithm> #include <assert.h> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -30,7 +31,6 @@ #include "cmPolicies.h" #include "cmSystemTools.h" #include "cmTimestamp.h" -#include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" #include "cmake.h" @@ -368,8 +368,8 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args) return false; } - CM_AUTO_PTR<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); - if (hash.get()) { + std::unique_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); + if (hash) { std::string out = hash->HashFile(args[1]); if (!out.empty()) { this->Makefile->AddDefinition(args[2], out.c_str()); @@ -2294,10 +2294,9 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args) if (errorArg.GetString().empty()) { this->SetError(error); return false; - } else { - this->Makefile->AddDefinition(errorArg.GetString(), error.c_str()); - return true; } + this->Makefile->AddDefinition(errorArg.GetString(), error.c_str()); + return true; #endif } @@ -2629,7 +2628,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO"); std::string expectedHash; std::string hashMatchMSG; - CM_AUTO_PTR<cmCryptoHash> hash; + std::unique_ptr<cmCryptoHash> hash; bool showProgress = false; std::string userpwd; @@ -2688,8 +2687,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5."); return false; } - hash = - CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(cmCryptoHash::AlgoMD5)); + hash = cm::make_unique<cmCryptoHash>(cmCryptoHash::AlgoMD5); hashMatchMSG = "MD5 sum"; expectedHash = cmSystemTools::LowerCase(*i); } else if (*i == "SHOW_PROGRESS") { @@ -2710,7 +2708,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) } std::string algo = i->substr(0, pos); expectedHash = cmSystemTools::LowerCase(i->substr(pos + 1)); - hash = CM_AUTO_PTR<cmCryptoHash>(cmCryptoHash::New(algo.c_str())); + hash = std::unique_ptr<cmCryptoHash>(cmCryptoHash::New(algo.c_str())); if (!hash.get()) { std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: "; err += algo; @@ -2906,7 +2904,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) // Verify MD5 sum if requested: // - if (hash.get()) { + if (hash) { std::string actualHash = hash->HashFile(file); if (actualHash.empty()) { this->SetError("DOWNLOAD cannot compute hash on downloaded file"); @@ -3195,15 +3193,15 @@ void cmFileCommand::AddEvaluationFile(const std::string& inputName, cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression outputGe(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> outputCge = + std::unique_ptr<cmCompiledGeneratorExpression> outputCge = outputGe.Parse(outputExpr); cmGeneratorExpression conditionGe(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> conditionCge = + std::unique_ptr<cmCompiledGeneratorExpression> conditionCge = conditionGe.Parse(condition); - this->Makefile->AddEvaluationFile(inputName, outputCge, conditionCge, - inputIsContent); + this->Makefile->AddEvaluationFile(inputName, std::move(outputCge), + std::move(conditionCge), inputIsContent); } bool cmFileCommand::HandleGenerateCommand(std::vector<std::string> const& args) diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx index 61e419c..622c15e 100644 --- a/Source/cmFileTimeComparison.cxx +++ b/Source/cmFileTimeComparison.cxx @@ -116,18 +116,22 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1, // Compare using nanosecond resolution. if (s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec) { return -1; - } else if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) { + } + if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) { return 1; - } else if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) { + } + if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) { return -1; - } else if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) { + } + if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) { return 1; } #else // Compare using 1 second resolution. if (s1->st_mtime < s2->st_mtime) { return -1; - } else if (s1->st_mtime > s2->st_mtime) { + } + if (s1->st_mtime > s2->st_mtime) { return 1; } #endif @@ -162,20 +166,20 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1, long long t2 = s2->st_mtimespec.tv_sec * bil + s2->st_mtimespec.tv_nsec; if (t1 < t2) { return (t2 - t1) >= bil; - } else if (t2 < t1) { + } + if (t2 < t1) { return (t1 - t2) >= bil; - } else { - return false; } + return false; #else // Times are integers in units of 1s. if (s1->st_mtime < s2->st_mtime) { return (s2->st_mtime - s1->st_mtime) >= 1; - } else if (s1->st_mtime > s2->st_mtime) { + } + if (s1->st_mtime > s2->st_mtime) { return (s1->st_mtime - s2->st_mtime) >= 1; - } else { - return false; } + return false; #endif #else // Times are integers in units of 100ns. diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index b8b51ba..758da2c 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -260,7 +260,7 @@ void cmFindLibraryHelper::RegexFromLiteral(std::string& out, out += "\\"; } #if defined(_WIN32) || defined(__APPLE__) - out += tolower(ch); + out += static_cast<char>(tolower(ch)); #else out += ch; #endif diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index cd55e89..5a72655 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -13,6 +13,7 @@ #include <deque> #include <functional> #include <iterator> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <string.h> @@ -24,7 +25,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmVersion.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__HAIKU__) @@ -1611,10 +1611,10 @@ protected: private: bool Search(cmFileList&); virtual bool Search(std::string const& parent, cmFileList&) = 0; - virtual CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const = 0; + virtual std::unique_ptr<cmFileListGeneratorBase> Clone() const = 0; friend class cmFileList; cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next); - CM_AUTO_PTR<cmFileListGeneratorBase> Next; + std::unique_ptr<cmFileListGeneratorBase> Next; }; class cmFileList @@ -1638,7 +1638,7 @@ public: } bool Search() { - if (this->First.get()) { + if (this->First) { return this->First->Search(*this); } return false; @@ -1647,7 +1647,7 @@ public: private: virtual bool Visit(std::string const& fullPath) = 0; friend class cmFileListGeneratorBase; - CM_AUTO_PTR<cmFileListGeneratorBase> First; + std::unique_ptr<cmFileListGeneratorBase> First; cmFileListGeneratorBase* Last; }; @@ -1688,7 +1688,7 @@ cmFileListGeneratorBase* cmFileListGeneratorBase::SetNext( bool cmFileListGeneratorBase::Consider(std::string const& fullPath, cmFileList& listing) { - if (this->Next.get()) { + if (this->Next) { return this->Next->Search(fullPath + "/", listing); } return listing.Visit(fullPath + "/"); @@ -1715,9 +1715,9 @@ private: std::string fullPath = parent + this->String; return this->Consider(fullPath, lister); } - CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const override + std::unique_ptr<cmFileListGeneratorBase> Clone() const override { - CM_AUTO_PTR<cmFileListGeneratorBase> g( + std::unique_ptr<cmFileListGeneratorBase> g( new cmFileListGeneratorFixed(*this)); return g; } @@ -1748,9 +1748,9 @@ private: } return false; } - CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const override + std::unique_ptr<cmFileListGeneratorBase> Clone() const override { - CM_AUTO_PTR<cmFileListGeneratorBase> g( + std::unique_ptr<cmFileListGeneratorBase> g( new cmFileListGeneratorEnumerate(*this)); return g; } @@ -1820,9 +1820,9 @@ private: } return false; } - CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const override + std::unique_ptr<cmFileListGeneratorBase> Clone() const override { - CM_AUTO_PTR<cmFileListGeneratorBase> g( + std::unique_ptr<cmFileListGeneratorBase> g( new cmFileListGeneratorProject(*this)); return g; } @@ -1874,9 +1874,9 @@ private: } return false; } - CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const override + std::unique_ptr<cmFileListGeneratorBase> Clone() const override { - CM_AUTO_PTR<cmFileListGeneratorBase> g( + std::unique_ptr<cmFileListGeneratorBase> g( new cmFileListGeneratorMacProject(*this)); return g; } @@ -1918,9 +1918,9 @@ private: } return false; } - CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const override + std::unique_ptr<cmFileListGeneratorBase> Clone() const override { - CM_AUTO_PTR<cmFileListGeneratorBase> g( + std::unique_ptr<cmFileListGeneratorBase> g( new cmFileListGeneratorCaseInsensitive(*this)); return g; } @@ -1963,10 +1963,9 @@ private: } return false; } - CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const override + std::unique_ptr<cmFileListGeneratorBase> Clone() const override { - CM_AUTO_PTR<cmFileListGeneratorBase> g(new cmFileListGeneratorGlob(*this)); - return g; + return cm::make_unique<cmFileListGeneratorGlob>(*this); } }; diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx index 37387b0..542a860 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmForEachCommand.h" +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -9,7 +10,6 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmForEachFunctionBlocker::cmForEachFunctionBlocker(cmMakefile* mf) @@ -35,7 +35,8 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // if this is the endofreach for this statement if (!this->Depth) { // Remove the function blocker for this scope or bail. - CM_AUTO_PTR<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(this, lff)); + std::unique_ptr<cmFunctionBlocker> fb( + mf.RemoveFunctionBlocker(this, lff)); if (!fb.get()) { return false; } @@ -181,7 +182,7 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& args, bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) { - CM_AUTO_PTR<cmForEachFunctionBlocker> f( + std::unique_ptr<cmForEachFunctionBlocker> f( new cmForEachFunctionBlocker(this->Makefile)); f->Args.push_back(args[0]); @@ -213,7 +214,7 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) } } - this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass auto_ptr + this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass unique_ptr return true; } diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index d4b501f..86991c1 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -3,6 +3,7 @@ #include "cmGeneratorExpression.h" #include "cmsys/RegularExpression.hxx" +#include <memory> // IWYU pragma: keep #include <utility> #include "assert.h" @@ -12,7 +13,6 @@ #include "cmGeneratorExpressionLexer.h" #include "cmGeneratorExpressionParser.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" cmGeneratorExpression::cmGeneratorExpression( const cmListFileBacktrace& backtrace) @@ -20,14 +20,14 @@ cmGeneratorExpression::cmGeneratorExpression( { } -CM_AUTO_PTR<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse( +std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse( std::string const& input) { - return CM_AUTO_PTR<cmCompiledGeneratorExpression>( + return std::unique_ptr<cmCompiledGeneratorExpression>( new cmCompiledGeneratorExpression(this->Backtrace, input)); } -CM_AUTO_PTR<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse( +std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse( const char* input) { return this->Parse(std::string(input ? input : "")); diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index d22a191..cface0d 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -7,8 +7,8 @@ #include "cmListFileCache.h" -#include "cm_auto_ptr.hxx" #include <map> +#include <memory> // IWYU pragma: keep #include <set> #include <string> #include <vector> @@ -39,8 +39,9 @@ public: cmListFileBacktrace const& backtrace = cmListFileBacktrace()); ~cmGeneratorExpression(); - CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(std::string const& input); - CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(const char* input); + std::unique_ptr<cmCompiledGeneratorExpression> Parse( + std::string const& input); + std::unique_ptr<cmCompiledGeneratorExpression> Parse(const char* input); enum PreprocessContext { diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index ace9609..87b6b34 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -3,6 +3,7 @@ #include "cmGeneratorExpressionEvaluationFile.h" #include "cmsys/FStream.hxx" +#include <memory> // IWYU pragma: keep #include <sstream> #include <utility> @@ -13,17 +14,16 @@ #include "cmMakefile.h" #include "cmSourceFile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile( const std::string& input, - CM_AUTO_PTR<cmCompiledGeneratorExpression> outputFileExpr, - CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent, - cmPolicies::PolicyStatus policyStatusCMP0070) + std::unique_ptr<cmCompiledGeneratorExpression> outputFileExpr, + std::unique_ptr<cmCompiledGeneratorExpression> condition, + bool inputIsContent, cmPolicies::PolicyStatus policyStatusCMP0070) : Input(input) - , OutputFileExpr(outputFileExpr) - , Condition(condition) + , OutputFileExpr(std::move(outputFileExpr)) + , Condition(std::move(condition)) , InputIsContent(inputIsContent) , PolicyStatusCMP0070(policyStatusCMP0070) { @@ -144,7 +144,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace(); cmGeneratorExpression contentGE(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> inputExpression = + std::unique_ptr<cmCompiledGeneratorExpression> inputExpression = contentGE.Parse(inputContent); std::map<std::string, std::string> outputFiles; diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h index ecf919d..2a79069 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -6,12 +6,12 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <map> +#include <memory> // IWYU pragma: keep #include <string> #include <vector> #include "cmGeneratorExpression.h" #include "cmPolicies.h" -#include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" class cmLocalGenerator; @@ -21,9 +21,9 @@ class cmGeneratorExpressionEvaluationFile public: cmGeneratorExpressionEvaluationFile( const std::string& input, - CM_AUTO_PTR<cmCompiledGeneratorExpression> outputFileExpr, - CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent, - cmPolicies::PolicyStatus policyStatusCMP0070); + std::unique_ptr<cmCompiledGeneratorExpression> outputFileExpr, + std::unique_ptr<cmCompiledGeneratorExpression> condition, + bool inputIsContent, cmPolicies::PolicyStatus policyStatusCMP0070); void Generate(cmLocalGenerator* lg); @@ -47,8 +47,8 @@ private: private: const std::string Input; - const CM_AUTO_PTR<cmCompiledGeneratorExpression> OutputFileExpr; - const CM_AUTO_PTR<cmCompiledGeneratorExpression> Condition; + const std::unique_ptr<cmCompiledGeneratorExpression> OutputFileExpr; + const std::unique_ptr<cmCompiledGeneratorExpression> Condition; std::vector<std::string> Files; const bool InputIsContent; cmPolicies::PolicyStatus PolicyStatusCMP0070; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 8f32410..fea20ba 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -17,7 +17,6 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #include "cmsys/RegularExpression.hxx" @@ -26,6 +25,7 @@ #include <assert.h> #include <errno.h> #include <map> +#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <stdlib.h> @@ -39,7 +39,7 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression( cmGeneratorExpressionDAGChecker* dagChecker) { cmGeneratorExpression ge(context->Backtrace); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop); cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem); std::string result = cge->Evaluate(lg, context->Config, context->Quiet, headTarget, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 28b43e7..ea41204e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -7,6 +7,7 @@ #include <assert.h> #include <errno.h> #include <iterator> +#include <memory> // IWYU pragma: keep #include <queue> #include <sstream> #include <stdio.h> @@ -32,7 +33,6 @@ #include "cmTarget.h" #include "cmTargetLinkLibraryType.h" #include "cmTargetPropertyComputer.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" class cmMessenger; @@ -64,13 +64,13 @@ class cmGeneratorTarget::TargetPropertyEntry static cmLinkImplItem NoLinkImplItem; public: - TargetPropertyEntry(CM_AUTO_PTR<cmCompiledGeneratorExpression> cge, + TargetPropertyEntry(std::unique_ptr<cmCompiledGeneratorExpression> cge, cmLinkImplItem const& item = NoLinkImplItem) - : ge(cge) + : ge(std::move(cge)) , LinkImplItem(item) { } - const CM_AUTO_PTR<cmCompiledGeneratorExpression> ge; + const std::unique_ptr<cmCompiledGeneratorExpression> ge; cmLinkImplItem const& LinkImplItem; }; cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem; @@ -84,9 +84,10 @@ void CreatePropertyGeneratorExpressions( for (std::vector<std::string>::const_iterator it = entries.begin(); it != entries.end(); ++it, ++btIt) { cmGeneratorExpression ge(*btIt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*it); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it); cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); - items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge)); + items.push_back( + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge))); } } @@ -309,7 +310,7 @@ std::string cmGeneratorTarget::GetOutputName( // Now evaluate genex and update the previously-prepared map entry. cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outName); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName); i->second = cge->Evaluate(this->LocalGenerator, config); } else if (i->second.empty()) { // An empty map entry indicates we have been called recursively @@ -333,9 +334,9 @@ void cmGeneratorTarget::AddSourceCommon(const std::string& src) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression ge(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); - this->SourceEntries.push_back(new TargetPropertyEntry(cge)); + this->SourceEntries.push_back(new TargetPropertyEntry(std::move(cge))); this->ClearSourcesCache(); } @@ -359,13 +360,14 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before); cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression ge(lfbt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); // Insert before begin/end std::vector<TargetPropertyEntry*>::iterator pos = before ? this->IncludeDirectoriesEntries.begin() : this->IncludeDirectoriesEntries.end(); - this->IncludeDirectoriesEntries.insert(pos, new TargetPropertyEntry(cge)); + this->IncludeDirectoriesEntries.insert( + pos, new TargetPropertyEntry(std::move(cge))); } std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends( @@ -795,10 +797,10 @@ static void AddInterfaceEntries( if (lib.Target) { std::string genex = "$<TARGET_PROPERTY:" + lib + "," + prop + ">"; cmGeneratorExpression ge(lib.Backtrace); - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(genex); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); entries.push_back( - new cmGeneratorTarget::TargetPropertyEntry(cge, lib)); + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge), lib)); } } } @@ -2285,7 +2287,7 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) // Check for target references in generator expressions. for (std::string const& cl : cCmdLine) { - const CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cl); + const std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cl); cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true); std::set<cmGeneratorTarget*> geTargets = cge->GetTargets(); targets.insert(geTargets.begin(), geTargets.end()); @@ -2570,10 +2572,10 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories( libDir = frameworkCheck.match(1); cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(libDir.c_str()); linkInterfaceIncludeDirectoriesEntries.push_back( - new cmGeneratorTarget::TargetPropertyEntry(cge)); + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge))); } } @@ -2781,10 +2783,10 @@ void cmGeneratorTarget::GetCompileDefinitions( } case cmPolicies::OLD: { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(configProp); linkInterfaceCompileDefinitionsEntries.push_back( - new cmGeneratorTarget::TargetPropertyEntry(cge)); + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge))); } break; case cmPolicies::NEW: case cmPolicies::REQUIRED_ALWAYS: @@ -4214,7 +4216,7 @@ void cmGeneratorTarget::ExpandLinkItems( dagChecker.SetTransitivePropertiesOnly(); } std::vector<std::string> libs; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(value); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value); cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config, false, headTarget, this, &dagChecker), @@ -4484,7 +4486,8 @@ bool cmGeneratorTarget::ComputeOutputDir(const std::string& config, if (const char* config_outdir = this->GetProperty(configProp)) { // Use the user-specified per-configuration output directory. cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(config_outdir); + std::unique_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(config_outdir); out = cge->Evaluate(this->LocalGenerator, config); // Skip per-configuration subdirectory. @@ -4492,7 +4495,7 @@ bool cmGeneratorTarget::ComputeOutputDir(const std::string& config, } else if (const char* outdir = this->GetProperty(propertyName)) { // Use the user-specified output directory. cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outdir); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir); out = cge->Evaluate(this->LocalGenerator, config); // Skip per-configuration subdirectory if the value contained a @@ -5222,7 +5225,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( cmGeneratorExpressionDAGChecker dagChecker( this->GetName(), "LINK_LIBRARIES", nullptr, nullptr); cmGeneratorExpression ge(*btIt); - CM_AUTO_PTR<cmCompiledGeneratorExpression> const cge = ge.Parse(*le); + std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le); std::string const evaluated = cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker); cmSystemTools::ExpandListArgument(evaluated, llibs); diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 4f799ba..a31e415 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -363,7 +363,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries( this->GeneratorTarget->GetCreateRuleVariable(language, config); bool useWatcomQuote = this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE"); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->GetGlobalGenerator()->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 3e9e995..d5531cb 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -10,6 +10,7 @@ #include <ctype.h> #include <functional> #include <iterator> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> @@ -32,7 +33,6 @@ #include "cmTarget.h" #include "cmTargetDepend.h" #include "cmVersion.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" class cmLinkLineComputer; @@ -1692,9 +1692,10 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( snapshot.GetDirectory().SetCurrentBinary(dir_cur_bld); snapshot.GetDirectory().SetRelativePathTopSource(dir_top_src.c_str()); snapshot.GetDirectory().SetRelativePathTopBinary(dir_top_bld.c_str()); - CM_AUTO_PTR<cmMakefile> mfd(new cmMakefile(this, snapshot)); - CM_AUTO_PTR<cmLocalNinjaGenerator> lgd(static_cast<cmLocalNinjaGenerator*>( - this->CreateLocalGenerator(mfd.get()))); + auto mfd = cm::make_unique<cmMakefile>(this, snapshot); + std::unique_ptr<cmLocalNinjaGenerator> lgd( + static_cast<cmLocalNinjaGenerator*>( + this->CreateLocalGenerator(mfd.get()))); this->Makefiles.push_back(mfd.release()); this->LocalGenerators.push_back(lgd.release()); } @@ -1869,7 +1870,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, cmake cm(cmake::RoleInternal); cm.SetHomeDirectory(dir_top_src); cm.SetHomeOutputDirectory(dir_top_bld); - CM_AUTO_PTR<cmGlobalNinjaGenerator> ggd( + std::unique_ptr<cmGlobalNinjaGenerator> ggd( static_cast<cmGlobalNinjaGenerator*>(cm.CreateGlobalGenerator("Ninja"))); if (!ggd.get() || !ggd->WriteDyndepFile(dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 8c1111e..a14b5f7 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -708,7 +708,7 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( const char* propertyValue = target->Target->GetMakefile()->GetDefinition(propertyName); cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(propertyValue); if (cmSystemTools::IsOn( cge->Evaluate(target->GetLocalGenerator(), *i))) { diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2a05d4e..304a188 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -5,10 +5,12 @@ #include "cmsys/RegularExpression.hxx" #include <assert.h> #include <iomanip> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <string.h> +#include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" #include "cmDocumentationEntry.h" @@ -29,7 +31,6 @@ #include "cmXCode21Object.h" #include "cmXCodeObject.h" #include "cmXCodeScheme.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" struct cmLinkImplementation; @@ -46,8 +47,11 @@ public: : Version("1.5") { } - void StartElement(const std::string&, const char**) { this->Data = ""; } - void EndElement(const std::string& name) + void StartElement(const std::string&, const char**) override + { + this->Data = ""; + } + void EndElement(const std::string& name) override { if (name == "key") { this->Key = this->Data; @@ -57,7 +61,7 @@ public: } } } - void CharacterDataHandler(const char* data, int length) + void CharacterDataHandler(const char* data, int length) override { this->Data.append(data, length); } @@ -107,9 +111,8 @@ public: { if (this->Group) { return this->Group; - } else { - return this->Generator->CreateString(this->String); } + return this->Generator->CreateString(this->String); } }; @@ -160,8 +163,9 @@ cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory() cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( const std::string& name, cmake* cm) const { - if (name != GetActualName()) + if (name != GetActualName()) { return nullptr; + } #if defined(CMAKE_BUILD_WITH_CMAKE) cmXcodeVersionParser parser; std::string versionFile; @@ -197,8 +201,8 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( return nullptr; } - CM_AUTO_PTR<cmGlobalXCodeGenerator> gg( - new cmGlobalXCodeGenerator(cm, version_string, version_number)); + auto gg = cm::make_unique<cmGlobalXCodeGenerator>(cm, version_string, + version_number); return gg.release(); #else std::cerr << "CMake should be built with cmake to use Xcode, " @@ -236,10 +240,9 @@ std::string cmGlobalXCodeGenerator::FindXcodeBuildCommand() makeProgram = "xcodebuild"; } return makeProgram; - } else { - // Use cmakexbuild wrapper to suppress environment dump from output. - return cmSystemTools::GetCMakeCommand() + "xbuild"; } + // Use cmakexbuild wrapper to suppress environment dump from output. + return cmSystemTools::GetCMakeCommand() + "xbuild"; } bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts, @@ -434,18 +437,13 @@ void cmGlobalXCodeGenerator::AddExtraTargets( // now make the allbuild depend on all the non-utility targets // in the project - for (std::vector<cmLocalGenerator*>::iterator i = gens.begin(); - i != gens.end(); ++i) { - cmLocalGenerator* lg = *i; - if (this->IsExcluded(root, *i)) { + for (auto& gen : gens) { + if (this->IsExcluded(root, gen)) { continue; } - const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); - l != tgts.end(); l++) { - cmGeneratorTarget* target = *l; - + const std::vector<cmGeneratorTarget*>& tgts = gen->GetGeneratorTargets(); + for (auto target : tgts) { if (target->GetType() == cmStateEnums::GLOBAL_TARGET) { continue; } @@ -471,7 +469,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cmCustomCommandLines commandLines; commandLines.push_back(makeHelper); std::vector<std::string> no_byproducts; - lg->GetMakefile()->AddCustomCommandToTarget( + gen->GetMakefile()->AddCustomCommandToTarget( target->GetName(), no_byproducts, no_depends, commandLines, cmTarget::POST_BUILD, "Depend check for xcode", dir.c_str(), true, false, "", false, cmMakefile::AcceptObjectLibraryCommands); @@ -483,7 +481,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( } // Refer to the build configuration file for easy editing. - listfile = lg->GetCurrentSourceDirectory(); + listfile = gen->GetCurrentSourceDirectory(); listfile += "/"; listfile += "CMakeLists.txt"; target->AddSource(listfile); @@ -495,9 +493,8 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( cmLocalGenerator* root, std::vector<cmLocalGenerator*> const& gens) { std::vector<std::string> lfiles; - for (std::vector<cmLocalGenerator*>::const_iterator gi = gens.begin(); - gi != gens.end(); ++gi) { - std::vector<std::string> const& lf = (*gi)->GetMakefile()->GetListFiles(); + for (auto gen : gens) { + std::vector<std::string> const& lf = gen->GetMakefile()->GetListFiles(); lfiles.insert(lfiles.end(), lf.begin(), lf.end()); } @@ -557,8 +554,8 @@ void cmGlobalXCodeGenerator::SortXCodeObjects() void cmGlobalXCodeGenerator::ClearXCodeObjects() { this->TargetDoneSet.clear(); - for (unsigned int i = 0; i < this->XCodeObjects.size(); ++i) { - delete this->XCodeObjects[i]; + for (auto& obj : this->XCodeObjects) { + delete obj; } this->XCodeObjects.clear(); this->XCodeObjectIDs.clear(); @@ -572,7 +569,7 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects() void cmGlobalXCodeGenerator::addObject(cmXCodeObject* obj) { if (obj->GetType() == cmXCodeObject::OBJECT) { - std::string id = obj->GetId(); + const std::string& id = obj->GetId(); // If this is a duplicate id, it's an error: // @@ -669,7 +666,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( if (const char* cflags = sf->GetProperty("COMPILE_FLAGS")) { cmGeneratorExpression ge; std::string configName = "NO-PER-CONFIG-SUPPORT-IN-XCODE"; - CM_AUTO_PTR<cmCompiledGeneratorExpression> compiledExpr = ge.Parse(cflags); + std::unique_ptr<cmCompiledGeneratorExpression> compiledExpr = + ge.Parse(cflags); const char* processed = compiledExpr->Evaluate(lg, configName); if (compiledExpr->GetHadContextSensitiveCondition()) { std::ostringstream e; @@ -931,13 +929,11 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( typedef std::map<std::string, cmGeneratorTarget*, cmCompareTargets> cmSortedTargets; cmSortedTargets sortedTargets; - for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); - l != tgts.end(); l++) { - sortedTargets[(*l)->GetName()] = *l; + for (auto tgt : tgts) { + sortedTargets[tgt->GetName()] = tgt; } - for (cmSortedTargets::iterator l = sortedTargets.begin(); - l != sortedTargets.end(); l++) { - cmGeneratorTarget* gtgt = l->second; + for (auto& sortedTarget : sortedTargets) { + cmGeneratorTarget* gtgt = sortedTarget.second; std::string targetName = gtgt->GetName(); @@ -1040,9 +1036,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( sourceBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin(); - i != sourceFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& sourceFile : sourceFiles) { + buildFiles->AddObject(sourceFile); } sourceBuildPhase->AddAttribute("files", buildFiles); sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", @@ -1058,9 +1053,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( headerBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector<cmXCodeObject*>::iterator i = headerFiles.begin(); - i != headerFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& headerFile : headerFiles) { + buildFiles->AddObject(headerFile); } headerBuildPhase->AddAttribute("files", buildFiles); headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", @@ -1077,9 +1071,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( resourceBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin(); - i != resourceFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& resourceFile : resourceFiles) { + buildFiles->AddObject(resourceFile); } resourceBuildPhase->AddAttribute("files", buildFiles); resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", @@ -1187,9 +1180,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); frameworkBuildPhase->AddAttribute("files", buildFiles); - for (std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin(); - i != externalObjFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& externalObjFile : externalObjFiles) { + buildFiles->AddObject(externalObjFile); } frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", this->CreateString("0")); @@ -1210,14 +1202,13 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( void cmGlobalXCodeGenerator::ForceLinkerLanguages() { - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { + for (auto& localGenerator : this->LocalGenerators) { const std::vector<cmGeneratorTarget*>& tgts = - this->LocalGenerators[i]->GetGeneratorTargets(); + localGenerator->GetGeneratorTargets(); // All targets depend on the build-system check target. - for (std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin(); - ti != tgts.end(); ++ti) { + for (auto tgt : tgts) { // This makes sure all targets link using the proper language. - this->ForceLinkerLanguage(*ti); + this->ForceLinkerLanguage(tgt); } } } @@ -1238,9 +1229,8 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt) // If the language is compiled as a source trust Xcode to link with it. cmLinkImplementation const* impl = gtgt->GetLinkImplementation("NOCONFIG"); - for (std::vector<std::string>::const_iterator li = impl->Languages.begin(); - li != impl->Languages.end(); ++li) { - if (*li == llang) { + for (auto const& Language : impl->Languages) { + if (Language == llang) { return; } } @@ -1278,7 +1268,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase( const char* name, const char* name2, cmGeneratorTarget* target, const std::vector<cmCustomCommand>& commands) { - if (commands.size() == 0 && strcmp(name, "CMake ReRun") != 0) { + if (commands.empty() && strcmp(name, "CMake ReRun") != 0) { return nullptr; } cmXCodeObject* buildPhase = @@ -1466,7 +1456,7 @@ void cmGlobalXCodeGenerator::FilterConfigurationAttribute( return; } - std::string::size_type endVariant = attribute.find("]", beginVariant + 9); + std::string::size_type endVariant = attribute.find(']', beginVariant + 9); if (endVariant == std::string::npos) { // There is no terminating bracket. return; @@ -1542,16 +1532,15 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( makefileStream << "all: "; std::map<const cmCustomCommand*, std::string> tname; int count = 0; - for (std::vector<cmCustomCommand>::const_iterator i = commands.begin(); - i != commands.end(); ++i) { - cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator); + for (auto const& command : commands) { + cmCustomCommandGenerator ccg(command, configName, + this->CurrentLocalGenerator); if (ccg.GetNumberOfCommands() > 0) { const std::vector<std::string>& outputs = ccg.GetOutputs(); if (!outputs.empty()) { - for (std::vector<std::string>::const_iterator o = outputs.begin(); - o != outputs.end(); ++o) { + for (auto const& output : outputs) { makefileStream << "\\\n\t" - << this->ConvertToRelativeForMake(o->c_str()); + << this->ConvertToRelativeForMake(output.c_str()); } } else { std::ostringstream str; @@ -1562,18 +1551,18 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } } makefileStream << "\n\n"; - for (std::vector<cmCustomCommand>::const_iterator i = commands.begin(); - i != commands.end(); ++i) { - cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator); + for (auto const& command : commands) { + cmCustomCommandGenerator ccg(command, configName, + this->CurrentLocalGenerator); if (ccg.GetNumberOfCommands() > 0) { makefileStream << "\n"; const std::vector<std::string>& outputs = ccg.GetOutputs(); if (!outputs.empty()) { // There is at least one output, start the rule for it const char* sep = ""; - for (std::vector<std::string>::const_iterator oi = outputs.begin(); - oi != outputs.end(); ++oi) { - makefileStream << sep << this->ConvertToRelativeForMake(oi->c_str()); + for (auto const& output : outputs) { + makefileStream << sep + << this->ConvertToRelativeForMake(output.c_str()); sep = " "; } makefileStream << ": "; @@ -1581,11 +1570,9 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( // There are no outputs. Use the generated force rule name. makefileStream << tname[&ccg.GetCC()] << ": "; } - for (std::vector<std::string>::const_iterator d = - ccg.GetDepends().begin(); - d != ccg.GetDepends().end(); ++d) { + for (auto const& d : ccg.GetDepends()) { std::string dep; - if (this->CurrentLocalGenerator->GetRealDependency(*d, configName, + if (this->CurrentLocalGenerator->GetRealDependency(d, configName, dep)) { makefileStream << "\\\n" << this->ConvertToRelativeForMake(dep.c_str()); @@ -1640,9 +1627,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::set<std::string> languages; gtgt->GetLanguages(languages, configName); std::map<std::string, std::string> cflags; - for (std::set<std::string>::iterator li = languages.begin(); - li != languages.end(); ++li) { - std::string const& lang = *li; + for (auto const& lang : languages) { std::string& flags = cflags[lang]; // Add language-specific flags. @@ -1738,9 +1723,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } else { cmXCodeObject* archObjects = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector<std::string>::iterator i = archs.begin(); - i != archs.end(); i++) { - archObjects->AddObject(this->CreateString(*i)); + for (auto& arch : archs) { + archObjects->AddObject(this->CreateString(arch)); } buildSettings->AddAttribute("ARCHS", archObjects); } @@ -1965,10 +1949,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::set<std::string> emitted; emitted.insert("/System/Library/Frameworks"); - for (std::vector<std::string>::iterator i = includes.begin(); - i != includes.end(); ++i) { - if (this->NameResolvesToFramework(*i)) { - std::string frameworkDir = *i; + for (auto& include : includes) { + if (this->NameResolvesToFramework(include)) { + std::string frameworkDir = include; frameworkDir += "/../"; frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); if (emitted.insert(frameworkDir).second) { @@ -1981,9 +1964,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } } } else { - std::string incpath = this->XCodeEscapePath(*i); + std::string incpath = this->XCodeEscapePath(include); if (emitSystemIncludes && - gtgt->IsSystemIncludeDirectory(*i, configName)) { + gtgt->IsSystemIncludeDirectory(include, configName)) { sysdirs.Add(incpath); } else { dirs.Add(incpath); @@ -1993,12 +1976,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Add framework search paths needed for linking. if (cmComputeLinkInformation* cli = gtgt->GetLinkInformation(configName)) { std::vector<std::string> const& fwDirs = cli->GetFrameworkPaths(); - for (std::vector<std::string>::const_iterator fdi = fwDirs.begin(); - fdi != fwDirs.end(); ++fdi) { - if (emitted.insert(*fdi).second) { - std::string incpath = this->XCodeEscapePath(*fdi); + for (auto const& fwDir : fwDirs) { + if (emitted.insert(fwDir).second) { + std::string incpath = this->XCodeEscapePath(fwDir); if (emitSystemIncludes && - gtgt->IsSystemIncludeDirectory(*fdi, configName)) { + gtgt->IsSystemIncludeDirectory(fwDir, configName)) { sysfdirs.Add(incpath); } else { fdirs.Add(incpath); @@ -2026,13 +2008,12 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // system include directory awareness. We need to also keep on setting // HEADER_SEARCH_PATHS to work around a missing compile options flag for // GNU assembly files (#16449) - for (std::set<std::string>::iterator li = languages.begin(); - li != languages.end(); ++li) { + for (auto const& language : languages) { std::string includeFlags = this->CurrentLocalGenerator->GetIncludeFlags( - includes, gtgt, *li, true, false, configName); + includes, gtgt, language, true, false, configName); if (!includeFlags.empty()) { - cflags[*li] += " " + includeFlags; + cflags[language] += " " + includeFlags; } } } @@ -2043,10 +2024,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::string optLevel = "0"; // Minimal map of flags to build settings. - for (std::set<std::string>::iterator li = languages.begin(); - li != languages.end(); ++li) { - std::string& flags = cflags[*li]; - std::string& gflag = gflags[*li]; + for (auto const& language : languages) { + std::string& flags = cflags[language]; + std::string& gflag = gflags[language]; std::string oflag = this->ExtractFlagRegex("(^| )(-Ofast|-Os|-O[0-9]*)( |$)", 2, flags); if (oflag.size() == 2) { @@ -2071,10 +2051,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, if (!same_gflags) { // We can't set the Xcode flag differently depending on the language, // so put them back in this case. - for (std::set<std::string>::iterator li = languages.begin(); - li != languages.end(); ++li) { - cflags[*li] += " "; - cflags[*li] += gflags[*li]; + for (auto const& language : languages) { + cflags[language] += " "; + cflags[language] += gflags[language]; } debugStr = "NO"; } else if (last_gflag && (last_gflag->empty() || *last_gflag == "-g0")) { @@ -2091,18 +2070,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, this->CreateString("NO")); buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN", this->CreateString("NO")); - for (std::set<std::string>::iterator li = languages.begin(); - li != languages.end(); ++li) { - std::string flags = cflags[*li] + " " + defFlags; - if (*li == "CXX") { + for (auto const& language : languages) { + std::string flags = cflags[language] + " " + defFlags; + if (language == "CXX") { buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS", this->CreateString(flags)); - } else if (*li == "Fortran") { + } else if (language == "Fortran") { buildSettings->AddAttribute("IFORT_OTHER_FLAGS", this->CreateString(flags)); - } else if (*li == "C") { + } else if (language == "C") { buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(flags)); - } else if (*li == "Swift") { + } else if (language == "Swift") { buildSettings->AddAttribute("OTHER_SWIFT_FLAGS", this->CreateString(flags)); } @@ -2226,15 +2204,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Convert "XCODE_ATTRIBUTE_*" properties directly. { std::vector<std::string> const& props = gtgt->GetPropertyKeys(); - for (std::vector<std::string>::const_iterator i = props.begin(); - i != props.end(); ++i) { - if (i->find("XCODE_ATTRIBUTE_") == 0) { - std::string attribute = i->substr(16); + for (auto const& prop : props) { + if (prop.find("XCODE_ATTRIBUTE_") == 0) { + std::string attribute = prop.substr(16); this->FilterConfigurationAttribute(configName, attribute); if (!attribute.empty()) { cmGeneratorExpression ge; std::string processed = - ge.Parse(gtgt->GetProperty(*i)) + ge.Parse(gtgt->GetProperty(prop)) ->Evaluate(this->CurrentLocalGenerator, configName); buildSettings->AddAttribute(attribute, this->CreateString(processed)); @@ -2322,15 +2299,15 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target, configlist->SetComment(comment); target->AddAttribute("buildConfigurationList", this->CreateObjectReference(configlist)); - for (unsigned int i = 0; i < configVector.size(); ++i) { + for (auto const& i : configVector) { cmXCodeObject* config = this->CreateObject(cmXCodeObject::XCBuildConfiguration); buildConfigurations->AddObject(config); cmXCodeObject* buildSettings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); - this->CreateBuildSettings(gtgt, buildSettings, configVector[i]); - config->AddAttribute("name", this->CreateString(configVector[i])); - config->SetComment(configVector[i]); + this->CreateBuildSettings(gtgt, buildSettings, i); + config->AddAttribute("name", this->CreateString(i)); + config->SetComment(i); config->AddAttribute("buildSettings", buildSettings); } if (!configVector.empty()) { @@ -2350,9 +2327,8 @@ const char* cmGlobalXCodeGenerator::GetTargetLinkFlagsVar( (target->GetType() == cmStateEnums::STATIC_LIBRARY || target->GetType() == cmStateEnums::OBJECT_LIBRARY)) { return "OTHER_LIBTOOLFLAGS"; - } else { - return "OTHER_LDFLAGS"; } + return "OTHER_LDFLAGS"; } const char* cmGlobalXCodeGenerator::GetTargetFileType( @@ -2369,12 +2345,13 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType( return (target->GetPropertyAsBool("FRAMEWORK") ? "wrapper.framework" : "archive.ar"); case cmStateEnums::MODULE_LIBRARY: - if (target->IsXCTestOnApple()) + if (target->IsXCTestOnApple()) { return "wrapper.cfbundle"; - else if (target->IsCFBundleOnApple()) + } + if (target->IsCFBundleOnApple()) { return "wrapper.plug-in"; - else - return "compiled.mach-o.executable"; + } + return "compiled.mach-o.executable"; case cmStateEnums::SHARED_LIBRARY: return (target->GetPropertyAsBool("FRAMEWORK") ? "wrapper.framework" @@ -2402,12 +2379,13 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType( ? "com.apple.product-type.framework" : "com.apple.product-type.library.static"); case cmStateEnums::MODULE_LIBRARY: - if (target->IsXCTestOnApple()) + if (target->IsXCTestOnApple()) { return "com.apple.product-type.bundle.unit-test"; - else if (target->IsCFBundleOnApple()) + } else if (target->IsCFBundleOnApple()) { return "com.apple.product-type.bundle"; - else + } else { return "com.apple.product-type.tool"; + } case cmStateEnums::SHARED_LIBRARY: return (target->GetPropertyAsBool("FRAMEWORK") ? "com.apple.product-type.framework" @@ -2561,15 +2539,14 @@ void cmGlobalXCodeGenerator::AppendBuildSettingAttribute( std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList(); // each configuration and the target itself has a buildSettings in it // list.push_back(target); - for (std::vector<cmXCodeObject*>::iterator i = list.begin(); i != list.end(); - ++i) { + for (auto& i : list) { if (!configName.empty()) { - if ((*i)->GetObject("name")->GetString() == configName) { - cmXCodeObject* settings = (*i)->GetObject("buildSettings"); + if (i->GetObject("name")->GetString() == configName) { + cmXCodeObject* settings = i->GetObject("buildSettings"); this->AppendOrAddBuildSetting(settings, attribute, value); } } else { - cmXCodeObject* settings = (*i)->GetObject("buildSettings"); + cmXCodeObject* settings = i->GetObject("buildSettings"); this->AppendOrAddBuildSetting(settings, attribute, value); } } @@ -2588,20 +2565,15 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) // Add dependencies on other CMake targets. TargetDependSet const& deps = this->GetTargetDirectDepends(gt); - for (TargetDependSet::const_iterator i = deps.begin(); i != deps.end(); - ++i) { - if (cmXCodeObject* dptarget = this->FindXCodeTarget(*i)) { + for (auto dep : deps) { + if (cmXCodeObject* dptarget = this->FindXCodeTarget(dep)) { this->AddDependTarget(target, dptarget); } } // Loop over configuration types and set per-configuration info. - for (std::vector<std::string>::iterator i = - this->CurrentConfigurationTypes.begin(); - i != this->CurrentConfigurationTypes.end(); ++i) { + for (auto const& configName : this->CurrentConfigurationTypes) { // Get the current configuration name. - std::string configName = *i; - if (this->XcodeVersion >= 50) { // Add object library contents as link flags. std::string linkObjs; @@ -2637,9 +2609,8 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) // Add dependencies directly on library files. { std::vector<std::string> const& libDeps = cli.GetDepends(); - for (std::vector<std::string>::const_iterator j = libDeps.begin(); - j != libDeps.end(); ++j) { - target->AddDependLibrary(configName, *j); + for (auto const& libDep : libDeps) { + target->AddDependLibrary(configName, libDep); } } @@ -2647,16 +2618,15 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) { std::vector<std::string> const& libDirs = cli.GetDirectories(); std::string linkDirs; - for (std::vector<std::string>::const_iterator libDir = libDirs.begin(); - libDir != libDirs.end(); ++libDir) { - if (libDir->size() && *libDir != "/usr/lib") { + for (auto const& libDir : libDirs) { + if (!libDir.empty() && libDir != "/usr/lib") { // Now add the same one but append // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it: linkDirs += " "; linkDirs += this->XCodeEscapePath( - *libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"); + libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"); linkDirs += " "; - linkDirs += this->XCodeEscapePath(*libDir); + linkDirs += this->XCodeEscapePath(libDir); } } this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS", @@ -2669,18 +2639,18 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) const char* sep = ""; typedef cmComputeLinkInformation::ItemVector ItemVector; ItemVector const& libNames = cli.GetItems(); - for (ItemVector::const_iterator li = libNames.begin(); - li != libNames.end(); ++li) { + for (auto const& libName : libNames) { linkLibs += sep; sep = " "; - if (li->IsPath) { - linkLibs += this->XCodeEscapePath(li->Value); - } else if (!li->Target || - li->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { - linkLibs += li->Value; + if (libName.IsPath) { + linkLibs += this->XCodeEscapePath(libName.Value); + } else if (!libName.Target || + libName.Target->GetType() != + cmStateEnums::INTERFACE_LIBRARY) { + linkLibs += libName.Value; } - if (li->Target && !li->Target->IsImported()) { - target->AddDependTarget(configName, li->Target->GetName()); + if (libName.Target && !libName.Target->IsImported()) { + target->AddDependTarget(configName, libName.Target->GetName()); } } this->AppendBuildSettingAttribute( @@ -2692,15 +2662,12 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) bool cmGlobalXCodeGenerator::CreateGroups( std::vector<cmLocalGenerator*>& generators) { - for (std::vector<cmLocalGenerator*>::iterator i = generators.begin(); - i != generators.end(); ++i) { - cmMakefile* mf = (*i)->GetMakefile(); + for (auto& generator : generators) { + cmMakefile* mf = generator->GetMakefile(); std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups(); - const std::vector<cmGeneratorTarget*>& tgts = (*i)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); - l != tgts.end(); l++) { - cmGeneratorTarget* gtgt = *l; - + const std::vector<cmGeneratorTarget*>& tgts = + generator->GetGeneratorTargets(); + for (auto gtgt : tgts) { // Same skipping logic here as in CreateXCodeTargets so that we do not // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source // groups: @@ -2724,10 +2691,8 @@ bool cmGlobalXCodeGenerator::CreateGroups( gtgt->GetAllConfigSources(); // Put cmSourceFile instances in proper groups: - for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si = - sources.begin(); - si != sources.end(); ++si) { - cmSourceFile const* sf = si->Source; + for (auto const& si : sources) { + cmSourceFile const* sf = si.Source; if (this->XcodeVersion >= 50 && !sf->GetObjectLibrary().empty()) { // Object library files go on the link line instead. continue; @@ -2746,19 +2711,21 @@ bool cmGlobalXCodeGenerator::CreateGroups( } cmXCodeObject* cmGlobalXCodeGenerator::CreatePBXGroup(cmXCodeObject* parent, - std::string name) + const std::string& name) { cmXCodeObject* parentChildren = nullptr; - if (parent) + if (parent) { parentChildren = parent->GetObject("children"); + } cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup); cmXCodeObject* groupChildren = this->CreateObject(cmXCodeObject::OBJECT_LIST); group->AddAttribute("name", this->CreateString(name)); group->AddAttribute("children", groupChildren); group->AddAttribute("sourceTree", this->CreateString("<group>")); - if (parentChildren) + if (parentChildren) { parentChildren->AddObject(group); + } return group; } @@ -2812,7 +2779,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup( // If it's the default source group (empty name) then put the source file // directly in the tgroup... // - if (std::string(sg->GetFullName()) == "") { + if (std::string(sg->GetFullName()).empty()) { this->GroupNameMap[s] = tgroup; return tgroup; } @@ -2823,13 +2790,13 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup( cmSystemTools::tokenize(sg->GetFullName(), "\\"); std::string curr_folder = target; curr_folder += "/"; - for (std::vector<std::string>::size_type i = 0; i < folders.size(); i++) { - curr_folder += folders[i]; + for (auto const& folder : folders) { + curr_folder += folder; std::map<std::string, cmXCodeObject*>::iterator i_folder = this->GroupNameMap.find(curr_folder); // Create new folder if (i_folder == this->GroupNameMap.end()) { - cmXCodeObject* group = this->CreatePBXGroup(tgroup, folders[i]); + cmXCodeObject* group = this->CreatePBXGroup(tgroup, folder); this->GroupNameMap[curr_folder] = group; tgroup = group; } else { @@ -2853,10 +2820,10 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO")); cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i) { + for (auto& CurrentConfigurationType : this->CurrentConfigurationTypes) { cmXCodeObject* buildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle); - const char* name = this->CurrentConfigurationTypes[i].c_str(); + const char* name = CurrentConfigurationType.c_str(); buildStyle->AddAttribute("name", this->CreateString(name)); buildStyle->SetComment(name); cmXCodeObject* sgroup = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); @@ -2889,7 +2856,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( std::string project_id = "PROJECT_"; project_id += root->GetProjectName(); this->RootObject->SetId( - this->GetOrCreateId(project_id.c_str(), this->RootObject->GetId())); + this->GetOrCreateId(project_id, this->RootObject->GetId())); group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); this->RootObject->AddAttribute("mainGroup", @@ -2905,15 +2872,16 @@ 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) + if (this->XcodeVersion >= 32) { this->RootObject->AddAttribute("compatibilityVersion", this->CreateString("Xcode 3.2")); - else if (this->XcodeVersion >= 31) + } else if (this->XcodeVersion >= 31) { this->RootObject->AddAttribute("compatibilityVersion", this->CreateString("Xcode 3.1")); - else + } else { this->RootObject->AddAttribute("compatibilityVersion", this->CreateString("Xcode 3.0")); + } // Point Xcode at the top of the source tree. { std::string pdir = @@ -2938,8 +2906,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( config->AddAttribute("name", this->CreateString(name)); configs.push_back(std::make_pair(name, config)); } - for (Configs::iterator c = configs.begin(); c != configs.end(); ++c) { - buildConfigurations->AddObject(c->second); + for (auto& config : configs) { + buildConfigurations->AddObject(config.second); } configlist->AddAttribute("buildConfigurations", buildConfigurations); @@ -2997,7 +2965,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( symroot += "/build"; buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot)); - for (Configs::iterator i = configs.begin(); i != configs.end(); ++i) { + for (auto& config : configs) { cmXCodeObject* buildSettingsForCfg = this->CreateFlatClone(buildSettings); // Put this last so it can override existing settings @@ -3007,43 +2975,38 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( d != vars.end(); ++d) { if (d->find("CMAKE_XCODE_ATTRIBUTE_") == 0) { std::string attribute = d->substr(22); - this->FilterConfigurationAttribute(i->first, attribute); + this->FilterConfigurationAttribute(config.first, attribute); if (!attribute.empty()) { cmGeneratorExpression ge; std::string processed = ge.Parse(this->CurrentMakefile->GetDefinition(*d)) - ->Evaluate(this->CurrentLocalGenerator, i->first); + ->Evaluate(this->CurrentLocalGenerator, config.first); buildSettingsForCfg->AddAttribute(attribute, this->CreateString(processed)); } } } // store per-config buildSettings into configuration object - i->second->AddAttribute("buildSettings", buildSettingsForCfg); + config.second->AddAttribute("buildSettings", buildSettingsForCfg); } this->RootObject->AddAttribute("buildConfigurationList", this->CreateObjectReference(configlist)); std::vector<cmXCodeObject*> targets; - for (std::vector<cmLocalGenerator*>::iterator i = generators.begin(); - i != generators.end(); ++i) { - if (!this->CreateXCodeTargets(*i, targets)) { + for (auto& generator : generators) { + if (!this->CreateXCodeTargets(generator, targets)) { return false; } } // loop over all targets and add link and depend info - for (std::vector<cmXCodeObject*>::iterator i = targets.begin(); - i != targets.end(); ++i) { - cmXCodeObject* t = *i; + for (auto t : targets) { this->AddDependAndLinkInformation(t); } this->CreateXCodeDependHackTarget(targets); // now add all targets to the root object cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector<cmXCodeObject*>::iterator i = targets.begin(); - i != targets.end(); ++i) { - cmXCodeObject* t = *i; + for (auto t : targets) { allTargets->AddObject(t); cmXCodeObject* productRef = t->GetObject("productReference"); if (productRef) { @@ -3136,9 +3099,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( this->CurrentConfigurationTypes.begin(); ct != this->CurrentConfigurationTypes.end(); ++ct) { std::string configName = *ct; - for (std::vector<cmXCodeObject*>::iterator i = targets.begin(); - i != targets.end(); ++i) { - cmXCodeObject* target = *i; + for (auto target : targets) { cmGeneratorTarget* gt = target->GetTarget(); if (gt->GetType() == cmStateEnums::EXECUTABLE || @@ -3163,9 +3124,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( target->GetDependTargets().find(*ct); if (y != target->GetDependTargets().end()) { std::vector<std::string> const& deptgts = y->second; - for (std::vector<std::string>::const_iterator d = deptgts.begin(); - d != deptgts.end(); ++d) { - makefileStream << this->PostBuildMakeTarget(*d, *ct) << ": " + for (auto const& deptgt : deptgts) { + makefileStream << this->PostBuildMakeTarget(deptgt, *ct) << ": " << trel << "\n"; } } @@ -3187,9 +3147,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( target->GetDependLibraries().find(*ct); if (x != target->GetDependLibraries().end()) { std::vector<std::string> const& deplibs = x->second; - for (std::vector<std::string>::const_iterator d = deplibs.begin(); - d != deplibs.end(); ++d) { - std::string file = this->ConvertToRelativeForMake(d->c_str()); + for (auto const& deplib : deplibs) { + std::string file = this->ConvertToRelativeForMake(deplib.c_str()); makefileStream << "\\\n\t" << file; dummyRules.insert(file); } @@ -3221,11 +3180,9 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( if (this->Architectures.size() > 1) { std::string universal = this->GetObjectsNormalDirectory( this->CurrentProject, configName, gt); - for (std::vector<std::string>::iterator arch = - this->Architectures.begin(); - arch != this->Architectures.end(); ++arch) { + for (auto& architecture : this->Architectures) { std::string universalFile = universal; - universalFile += *arch; + universalFile += architecture; universalFile += "/"; universalFile += gt->GetFullName(configName); makefileStream << "\t/bin/rm -f " @@ -3242,22 +3199,20 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( makefileStream << "\n\n" << "# For each target create a dummy rule" << "so the target does not have to exist\n"; - for (std::set<std::string>::const_iterator it = dummyRules.begin(); - it != dummyRules.end(); ++it) { - makefileStream << *it << ":\n"; + for (auto const& dummyRule : dummyRules) { + makefileStream << dummyRule << ":\n"; } } void cmGlobalXCodeGenerator::OutputXCodeProject( cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators) { - if (generators.size() == 0) { + if (generators.empty()) { return; } // Skip local generators that are excluded from this project. - for (std::vector<cmLocalGenerator*>::iterator g = generators.begin(); - g != generators.end(); ++g) { - if (this->IsExcluded(root, *g)) { + for (auto& generator : generators) { + if (this->IsExcluded(root, generator)) { continue; } } @@ -3385,12 +3340,13 @@ void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, cmXCodeObject::Indent(1, fout); fout << "};\n"; cmXCodeObject::Indent(1, fout); - if (this->XcodeVersion >= 32) + if (this->XcodeVersion >= 32) { fout << "objectVersion = 46;\n"; - else if (this->XcodeVersion >= 31) + } else if (this->XcodeVersion >= 31) { fout << "objectVersion = 45;\n"; - else + } else { fout << "objectVersion = 44;\n"; + } cmXCode21Object::PrintList(this->XCodeObjects, fout); cmXCodeObject::Indent(1, fout); fout << "rootObject = " << this->RootObject->GetId() @@ -3510,11 +3466,10 @@ void cmGlobalXCodeGenerator::AppendDefines( { // GCC_PREPROCESSOR_DEFINITIONS is a space-separated list of definitions. std::string def; - for (std::vector<std::string>::const_iterator di = defines.begin(); - di != defines.end(); ++di) { + for (auto const& define : defines) { // Start with -D if requested. def = dflag ? "-D" : ""; - def += *di; + def += define; // Append the flag with needed escapes. std::string tmp; diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 81d1bd0..e9ca91c 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -106,7 +106,8 @@ protected: private: cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt, cmSourceGroup* sg); - cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, std::string name); + cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, + const std::string& name); bool CreateGroups(std::vector<cmLocalGenerator*>& generators); std::string XCodeEscapePath(const std::string& p); std::string RelativeToSource(const char* p); diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index ca87cbf..dd2993d 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -4,6 +4,7 @@ #include <cstddef> #include <iostream> +#include <memory> // IWYU pragma: keep #include <sstream> #include <utility> @@ -15,7 +16,6 @@ #include "cmStateSnapshot.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" namespace { @@ -147,8 +147,8 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator ggi(&cm); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&ggi, cm.GetCurrentSnapshot())); - CM_AUTO_PTR<cmLocalGenerator> lg(ggi.CreateLocalGenerator(mf.get())); + cmMakefile mf(&ggi, cm.GetCurrentSnapshot()); + std::unique_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator(&mf)); const char* inFileName = settingsFileName; @@ -159,7 +159,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, } } - if (!mf->ReadListFile(inFileName)) { + if (!mf.ReadListFile(inFileName)) { cmSystemTools::Error("Problem opening GraphViz options file: ", inFileName); return; @@ -169,7 +169,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, #define __set_if_set(var, cmakeDefinition) \ { \ - const char* value = mf->GetDefinition(cmakeDefinition); \ + const char* value = mf.GetDefinition(cmakeDefinition); \ if (value) { \ (var) = value; \ } \ @@ -182,9 +182,9 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, #define __set_bool_if_set(var, cmakeDefinition) \ { \ - const char* value = mf->GetDefinition(cmakeDefinition); \ + const char* value = mf.GetDefinition(cmakeDefinition); \ if (value) { \ - (var) = mf->IsOn(cmakeDefinition); \ + (var) = mf.IsOn(cmakeDefinition); \ } \ } diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 1a01854..4926f22 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -8,9 +8,10 @@ #include "cmMakefile.h" #include "cmOutputConverter.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" +#include <memory> // IWYU pragma: keep + static std::string cmIfCommandError( std::vector<cmExpandedCommandArgument> const& args) { @@ -36,7 +37,8 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // if this is the endif for this if statement, then start executing if (!this->ScopeDepth) { // Remove the function blocker for this scope or bail. - CM_AUTO_PTR<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(this, lff)); + std::unique_ptr<cmFunctionBlocker> fb( + mf.RemoveFunctionBlocker(this, lff)); if (!fb.get()) { return false; } diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index 49e57b1..e4209bd 100644 --- a/Source/cmInstallDirectoryGenerator.cxx +++ b/Source/cmInstallDirectoryGenerator.cxx @@ -7,7 +7,8 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" + +#include <memory> // IWYU pragma: keep cmInstallDirectoryGenerator::cmInstallDirectoryGenerator( std::vector<std::string> const& dirs, const char* dest, @@ -63,7 +64,7 @@ void cmInstallDirectoryGenerator::GenerateScriptForConfig( std::vector<std::string> dirs; cmGeneratorExpression ge; for (std::string const& d : this->Directories) { - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(d); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(d); cmSystemTools::ExpandListArgument( cge->Evaluate(this->LocalGenerator, config), dirs); } diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx index 0e79563..68e3f86 100644 --- a/Source/cmInstallFilesGenerator.cxx +++ b/Source/cmInstallFilesGenerator.cxx @@ -5,7 +5,8 @@ #include "cmGeneratorExpression.h" #include "cmInstallType.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" + +#include <memory> // IWYU pragma: keep class cmLocalGenerator; @@ -82,7 +83,7 @@ void cmInstallFilesGenerator::GenerateScriptForConfig( std::vector<std::string> files; cmGeneratorExpression ge; for (std::string const& f : this->Files) { - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(f); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(f); cmSystemTools::ExpandListArgument( cge->Evaluate(this->LocalGenerator, config), files); } diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index c8144aa..3ffeabd 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -16,9 +16,7 @@ cmInstalledFile::cmInstalledFile() cmInstalledFile::~cmInstalledFile() { - if (NameExpression) { - delete NameExpression; - } + delete NameExpression; } cmInstalledFile::Property::Property() diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index fbf754f..47a4959 100644 --- a/Source/cmInstalledFile.h +++ b/Source/cmInstalledFile.h @@ -6,9 +6,9 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmGeneratorExpression.h" -#include "cm_auto_ptr.hxx" #include <map> +#include <memory> // IWYU pragma: keep #include <string> #include <vector> @@ -22,7 +22,7 @@ class cmMakefile; class cmInstalledFile { public: - typedef CM_AUTO_PTR<cmCompiledGeneratorExpression> + typedef std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpressionPtrType; typedef std::vector<cmCompiledGeneratorExpression*> ExpressionVectorType; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 73f5a16..477ce51 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -5,6 +5,7 @@ #include <algorithm> #include <assert.h> #include <iterator> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <utility> @@ -22,7 +23,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg, @@ -505,7 +505,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher( std::string launcher = property_value; launcher += " "; - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->CreateRulePlaceholderExpander()); rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 50ed0ed..e26182a 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -5,6 +5,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/Terminal.h" #include <algorithm> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <utility> @@ -28,7 +29,6 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmVersion.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" // Include dependency scanners for supported languages. Only the @@ -121,9 +121,9 @@ void cmLocalUnixMakefileGenerator3::Generate() if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - CM_AUTO_PTR<cmMakefileTargetGenerator> tg( + std::unique_ptr<cmMakefileTargetGenerator> tg( cmMakefileTargetGenerator::New(target)); - if (tg.get()) { + if (tg) { tg->WriteRuleFiles(); gg->RecordTargetProgress(tg.get()); } @@ -930,7 +930,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( *content << dir; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->CreateRulePlaceholderExpander()); // Add each command line to the set of commands. diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index db1776a..5e81514 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -17,7 +17,12 @@ public: virtual void CharacterDataHandler(const char* data, int length) { if (this->DoGUID) { - this->GUID.assign(data + 1, length - 2); + if (data[0] == '{') { + // remove surrounding curly brackets + this->GUID.assign(data + 1, length - 2); + } else { + this->GUID.assign(data, length); + } this->DoGUID = false; } } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index a1771ee..8027191 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1453,7 +1453,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( } if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); fc.CompileFlags = cge->Evaluate(lg, *i); needfc = true; } @@ -1849,7 +1849,7 @@ void cmLocalVisualStudio7Generator::OutputTargetRules( if (!addedPrelink) { event.Write(target->GetPreLinkCommands()); } - CM_AUTO_PTR<cmCustomCommand> pcc( + std::unique_ptr<cmCustomCommand> pcc( this->MaybeCreateImplibDir(target, configName, this->FortranProject)); if (pcc.get()) { event.Write(*pcc); @@ -2079,7 +2079,10 @@ public: if (strcmp(atts[i], "ProjectGUID") == 0) { if (atts[i + 1]) { this->GUID = atts[i + 1]; - this->GUID = this->GUID.substr(1, this->GUID.size() - 2); + if (this->GUID[0] == '{') { + // remove surrounding curly brackets + this->GUID = this->GUID.substr(1, this->GUID.size() - 2); + } } else { this->GUID.clear(); } diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 718c8cd..bbb91e0 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -78,12 +78,12 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames( } } -CM_AUTO_PTR<cmCustomCommand> +std::unique_ptr<cmCustomCommand> cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target, const std::string& config, bool isFortran) { - CM_AUTO_PTR<cmCustomCommand> pcc; + std::unique_ptr<cmCustomCommand> pcc; // If an executable exports symbols then VS wants to create an // import library but forgets to create the output directory. diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index c47db4f..cba24fe 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -6,12 +6,11 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <map> -#include <memory> +#include <memory> // IWYU pragma: keep #include <string> #include "cmGlobalVisualStudioGenerator.h" #include "cmLocalGenerator.h" -#include "cm_auto_ptr.hxx" class cmCustomCommand; class cmCustomCommandGenerator; @@ -56,9 +55,8 @@ protected: virtual bool CustomCommandUseLocal() const { return false; } /** Construct a custom command to make exe import lib dir. */ - CM_AUTO_PTR<cmCustomCommand> MaybeCreateImplibDir(cmGeneratorTarget* target, - const std::string& config, - bool isFortran); + std::unique_ptr<cmCustomCommand> MaybeCreateImplibDir( + cmGeneratorTarget* target, const std::string& config, bool isFortran); }; #endif diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index 355c394..853e66c 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -43,9 +43,8 @@ void cmLocalXCodeGenerator::Generate() cmLocalGenerator::Generate(); const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::const_iterator iter = targets.begin(); - iter != targets.end(); ++iter) { - (*iter)->HasMacOSXRpathInstallNameDir(""); + for (auto target : targets) { + target->HasMacOSXRpathInstallNameDir(""); } } @@ -54,9 +53,8 @@ void cmLocalXCodeGenerator::GenerateInstallRules() cmLocalGenerator::GenerateInstallRules(); const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::const_iterator iter = targets.begin(); - iter != targets.end(); ++iter) { - (*iter)->HasMacOSXRpathInstallNameDir(""); + for (auto target : targets) { + target->HasMacOSXRpathInstallNameDir(""); } } @@ -69,10 +67,8 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames( // to avoid exact duplicate file names. Note that Mac file names are not // typically case sensitive, hence the LowerCase. std::map<std::string, int> counts; - for (std::map<cmSourceFile const*, std::string>::iterator si = - mapping.begin(); - si != mapping.end(); ++si) { - cmSourceFile const* sf = si->first; + for (auto& si : mapping) { + cmSourceFile const* sf = si.first; std::string objectName = cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); objectName += ".o"; @@ -82,6 +78,6 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames( if (2 == counts[objectNameLower]) { // TODO: emit warning about duplicate name? } - si->second = objectName; + si.second = objectName; } } diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h index b05eab7..8c9596f 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -27,16 +27,16 @@ public: ///! Set cache only and recurse to false by default. cmLocalXCodeGenerator(cmGlobalGenerator* gg, cmMakefile* mf); - virtual ~cmLocalXCodeGenerator(); - virtual std::string GetTargetDirectory( - cmGeneratorTarget const* target) const; - virtual void AppendFlagEscape(std::string& flags, - const std::string& rawFlag); - virtual void Generate(); + ~cmLocalXCodeGenerator() override; + std::string GetTargetDirectory( + cmGeneratorTarget const* target) const override; + void AppendFlagEscape(std::string& flags, + const std::string& rawFlag) override; + void Generate() override; virtual void GenerateInstallRules(); - virtual void ComputeObjectFilenames( + void ComputeObjectFilenames( std::map<cmSourceFile const*, std::string>& mapping, - cmGeneratorTarget const* gt = nullptr); + cmGeneratorTarget const* gt = nullptr) override; private: }; diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx index 3706dd3..7294c1c 100644 --- a/Source/cmMachO.cxx +++ b/Source/cmMachO.cxx @@ -134,7 +134,7 @@ public: : cmMachOHeaderAndLoadCommands(_swap) { } - bool read_mach_o(cmsys::ifstream& fin) + bool read_mach_o(cmsys::ifstream& fin) override { if (!read(fin, this->Header)) { return false; @@ -251,8 +251,7 @@ cmMachOInternal::cmMachOInternal(const char* fname) } // parse each Mach-O file - for (size_t i = 0; i < this->FatArchs.size(); i++) { - const fat_arch& arch = this->FatArchs[i]; + for (const auto& arch : this->FatArchs) { if (!this->read_mach_o(OSSwapBigToHostInt32(arch.offset))) { return; } @@ -265,8 +264,8 @@ cmMachOInternal::cmMachOInternal(const char* fname) cmMachOInternal::~cmMachOInternal() { - for (size_t i = 0; i < this->MachOList.size(); i++) { - delete this->MachOList[i]; + for (auto& i : this->MachOList) { + delete i; } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index c96b892..32181cf 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -7,6 +7,7 @@ #include <algorithm> #include <assert.h> #include <ctype.h> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdlib.h> #include <string.h> @@ -37,7 +38,6 @@ #include "cmTestGenerator.h" // IWYU pragma: keep #include "cmVersion.h" #include "cmWorkingDirectory.h" -#include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" #include "cmake.h" @@ -264,7 +264,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, // Lookup the command prototype. if (cmCommand* proto = this->GetState()->GetCommand(name)) { // Clone the prototype. - CM_AUTO_PTR<cmCommand> pcmd(proto->Clone()); + std::unique_ptr<cmCommand> pcmd(proto->Clone()); pcmd->SetMakefile(this); // Decide whether to invoke the command. @@ -584,11 +584,12 @@ void cmMakefile::EnforceDirectoryLevelRules() const void cmMakefile::AddEvaluationFile( const std::string& inputFile, - CM_AUTO_PTR<cmCompiledGeneratorExpression> outputName, - CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent) + std::unique_ptr<cmCompiledGeneratorExpression> outputName, + std::unique_ptr<cmCompiledGeneratorExpression> condition, + bool inputIsContent) { this->EvaluationFiles.push_back(new cmGeneratorExpressionEvaluationFile( - inputFile, outputName, condition, inputIsContent, + inputFile, std::move(outputName), std::move(condition), inputIsContent, this->GetPolicyStatus(cmPolicies::CMP0070))); } @@ -2874,7 +2875,7 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError) FunctionBlockersType::size_type barrier = this->FunctionBlockerBarriers.back(); while (this->FunctionBlockers.size() > barrier) { - CM_AUTO_PTR<cmFunctionBlocker> fb(this->FunctionBlockers.back()); + std::unique_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back()); this->FunctionBlockers.pop_back(); if (reportError) { // Report the context in which the unclosed block was opened. @@ -3009,7 +3010,7 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb) this->FunctionBlockers.push_back(fb); } -CM_AUTO_PTR<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( +std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( cmFunctionBlocker* fb, const cmListFileFunction& lff) { // Find the function blocker stack barrier for the current scope. @@ -3042,11 +3043,11 @@ CM_AUTO_PTR<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( } cmFunctionBlocker* b = *pos; this->FunctionBlockers.erase(pos); - return CM_AUTO_PTR<cmFunctionBlocker>(b); + return std::unique_ptr<cmFunctionBlocker>(b); } } - return CM_AUTO_PTR<cmFunctionBlocker>(); + return std::unique_ptr<cmFunctionBlocker>(); } const char* cmMakefile::GetHomeDirectory() const @@ -3082,18 +3083,9 @@ void cmMakefile::SetArgcArgv(const std::vector<std::string>& args) cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const { cmSourceFileLocation sfl(this, sourceName); - -#if defined(_WIN32) || defined(__APPLE__) - const auto& name = cmSystemTools::LowerCase(sfl.GetName()); -#else - const auto& name = sfl.GetName(); -#endif - auto sfsi = this->SourceFileSearchIndex.find(name); - if (sfsi != this->SourceFileSearchIndex.end()) { - for (auto sf : sfsi->second) { - if (sf->Matches(sfl)) { - return sf; - } + for (cmSourceFile* sf : this->SourceFiles) { + if (sf->Matches(sfl)) { + return sf; } } return nullptr; @@ -3107,41 +3099,6 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, sf->SetProperty("GENERATED", "1"); } this->SourceFiles.push_back(sf); - - auto name = sf->GetLocation().GetName(); -#if defined(_WIN32) || defined(__APPLE__) - name = cmSystemTools::LowerCase(name); -#endif - - // For a file in the form "a.b.c" add the cmSourceFile to the index - // at "a.b.c", "a.b" and "a". - auto partial = name; - while (true) { - this->SourceFileSearchIndex[partial].insert(sf); - auto i = partial.rfind('.'); - if (i == std::string::npos) { - break; - } - partial = partial.substr(0, i); - } - - if (sf->GetLocation().ExtensionIsAmbiguous()) { - // For an ambiguous extension also add the various "known" - // extensions to the original filename. - - const auto& srcExts = this->GetCMakeInstance()->GetSourceExtensions(); - for (const auto& ext : srcExts) { - auto name_ext = name + "." + cmSystemTools::LowerCase(ext); - this->SourceFileSearchIndex[name_ext].insert(sf); - } - - const auto& hdrExts = this->GetCMakeInstance()->GetHeaderExtensions(); - for (const auto& ext : hdrExts) { - auto name_ext = name + "." + cmSystemTools::LowerCase(ext); - this->SourceFileSearchIndex[name_ext].insert(sf); - } - } - return sf; } @@ -3747,7 +3704,7 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name, bool global) { // Create the target. - CM_AUTO_PTR<cmTarget> target( + std::unique_ptr<cmTarget> target( new cmTarget(name, type, global ? cmTarget::VisibilityImportedGlobally : cmTarget::VisibilityImported, this)); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 2cae659..0273f5b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -8,12 +8,12 @@ #include "cmsys/RegularExpression.hxx" #include <deque> #include <map> +#include <memory> // IWYU pragma: keep #include <set> #include <stack> #include <stddef.h> #include <string> #include <unordered_map> -#include <unordered_set> #include <vector> #include "cmAlgorithms.h" @@ -23,7 +23,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -93,7 +92,7 @@ public: * Remove the function blocker whose scope ends with the given command. * This returns ownership of the function blocker object. */ - CM_AUTO_PTR<cmFunctionBlocker> RemoveFunctionBlocker( + std::unique_ptr<cmFunctionBlocker> RemoveFunctionBlocker( cmFunctionBlocker* fb, const cmListFileFunction& lff); /** @@ -782,10 +781,11 @@ public: void EnforceDirectoryLevelRules() const; - void AddEvaluationFile(const std::string& inputFile, - CM_AUTO_PTR<cmCompiledGeneratorExpression> outputName, - CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, - bool inputIsContent); + void AddEvaluationFile( + const std::string& inputFile, + std::unique_ptr<cmCompiledGeneratorExpression> outputName, + std::unique_ptr<cmCompiledGeneratorExpression> condition, + bool inputIsContent); std::vector<cmGeneratorExpressionEvaluationFile*> GetEvaluationFiles() const; std::vector<cmExportBuildFileGenerator*> GetExportBuildFileGenerators() @@ -809,17 +809,7 @@ protected: // libraries, classes, and executables mutable cmTargets Targets; std::map<std::string, std::string> AliasTargets; - std::vector<cmSourceFile*> SourceFiles; - // Because cmSourceFile names are compared in a fuzzy way (see - // cmSourceFileLocation::Match()) we can't have a straight mapping from - // filename to cmSourceFile. To make lookups more efficient we store the - // Name portion of the cmSourceFileLocation and then compare on the list of - // cmSourceFiles that might match that name. Note that on platforms which - // have a case-insensitive filesystem we store the key in all lowercase. - typedef std::unordered_set<cmSourceFile*> SourceFileSet; - typedef std::unordered_map<std::string, SourceFileSet> SourceFileMap; - SourceFileMap SourceFileSearchIndex; // Tests std::map<std::string, cmTest*> Tests; diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index ebc8e30..801f72a 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -3,6 +3,7 @@ #include "cmMakefileExecutableTargetGenerator.h" #include <algorithm> +#include <memory> // IWYU pragma: keep #include <sstream> #include <string> #include <vector> @@ -23,7 +24,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator( @@ -193,7 +193,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( new cmLinkLineDeviceComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -251,7 +251,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( launcher += " "; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Expand placeholders in the commands. @@ -448,7 +448,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) linkFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig)); { - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -538,7 +538,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -632,7 +632,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) launcher += " "; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Expand placeholders in the commands. diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 68d73d4..80c62d1 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -3,6 +3,7 @@ #include "cmMakefileLibraryTargetGenerator.h" #include <algorithm> +#include <memory> // IWYU pragma: keep #include <sstream> #include <vector> @@ -22,7 +23,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator( @@ -199,7 +199,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink) this->LocalGenerator->AddConfigVariableFlags( extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -248,7 +248,7 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink) this->LocalGenerator->AddConfigVariableFlags( extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -348,7 +348,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( std::string linkLibs; if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) { - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( new cmLinkLineDeviceComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -410,7 +410,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( launcher += " "; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Construct the main link rule and expand placeholders. @@ -754,7 +754,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( std::string linkLibs; if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) { - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -873,7 +873,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( launcher += " "; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Construct the main link rule and expand placeholders. rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index d0aad30..7db010c 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmMakefileTargetGenerator.h" +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <utility> @@ -27,7 +28,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target) @@ -134,7 +134,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() if (const char* additional_clean_files = this->Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES")) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(additional_clean_files); cmSystemTools::ExpandListArgument( @@ -434,7 +434,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( // Add flags from source file properties. if (const char* cflags = source.GetProperty("COMPILE_FLAGS")) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget); this->LocalGenerator->AppendFlags(flags, evaluatedFlags); @@ -570,7 +570,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( bool const lang_has_assembly = lang_has_preprocessor; bool const lang_can_export_cmds = lang_has_preprocessor; - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Construct the compile rules. diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index e0844e8..e0cc35a 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -6,6 +6,7 @@ #include <assert.h> #include <iterator> #include <map> +#include <memory> // IWYU pragma: keep #include <set> #include <sstream> @@ -29,7 +30,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" class cmCustomCommand; @@ -241,7 +241,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile) launcher += " "; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); // Rule for linking library/executable. @@ -365,7 +365,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) launcher += " "; } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); // Rule for linking library/executable. @@ -636,7 +636,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( new cmNinjaLinkLineDeviceComputer( this->GetLocalGenerator(), this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), @@ -839,7 +839,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL); - CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer( this->GetGlobalGenerator()->CreateLinkLineComputer( this->GetLocalGenerator(), this->GetLocalGenerator()->GetStateSnapshot().GetDirectory())); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index a464d6e..5805259 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -8,6 +8,7 @@ #include <assert.h> #include <iterator> #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <string.h> @@ -29,7 +30,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target) @@ -138,7 +138,7 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject( if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) { std::string config = this->LocalGenerator->GetConfigName(); cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget); this->LocalGenerator->AppendFlags(flags, evaluatedFlags); @@ -438,7 +438,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) : mf->GetSafeDefinition("CMAKE_CXX_COMPILER"); cldeps = "\""; cldeps += cmSystemTools::GetCMClDepsCommand(); - cldeps += "\" " + lang + " " + vars.Source + " \"$DEP_FILE\" $out \""; + cldeps += "\" " + lang + " " + vars.Source + " $DEP_FILE $out \""; cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"); cldeps += "\" \"" + cl + "\" "; } @@ -463,7 +463,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.Flags = flags.c_str(); vars.DependencyFile = depfile.c_str(); - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat( @@ -1077,7 +1077,7 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( cmSystemTools::ExpandListArgument(compileCmd, compileCmds); } - CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); for (std::string& i : compileCmds) { diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index d9b1fd3..5e89978 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -14,18 +14,22 @@ // - Static variables -const std::string genNameGen = "AutoGen"; -const std::string genNameMoc = "AutoMoc"; -const std::string genNameUic = "AutoUic"; -const std::string genNameRcc = "AutoRcc"; +std::string const genNameGen = "AutoGen"; +std::string const genNameMoc = "AutoMoc"; +std::string const genNameUic = "AutoUic"; +std::string const genNameRcc = "AutoRcc"; + +std::string const mcNameSingle = "SINGLE"; +std::string const mcNameWrap = "WRAP"; +std::string const mcNameFull = "FULL"; // - Static functions /// @brief Merges newOpts into baseOpts /// @arg valueOpts list of options that accept a value void MergeOptions(std::vector<std::string>& baseOpts, - const std::vector<std::string>& newOpts, - const std::vector<std::string>& valueOpts, bool isQt5) + std::vector<std::string> const& newOpts, + std::vector<std::string> const& valueOpts, bool isQt5) { typedef std::vector<std::string>::iterator Iter; typedef std::vector<std::string>::const_iterator CIter; @@ -40,7 +44,7 @@ void MergeOptions(std::vector<std::string>& baseOpts, std::vector<std::string> extraOpts; for (CIter fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd; ++fit) { - const std::string& newOpt = *fit; + std::string const& newOpt = *fit; Iter existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt); if (existIt != baseOpts.end()) { if (newOpt.size() >= 2) { @@ -87,7 +91,7 @@ static std::string utilStripCR(std::string const& line) /// @brief Reads the resource files list from from a .qrc file - Qt4 version /// @return True if the .qrc file was successfully parsed -static bool RccListInputsQt4(const std::string& fileName, +static bool RccListInputsQt4(std::string const& fileName, std::vector<std::string>& files, std::string* errorMessage) { @@ -140,8 +144,8 @@ static bool RccListInputsQt4(const std::string& fileName, /// @brief Reads the resource files list from from a .qrc file - Qt5 version /// @return True if the .qrc file was successfully parsed -static bool RccListInputsQt5(const std::string& rccCommand, - const std::string& fileName, +static bool RccListInputsQt5(std::string const& rccCommand, + std::string const& fileName, std::vector<std::string>& files, std::string* errorMessage) { @@ -244,29 +248,53 @@ static bool RccListInputsQt5(const std::string& rccCommand, // - Class definitions -const std::string cmQtAutoGen::listSep = "@LSEP@"; +std::string const cmQtAutoGen::listSep = "@LSEP@"; -const std::string& cmQtAutoGen::GeneratorName(GeneratorType type) +std::string const& cmQtAutoGen::GeneratorName(Generator type) { switch (type) { - case GeneratorType::GEN: + case Generator::GEN: return genNameGen; - case GeneratorType::MOC: + case Generator::MOC: return genNameMoc; - case GeneratorType::UIC: + case Generator::UIC: return genNameUic; - case GeneratorType::RCC: + case Generator::RCC: return genNameRcc; } return genNameGen; } -std::string cmQtAutoGen::GeneratorNameUpper(GeneratorType genType) +std::string cmQtAutoGen::GeneratorNameUpper(Generator genType) { return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType)); } -std::string cmQtAutoGen::Quoted(const std::string& text) +std::string const& cmQtAutoGen::MultiConfigName(MultiConfig config) +{ + switch (config) { + case MultiConfig::SINGLE: + return mcNameSingle; + case MultiConfig::WRAP: + return mcNameWrap; + case MultiConfig::FULL: + return mcNameFull; + } + return mcNameWrap; +} + +cmQtAutoGen::MultiConfig cmQtAutoGen::MultiConfigType(std::string const& name) +{ + if (name == mcNameSingle) { + return MultiConfig::SINGLE; + } + if (name == mcNameFull) { + return MultiConfig::FULL; + } + return MultiConfig::WRAP; +} + +std::string cmQtAutoGen::Quoted(std::string const& text) { static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a", "\b", "\\b", "\f", "\\f", "\n", "\\n", @@ -282,11 +310,28 @@ std::string cmQtAutoGen::Quoted(const std::string& text) return res; } +std::string cmQtAutoGen::AppendFilenameSuffix(std::string const& filename, + std::string const& suffix) +{ + std::string res; + auto pos = filename.rfind('.'); + if (pos != std::string::npos) { + const auto it_dot = filename.begin() + pos; + res.assign(filename.begin(), it_dot); + res.append(suffix); + res.append(it_dot, filename.end()); + } else { + res = filename; + res.append(suffix); + } + return res; +} + void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts, - const std::vector<std::string>& newOpts, + std::vector<std::string> const& newOpts, bool isQt5) { - static const std::vector<std::string> valueOpts = { + static std::vector<std::string> const valueOpts = { "tr", "translate", "postfix", "generator", "include", // Since Qt 5.3 "g" @@ -295,18 +340,18 @@ void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts, } void cmQtAutoGen::RccMergeOptions(std::vector<std::string>& baseOpts, - const std::vector<std::string>& newOpts, + std::vector<std::string> const& newOpts, bool isQt5) { - static const std::vector<std::string> valueOpts = { "name", "root", + static std::vector<std::string> const valueOpts = { "name", "root", "compress", "threshold" }; MergeOptions(baseOpts, newOpts, valueOpts, isQt5); } -bool cmQtAutoGen::RccListInputs(const std::string& qtMajorVersion, - const std::string& rccCommand, - const std::string& fileName, +bool cmQtAutoGen::RccListInputs(std::string const& qtMajorVersion, + std::string const& rccCommand, + std::string const& fileName, std::vector<std::string>& files, std::string* errorMessage) { diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h index 4cd5e32..acc092f 100644 --- a/Source/cmQtAutoGen.h +++ b/Source/cmQtAutoGen.h @@ -14,9 +14,9 @@ class cmQtAutoGen { public: - static const std::string listSep; + static std::string const listSep; - enum GeneratorType + enum Generator { GEN, // General MOC, @@ -24,32 +24,47 @@ public: RCC }; + enum MultiConfig + { + SINGLE, // Single configuration + WRAP, // Multi configuration using wrapper files + FULL // Full multi configuration using per config sources + }; + public: /// @brief Returns the generator name - static const std::string& GeneratorName(GeneratorType genType); + static std::string const& GeneratorName(Generator genType); /// @brief Returns the generator name in upper case - static std::string GeneratorNameUpper(GeneratorType genType); + static std::string GeneratorNameUpper(Generator genType); + + /// @brief Returns the multi configuration name string + static std::string const& MultiConfigName(MultiConfig config); + /// @brief Returns the multi configuration type + static MultiConfig MultiConfigType(std::string const& name); /// @brief Returns a the string escaped and enclosed in quotes - /// - static std::string Quoted(const std::string& text); + static std::string Quoted(std::string const& text); + + /// @brief Appends the suffix to the filename before the last dot + static std::string AppendFilenameSuffix(std::string const& filename, + std::string const& suffix); /// @brief Merges newOpts into baseOpts static void UicMergeOptions(std::vector<std::string>& baseOpts, - const std::vector<std::string>& newOpts, + std::vector<std::string> const& newOpts, bool isQt5); /// @brief Merges newOpts into baseOpts static void RccMergeOptions(std::vector<std::string>& baseOpts, - const std::vector<std::string>& newOpts, + std::vector<std::string> const& newOpts, bool isQt5); /// @brief Reads the resource files list from from a .qrc file /// @arg fileName Must be the absolute path of the .qrc file /// @return True if the rcc file was successfully parsed - static bool RccListInputs(const std::string& qtMajorVersion, - const std::string& rccCommand, - const std::string& fileName, + static bool RccListInputs(std::string const& qtMajorVersion, + std::string const& rccCommand, + std::string const& fileName, std::vector<std::string>& files, std::string* errorMessage = nullptr); }; diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 69f8b8f..c6f0a51 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -48,9 +48,26 @@ inline static std::string GetSafeProperty(cmSourceFile const* sf, return std::string(SafeString(sf->GetProperty(key))); } -inline static bool AutogenMultiConfig(cmGlobalGenerator* globalGen) +static cmQtAutoGen::MultiConfig AutogenMultiConfig( + cmGlobalGenerator* globalGen) { - return globalGen->IsMultiConfig(); + if (!globalGen->IsMultiConfig()) { + return cmQtAutoGen::SINGLE; + } + + // FIXME: Xcode does not support per-config sources, yet. + // (EXCLUDED_SOURCE_FILE_NAMES) + // if (globalGen->GetName().find("Xcode") != std::string::npos) { + // return cmQtAutoGen::FULL; + //} + + // FIXME: Visual Studio does not support per-config sources, yet. + // (EXCLUDED_SOURCE_FILE_NAMES) + // if (globalGen->GetName().find("Visual Studio") != std::string::npos) { + // return cmQtAutoGen::FULL; + //} + + return cmQtAutoGen::WRAP; } static std::string GetAutogenTargetName(cmGeneratorTarget const* target) @@ -100,7 +117,7 @@ std::string cmQtAutoGeneratorInitializer::GetQtMajorVersion( } std::string cmQtAutoGeneratorInitializer::GetQtMinorVersion( - cmGeneratorTarget const* target, const std::string& qtVersionMajor) + cmGeneratorTarget const* target, std::string const& qtVersionMajor) { cmMakefile* makefile = target->Target->GetMakefile(); std::string qtMinor; @@ -119,8 +136,8 @@ std::string cmQtAutoGeneratorInitializer::GetQtMinorVersion( return qtMinor; } -static bool QtVersionGreaterOrEqual(const std::string& major, - const std::string& minor, +static bool QtVersionGreaterOrEqual(std::string const& major, + std::string const& minor, unsigned long requestMajor, unsigned long requestMinor) { @@ -134,40 +151,17 @@ static bool QtVersionGreaterOrEqual(const std::string& major, return false; } -static std::vector<std::string> GetConfigurations( - cmMakefile* makefile, std::string* config = nullptr) -{ - std::vector<std::string> configs; - { - std::string cfg = makefile->GetConfigurations(configs); - if (config != nullptr) { - *config = cfg; - } - } - // Add empty configuration on demand - if (configs.empty()) { - configs.push_back(""); - } - return configs; -} - -static std::vector<std::string> GetConfigurationSuffixes(cmMakefile* makefile) +static void GetConfigs(cmMakefile* makefile, std::string& configDefault, + std::vector<std::string>& configsList) { - std::vector<std::string> suffixes; - if (AutogenMultiConfig(makefile->GetGlobalGenerator())) { - makefile->GetConfigurations(suffixes); - for (std::string& suffix : suffixes) { - suffix.insert(0, "_"); - } + configDefault = makefile->GetConfigurations(configsList); + if (configsList.empty()) { + configsList.push_back(""); } - if (suffixes.empty()) { - suffixes.push_back(""); - } - return suffixes; } static void AddDefinitionEscaped(cmMakefile* makefile, const char* key, - const std::string& value) + std::string const& value) { makefile->AddDefinition(key, cmOutputConverter::EscapeForCMake(value).c_str()); @@ -203,8 +197,8 @@ static void AddDefinitionEscaped( .c_str()); } -static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName, - cmQtAutoGen::GeneratorType genType) +static bool AddToSourceGroup(cmMakefile* makefile, std::string const& fileName, + cmQtAutoGen::Generator genType) { cmSourceGroup* sourceGroup = nullptr; // Acquire source group @@ -255,25 +249,54 @@ static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName, return true; } -static void AddCleanFile(cmMakefile* makefile, const std::string& fileName) +static void AddCleanFile(cmMakefile* makefile, std::string const& fileName) { makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fileName.c_str(), false); } -static void AddGeneratedSource(cmGeneratorTarget* target, - const std::string& filename, - cmQtAutoGen::GeneratorType genType) +static std::vector<std::string> AddGeneratedSource( + cmGeneratorTarget* target, std::string const& filename, + cmQtAutoGen::MultiConfig multiConfig, + const std::vector<std::string>& configsList, cmQtAutoGen::Generator genType) { - cmMakefile* makefile = target->Target->GetMakefile(); + std::vector<std::string> genFiles; + // Register source file in makefile and source group + if (multiConfig != cmQtAutoGen::FULL) { + genFiles.push_back(filename); + } else { + for (std::string const& cfg : configsList) { + genFiles.push_back( + cmQtAutoGen::AppendFilenameSuffix(filename, "_" + cfg)); + } + } { - cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); - gFile->SetProperty("GENERATED", "1"); - gFile->SetProperty("SKIP_AUTOGEN", "On"); + cmMakefile* makefile = target->Target->GetMakefile(); + for (std::string const& genFile : genFiles) { + { + cmSourceFile* gFile = makefile->GetOrCreateSource(genFile, true); + gFile->SetProperty("GENERATED", "1"); + gFile->SetProperty("SKIP_AUTOGEN", "On"); + } + AddToSourceGroup(makefile, genFile, genType); + } } - target->AddSource(filename); - AddToSourceGroup(makefile, filename, genType); + // Add source file to target + if (multiConfig != cmQtAutoGen::FULL) { + target->AddSource(filename); + } else { + for (std::string const& cfg : configsList) { + std::string src = "$<$<CONFIG:"; + src += cfg; + src += ">:"; + src += cmQtAutoGen::AppendFilenameSuffix(filename, "_" + cfg); + src += ">"; + target->AddSource(src); + } + } + + return genFiles; } struct cmQtAutoGenSetup @@ -295,8 +318,8 @@ static void SetupAcquireSkipFiles(cmQtAutoGenDigest const& digest, digest.Target->Makefile->GetSourceFiles(); for (cmSourceFile* sf : allSources) { // sf->GetExtension() is only valid after sf->GetFullPath() ... - const std::string& fPath = sf->GetFullPath(); - const cmSystemTools::FileFormat fileType = + std::string const& fPath = sf->GetFullPath(); + cmSystemTools::FileFormat const fileType = cmSystemTools::GetFileFormat(sf->GetExtension().c_str()); if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) && !(fileType == cmSystemTools::HEADER_FILE_FORMAT)) { @@ -308,7 +331,7 @@ static void SetupAcquireSkipFiles(cmQtAutoGenDigest const& digest, const bool uicSkip = digest.UicEnabled && (skipAll || sf->GetPropertyAsBool("SKIP_AUTOUIC")); if (mocSkip || uicSkip) { - const std::string absFile = cmSystemTools::GetRealPath(fPath); + std::string const absFile = cmSystemTools::GetRealPath(fPath); if (mocSkip) { setup.MocSkip.insert(absFile); } @@ -320,9 +343,9 @@ static void SetupAcquireSkipFiles(cmQtAutoGenDigest const& digest, } } -static void SetupAutoTargetMoc(const cmQtAutoGenDigest& digest, - std::string const& config, - std::vector<std::string> const& configs, +static void SetupAutoTargetMoc(cmQtAutoGenDigest const& digest, + std::string const& configDefault, + std::vector<std::string> const& configsList, cmQtAutoGenSetup& setup) { cmGeneratorTarget const* target = digest.Target; @@ -348,43 +371,42 @@ static void SetupAutoTargetMoc(const cmQtAutoGenDigest& digest, } // Moc includes and compile definitions { - auto GetCompileDefinitionsAndDirectories = [target, localGen]( - const std::string& cfg, std::string& incs, std::string& defs) { - { - std::vector<std::string> includeDirs; - // Get the include dirs for this target, without stripping the implicit - // include dirs off, see - // https://gitlab.kitware.com/cmake/cmake/issues/13667 - localGen->GetIncludeDirectories(includeDirs, target, "CXX", cfg, - false); - incs = cmJoin(includeDirs, ";"); - } - { - std::set<std::string> defines; - localGen->AddCompileDefinitions(defines, target, cfg, "CXX"); - defs += cmJoin(defines, ";"); - } + auto GetIncludeDirs = [target, + localGen](std::string const& cfg) -> std::string { + // Get the include dirs for this target, without stripping the implicit + // include dirs off, see + // https://gitlab.kitware.com/cmake/cmake/issues/13667 + std::vector<std::string> includeDirs; + localGen->GetIncludeDirectories(includeDirs, target, "CXX", cfg, false); + return cmJoin(includeDirs, ";"); + }; + auto GetCompileDefinitions = + [target, localGen](std::string const& cfg) -> std::string { + std::set<std::string> defines; + localGen->AddCompileDefinitions(defines, target, cfg, "CXX"); + return cmJoin(defines, ";"); }; - // Default settings - std::string incs; - std::string compileDefs; - GetCompileDefinitionsAndDirectories(config, incs, compileDefs); - AddDefinitionEscaped(makefile, "_moc_incs", incs); - AddDefinitionEscaped(makefile, "_moc_compile_defs", compileDefs); - - // Configuration specific settings - for (std::string const& cfg : configs) { - std::string configIncs; - std::string configCompileDefs; - GetCompileDefinitionsAndDirectories(cfg, configIncs, configCompileDefs); - if (configIncs != incs) { - setup.ConfigMocIncludes[cfg] = configIncs; + // Default configuration settings + std::string const includeDirs = GetIncludeDirs(configDefault); + std::string const compileDefs = GetCompileDefinitions(configDefault); + // Other configuration settings + for (std::string const& cfg : configsList) { + { + std::string const configIncludeDirs = GetIncludeDirs(cfg); + if (configIncludeDirs != includeDirs) { + setup.ConfigMocIncludes[cfg] = configIncludeDirs; + } } - if (configCompileDefs != compileDefs) { - setup.ConfigMocDefines[cfg] = configCompileDefs; + { + std::string const configCompileDefs = GetCompileDefinitions(cfg); + if (configCompileDefs != compileDefs) { + setup.ConfigMocDefines[cfg] = configCompileDefs; + } } } + AddDefinitionEscaped(makefile, "_moc_include_dirs", includeDirs); + AddDefinitionEscaped(makefile, "_moc_compile_defs", compileDefs); } // Moc executable @@ -419,7 +441,7 @@ static void SetupAutoTargetMoc(const cmQtAutoGenDigest& digest, } } -static void SetupAutoTargetUic(const cmQtAutoGenDigest& digest, +static void SetupAutoTargetUic(cmQtAutoGenDigest const& digest, std::string const& config, std::vector<std::string> const& configs, cmQtAutoGenSetup& setup) @@ -433,10 +455,10 @@ static void SetupAutoTargetUic(const cmQtAutoGenDigest& digest, { std::vector<std::string> uicSearchPaths; { - const std::string usp = GetSafeProperty(target, "AUTOUIC_SEARCH_PATHS"); + std::string const usp = GetSafeProperty(target, "AUTOUIC_SEARCH_PATHS"); if (!usp.empty()) { cmSystemTools::ExpandListArgument(usp, uicSearchPaths); - const std::string srcDir = makefile->GetCurrentSourceDirectory(); + std::string const srcDir = makefile->GetCurrentSourceDirectory(); for (std::string& path : uicSearchPaths) { path = cmSystemTools::CollapseFullPath(path, srcDir); } @@ -446,19 +468,19 @@ static void SetupAutoTargetUic(const cmQtAutoGenDigest& digest, } // Uic target options { - auto UicGetOpts = [target](const std::string& cfg) -> std::string { + auto UicGetOpts = [target](std::string const& cfg) -> std::string { std::vector<std::string> opts; target->GetAutoUicOptions(opts, cfg); return cmJoin(opts, ";"); }; // Default settings - const std::string uicOpts = UicGetOpts(config); + std::string const uicOpts = UicGetOpts(config); AddDefinitionEscaped(makefile, "_uic_target_options", uicOpts); // Configuration specific settings for (std::string const& cfg : configs) { - const std::string configUicOpts = UicGetOpts(cfg); + std::string const configUicOpts = UicGetOpts(cfg); if (configUicOpts != uicOpts) { setup.ConfigUicOptions[cfg] = configUicOpts; } @@ -469,16 +491,16 @@ static void SetupAutoTargetUic(const cmQtAutoGenDigest& digest, std::vector<std::string> uiFileFiles; std::vector<std::vector<std::string>> uiFileOptions; { - const std::string uiExt = "ui"; + std::string const uiExt = "ui"; const std::vector<cmSourceFile*>& srcFiles = makefile->GetSourceFiles(); for (cmSourceFile* sf : srcFiles) { // sf->GetExtension() is only valid after sf->GetFullPath() ... - const std::string& fPath = sf->GetFullPath(); + std::string const& fPath = sf->GetFullPath(); if (sf->GetExtension() == uiExt) { // Check if the files has uic options - const std::string uicOpts = GetSafeProperty(sf, "AUTOUIC_OPTIONS"); + std::string const uicOpts = GetSafeProperty(sf, "AUTOUIC_OPTIONS"); if (!uicOpts.empty()) { - const std::string absFile = cmSystemTools::GetRealPath(fPath); + std::string const absFile = cmSystemTools::GetRealPath(fPath); // Check if file isn't skipped if (setup.UicSkip.count(absFile) == 0) { uiFileFiles.push_back(absFile); @@ -528,7 +550,7 @@ static void SetupAutoTargetUic(const cmQtAutoGenDigest& digest, } static std::string RccGetExecutable(cmGeneratorTarget const* target, - const std::string& qtMajorVersion) + std::string const& qtMajorVersion) { std::string rccExec; std::string err; @@ -559,7 +581,7 @@ static std::string RccGetExecutable(cmGeneratorTarget const* target, return rccExec; } -static void SetupAutoTargetRcc(const cmQtAutoGenDigest& digest) +static void SetupAutoTargetRcc(cmQtAutoGenDigest const& digest) { std::vector<std::string> rccFiles; std::vector<std::string> rccBuilds; @@ -590,26 +612,36 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( cmLocalGenerator* localGen = target->GetLocalGenerator(); cmGlobalGenerator* globalGen = localGen->GetGlobalGenerator(); - // Create a custom target for running generators at buildtime - const bool multiConfig = AutogenMultiConfig(globalGen); - const std::string autogenTargetName = GetAutogenTargetName(target); - const std::string autogenBuildDir = GetAutogenTargetBuildDir(target); - const std::string workingDirectory = + std::string const autogenTargetName = GetAutogenTargetName(target); + std::string const autogenInfoDir = GetAutogenTargetFilesDir(target); + std::string const autogenBuildDir = GetAutogenTargetBuildDir(target); + std::string const workingDirectory = cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory()); - const std::vector<std::string> suffixes = GetConfigurationSuffixes(makefile); + + cmQtAutoGen::MultiConfig const multiConfig = AutogenMultiConfig(globalGen); + std::string configDefault; + std::vector<std::string> configsList; + GetConfigs(makefile, configDefault, configsList); + std::set<std::string> autogenDependFiles; std::set<std::string> autogenDependTargets; std::vector<std::string> autogenProvides; // Remove build directories on cleanup AddCleanFile(makefile, autogenBuildDir); - // Remove old settings on cleanup { - std::string base = GetAutogenTargetFilesDir(target); - base += "/AutogenOldSettings"; - for (std::string const& suffix : suffixes) { - AddCleanFile(makefile, (base + suffix).append(".cmake")); + std::string base = autogenInfoDir + "/AutogenOldSettings"; + if (multiConfig == cmQtAutoGen::SINGLE) { + AddCleanFile(makefile, base.append(".cmake")); + } else { + for (std::string const& cfg : configsList) { + std::string filename = base; + filename += "_"; + filename += cfg; + filename += ".cmake"; + AddCleanFile(makefile, filename); + } } } @@ -620,7 +652,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( currentLine.push_back(cmSystemTools::GetCMakeCommand()); currentLine.push_back("-E"); currentLine.push_back("cmake_autogen"); - currentLine.push_back(GetAutogenTargetFilesDir(target)); + currentLine.push_back(autogenInfoDir); currentLine.push_back("$<CONFIGURATION>"); commandLines.push_back(currentLine); } @@ -630,38 +662,42 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( { std::vector<std::string> toolNames; if (digest.MocEnabled) { - toolNames.push_back("MOC"); + toolNames.emplace_back("MOC"); } if (digest.UicEnabled) { - toolNames.push_back("UIC"); + toolNames.emplace_back("UIC"); } if (digest.RccEnabled) { - toolNames.push_back("RCC"); + toolNames.emplace_back("RCC"); } - std::string tools = toolNames[0]; + std::string tools = toolNames.front(); toolNames.erase(toolNames.begin()); - while (toolNames.size() > 1) { - tools += ", " + toolNames[0]; - toolNames.erase(toolNames.begin()); - } - if (toolNames.size() == 1) { - tools += " and " + toolNames[0]; + if (!toolNames.empty()) { + while (toolNames.size() > 1) { + tools += ", "; + tools += toolNames.front(); + toolNames.erase(toolNames.begin()); + } + tools += " and " + toolNames.front(); } autogenComment = "Automatic " + tools + " for target " + target->GetName(); } // Add moc compilation to generated files list if (digest.MocEnabled) { - const std::string mocsComp = autogenBuildDir + "/mocs_compilation.cpp"; - AddGeneratedSource(target, mocsComp, cmQtAutoGen::MOC); - autogenProvides.push_back(mocsComp); + std::string const mocsComp = autogenBuildDir + "/mocs_compilation.cpp"; + auto files = AddGeneratedSource(target, mocsComp, multiConfig, configsList, + cmQtAutoGen::MOC); + for (std::string& file : files) { + autogenProvides.push_back(std::move(file)); + } } // Add autogen includes directory to the origin target INCLUDE_DIRECTORIES if (digest.MocEnabled || digest.UicEnabled) { std::string includeDir = autogenBuildDir + "/include"; - if (multiConfig) { + if (multiConfig != cmQtAutoGen::SINGLE) { includeDir += "_$<CONFIG>"; } target->AddIncludeDirectory(includeDir, true); @@ -671,7 +707,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( std::vector<std::string> generatedSources; std::vector<std::string> generatedHeaders; { - const std::string qrcExt = "qrc"; + std::string const qrcExt = "qrc"; std::vector<cmSourceFile*> srcFiles; target->GetConfigCommonSourceFiles(srcFiles); for (cmSourceFile* sf : srcFiles) { @@ -679,15 +715,15 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( continue; } // sf->GetExtension() is only valid after sf->GetFullPath() ... - const std::string& fPath = sf->GetFullPath(); - const std::string& ext = sf->GetExtension(); + std::string const& fPath = sf->GetFullPath(); + std::string const& ext = sf->GetExtension(); // Register generated files that will be scanned by moc or uic if (digest.MocEnabled || digest.UicEnabled) { - const cmSystemTools::FileFormat fileType = + cmSystemTools::FileFormat const fileType = cmSystemTools::GetFileFormat(ext.c_str()); if ((fileType == cmSystemTools::CXX_FILE_FORMAT) || (fileType == cmSystemTools::HEADER_FILE_FORMAT)) { - const std::string absPath = cmSystemTools::GetRealPath(fPath); + std::string const absPath = cmSystemTools::GetRealPath(fPath); if ((digest.MocEnabled && !sf->GetPropertyAsBool("SKIP_AUTOMOC")) || (digest.UicEnabled && !sf->GetPropertyAsBool("SKIP_AUTOUIC"))) { // Register source @@ -720,7 +756,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( qrcDigest.Generated = sf->GetPropertyAsBool("GENERATED"); // RCC options { - const std::string opts = GetSafeProperty(sf, "AUTORCC_OPTIONS"); + std::string const opts = GetSafeProperty(sf, "AUTORCC_OPTIONS"); if (!opts.empty()) { cmSystemTools::ExpandListArgument(opts, qrcDigest.Options); } @@ -741,7 +777,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Check status of policy CMP0071 bool policyAccept = false; bool policyWarn = false; - const cmPolicies::PolicyStatus CMP0071_status = + cmPolicies::PolicyStatus const CMP0071_status = target->Makefile->GetPolicyStatus(cmPolicies::CMP0071); switch (CMP0071_status) { case cmPolicies::WARN: @@ -774,27 +810,35 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( msg += cmPolicies::GetPolicyWarning(cmPolicies::CMP0071); msg += "\n"; std::string tools; - if (digest.MocEnabled) { - tools += "AUTOMOC"; - } - if (digest.UicEnabled) { - if (!tools.empty()) { - tools += ","; - } - tools += "AUTOUIC"; + std::string property; + if (digest.MocEnabled && digest.UicEnabled) { + tools = "AUTOMOC and AUTOUIC"; + property = "SKIP_AUTOGEN"; + } else if (digest.MocEnabled) { + tools = "AUTOMOC"; + property = "SKIP_AUTOMOC"; + } else if (digest.UicEnabled) { + tools = "AUTOUIC"; + property = "SKIP_AUTOUIC"; } - if (!generatedHeaders.empty()) { - msg.append(tools).append(": Ignoring GENERATED header file(s):\n"); - for (const std::string& absFile : generatedHeaders) { - msg.append(" ").append(cmQtAutoGen::Quoted(absFile)).append("\n"); - } + msg += "For compatibility, CMake is excluding the GENERATED source " + "file(s):\n"; + for (const std::string& absFile : generatedHeaders) { + msg.append(" ").append(cmQtAutoGen::Quoted(absFile)).append("\n"); } - if (!generatedSources.empty()) { - msg.append(tools).append(": Ignoring GENERATED source file(s):\n"); - for (const std::string& absFile : generatedSources) { - msg.append(" ").append(cmQtAutoGen::Quoted(absFile)).append("\n"); - } + for (const std::string& absFile : generatedSources) { + msg.append(" ").append(cmQtAutoGen::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(cmake::AUTHOR_WARNING, msg); } } @@ -806,7 +850,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Process qrc files if (!digest.Qrcs.empty()) { const bool QtV5 = (digest.QtVersionMajor == "5"); - const std::string rcc = RccGetExecutable(target, digest.QtVersionMajor); + std::string const rcc = RccGetExecutable(target, digest.QtVersionMajor); // Target rcc options std::vector<std::string> optionsTarget; cmSystemTools::ExpandListArgument( @@ -825,7 +869,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } // Path checksum { - const cmFilePathChecksum fpathCheckSum(makefile); + cmFilePathChecksum const fpathCheckSum(makefile); for (cmQtAutoGenDigestQrc& qrcDigest : digest.Qrcs) { qrcDigest.PathChecksum = fpathCheckSum.getPart(qrcDigest.QrcFile); // RCC output file name @@ -861,8 +905,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } for (cmQtAutoGenDigestQrc& qrcDigest : digest.Qrcs) { // Register file at target - AddGeneratedSource(target, qrcDigest.RccFile, cmQtAutoGen::RCC); - autogenProvides.push_back(qrcDigest.RccFile); + { + auto files = AddGeneratedSource(target, qrcDigest.RccFile, multiConfig, + configsList, cmQtAutoGen::RCC); + for (std::string& file : files) { + autogenProvides.push_back(std::move(file)); + } + } // Dependencies if (qrcDigest.Generated) { // Add the GENERATED .qrc file to the dependencies @@ -889,7 +938,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Add user defined autogen target dependencies { - const std::string deps = GetSafeProperty(target, "AUTOGEN_TARGET_DEPENDS"); + std::string const deps = GetSafeProperty(target, "AUTOGEN_TARGET_DEPENDS"); if (!deps.empty()) { std::vector<std::string> extraDeps; cmSystemTools::ExpandListArgument(deps, extraDeps); @@ -924,7 +973,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Create the autogen target/command if (usePRE_BUILD) { // Add additional autogen target dependencies to origin target - for (const std::string& depTarget : autogenDependTargets) { + for (std::string const& depTarget : autogenDependTargets) { target->Target->AddUtility(depTarget, makefile); } @@ -944,7 +993,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } else { // Add utility target dependencies to the autogen target dependencies - for (const std::string& depTarget : target->Target->GetUtilities()) { + for (std::string const& depTarget : target->Target->GetUtilities()) { autogenDependTargets.insert(depTarget); } // Add link library target dependencies to the autogen target dependencies @@ -967,7 +1016,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( new cmGeneratorTarget(autogenTarget, localGen)); // Add additional autogen target dependencies to autogen target - for (const std::string& depTarget : autogenDependTargets) { + for (std::string const& depTarget : autogenDependTargets) { autogenTarget->AddUtility(depTarget, makefile); } @@ -994,45 +1043,51 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( - const cmQtAutoGenDigest& digest) + cmQtAutoGenDigest const& digest) { cmGeneratorTarget const* target = digest.Target; cmMakefile* makefile = target->Target->GetMakefile(); + cmQtAutoGen::MultiConfig const multiConfig = + AutogenMultiConfig(target->GetGlobalGenerator()); // forget the variables added here afterwards again: cmMakefile::ScopePushPop varScope(makefile); static_cast<void>(varScope); - // Get configurations - std::string config; - const std::vector<std::string> configs(GetConfigurations(makefile, &config)); - - // Configuration suffixes - std::map<std::string, std::string> configSuffix; - if (AutogenMultiConfig(target->GetGlobalGenerator())) { - for (std::string const& cfg : configs) { - configSuffix[cfg] = "_" + cfg; + // Configurations + std::string configDefault; + std::vector<std::string> configsList; + std::map<std::string, std::string> configSuffixes; + { + configDefault = makefile->GetConfigurations(configsList); + if (configsList.empty()) { + configsList.push_back(""); } } + for (std::string const& cfg : configsList) { + configSuffixes[cfg] = "_" + cfg; + } // Configurations settings buffers cmQtAutoGenSetup setup; // Basic setup + AddDefinitionEscaped(makefile, "_multi_config", + cmQtAutoGen::MultiConfigName(multiConfig)); AddDefinitionEscaped(makefile, "_build_dir", GetAutogenTargetBuildDir(target)); - AddDefinitionEscaped(makefile, "_qt_version_major", digest.QtVersionMajor); - AddDefinitionEscaped(makefile, "_qt_version_minor", digest.QtVersionMinor); AddDefinitionEscaped(makefile, "_sources", digest.Sources); AddDefinitionEscaped(makefile, "_headers", digest.Headers); + AddDefinitionEscaped(makefile, "_qt_version_major", digest.QtVersionMajor); + AddDefinitionEscaped(makefile, "_qt_version_minor", digest.QtVersionMinor); { if (digest.MocEnabled || digest.UicEnabled) { SetupAcquireSkipFiles(digest, setup); if (digest.MocEnabled) { - SetupAutoTargetMoc(digest, config, configs, setup); + SetupAutoTargetMoc(digest, configDefault, configsList, setup); } if (digest.UicEnabled) { - SetupAutoTargetUic(digest, config, configs, setup); + SetupAutoTargetUic(digest, configDefault, configsList, setup); } } if (digest.RccEnabled) { @@ -1041,17 +1096,23 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( } // Generate info file - std::string infoFile = GetAutogenTargetFilesDir(target); - infoFile += "/AutogenInfo.cmake"; { - std::string inf = cmSystemTools::GetCMakeRoot(); - inf += "/Modules/AutogenInfo.cmake.in"; - makefile->ConfigureFile(inf.c_str(), infoFile.c_str(), false, true, false); - } + std::string const infoDir = GetAutogenTargetFilesDir(target); + if (!cmSystemTools::MakeDirectory(infoDir)) { + std::string emsg = ("Could not create directory: "); + emsg += cmQtAutoGen::Quoted(infoDir); + cmSystemTools::Error(emsg.c_str()); + } + std::string const infoFile = infoDir + "/AutogenInfo.cmake"; + { + std::string infoFileIn = cmSystemTools::GetCMakeRoot(); + infoFileIn += "/Modules/AutogenInfo.cmake.in"; + makefile->ConfigureFile(infoFileIn.c_str(), infoFile.c_str(), false, + true, false); + } - // Append custom definitions to info file on demand - if (!configSuffix.empty() || !setup.ConfigMocDefines.empty() || - !setup.ConfigMocIncludes.empty() || !setup.ConfigUicOptions.empty()) { + // Append custom definitions to info file + // -------------------------------------- // Ensure we have write permission in case .in was read-only. mode_t perm = 0; @@ -1069,14 +1130,14 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( cmsys::ofstream ofs(infoFile.c_str(), std::ios::app); if (ofs) { auto OfsWriteMap = [&ofs]( - const char* key, const std::map<std::string, std::string>& map) { + const char* key, std::map<std::string, std::string> const& map) { for (auto const& item : map) { ofs << "set(" << key << "_" << item.first << " " << cmOutputConverter::EscapeForCMake(item.second) << ")\n"; } }; - ofs << "# Configuration specific options\n"; - OfsWriteMap("AM_CONFIG_SUFFIX", configSuffix); + ofs << "# Configurations options\n"; + OfsWriteMap("AM_CONFIG_SUFFIX", configSuffixes); OfsWriteMap("AM_MOC_DEFINITIONS", setup.ConfigMocDefines); OfsWriteMap("AM_MOC_INCLUDES", setup.ConfigMocIncludes); OfsWriteMap("AM_UIC_TARGET_OPTIONS", setup.ConfigUicOptions); diff --git a/Source/cmQtAutoGeneratorInitializer.h b/Source/cmQtAutoGeneratorInitializer.h index 1264ca5..b8a5ae4 100644 --- a/Source/cmQtAutoGeneratorInitializer.h +++ b/Source/cmQtAutoGeneratorInitializer.h @@ -15,7 +15,7 @@ class cmQtAutoGeneratorInitializer public: static std::string GetQtMajorVersion(cmGeneratorTarget const* target); static std::string GetQtMinorVersion(cmGeneratorTarget const* target, - const std::string& qtVersionMajor); + std::string const& qtVersionMajor); static void InitializeAutogenTarget(cmQtAutoGenDigest& digest); static void SetupAutoGenerateTarget(cmQtAutoGenDigest const& digest); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index e8a9006..f13312f 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -131,7 +131,8 @@ static bool ListContains(std::vector<std::string> const& list, // -- Class methods cmQtAutoGenerators::cmQtAutoGenerators() - : IncludeProjectDirsBefore(false) + : MultiConfig(cmQtAutoGen::WRAP) + , IncludeProjectDirsBefore(false) , Verbose(cmSystemTools::HasEnv("VERBOSE")) , ColorOutput(true) , MocSettingsChanged(false) @@ -148,12 +149,6 @@ cmQtAutoGenerators::cmQtAutoGenerators() } } - // Moc macro filters - this->MocMacroFilters.emplace_back( - "Q_OBJECT", "[\n][ \t]*{?[ \t]*Q_OBJECT[^a-zA-Z0-9_]"); - this->MocMacroFilters.emplace_back( - "Q_GADGET", "[\n][ \t]*{?[ \t]*Q_GADGET[^a-zA-Z0-9_]"); - // Precompile regular expressions this->MocRegExpInclude.compile( "[\n][ \t]*#[ \t]*include[ \t]+" @@ -196,6 +191,9 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, std::string const& targetDirectory, std::string const& config) { + // -- Meta + this->HeaderExtensions = makefile->GetCMakeInstance()->GetHeaderExtensions(); + // Utility lambdas auto InfoGet = [makefile](const char* key) { return makefile->GetSafeDefinition(key); @@ -239,10 +237,8 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, const char* valueConf = nullptr; { std::string keyConf = key; - if (!config.empty()) { - keyConf += '_'; - keyConf += config; - } + keyConf += '_'; + keyConf += config; valueConf = makefile->GetDefinition(keyConf); } if (valueConf == nullptr) { @@ -257,10 +253,10 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, return list; }; + // -- Read info file this->InfoFile = cmSystemTools::CollapseFullPath(targetDirectory); cmSystemTools::ConvertToUnixSlashes(this->InfoFile); this->InfoFile += "/AutogenInfo.cmake"; - if (!makefile->ReadListFile(this->InfoFile.c_str())) { this->LogFileError(cmQtAutoGen::GEN, this->InfoFile, "File processing failed"); @@ -268,16 +264,11 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, } // -- Meta - this->HeaderExtensions = makefile->GetCMakeInstance()->GetHeaderExtensions(); + this->MultiConfig = cmQtAutoGen::MultiConfigType(InfoGet("AM_MULTI_CONFIG")); this->ConfigSuffix = InfoGetConfig("AM_CONFIG_SUFFIX"); - - // - Old settings file - { - this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory); - cmSystemTools::ConvertToUnixSlashes(this->SettingsFile); - this->SettingsFile += "/AutogenOldSettings"; - this->SettingsFile += this->ConfigSuffix; - this->SettingsFile += ".cmake"; + if (this->ConfigSuffix.empty()) { + this->ConfigSuffix = "_"; + this->ConfigSuffix += config; } // - Files and directories @@ -329,7 +320,7 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, InfoGetList("AM_MOC_MACRO_NAMES"); for (std::string const& item : MocMacroNames) { this->MocMacroFilters.emplace_back( - item, ("[^a-zA-Z0-9_]" + item).append("[^a-zA-Z0-9_]")); + item, ("[\n][ \t]*{?[ \t]*" + item).append("[^a-zA-Z0-9_]")); } } { @@ -499,19 +490,28 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, // include directory this->AutogenIncludeDir = "include"; - this->AutogenIncludeDir += this->ConfigSuffix; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + this->AutogenIncludeDir += this->ConfigSuffix; + } this->AutogenIncludeDir += "/"; + // Moc variables if (this->MocEnabled()) { // Mocs compilation file - this->MocCompFileRel = "mocs_compilation.cpp"; + this->MocCompFileRel = "mocs_compilation"; + if (this->MultiConfig == cmQtAutoGen::FULL) { + this->MocCompFileRel += this->ConfigSuffix; + } + this->MocCompFileRel += ".cpp"; this->MocCompFileAbs = cmSystemTools::CollapseCombinedPath( this->AutogenBuildDir, this->MocCompFileRel); // Moc predefs file if (!this->MocPredefsCmd.empty()) { this->MocPredefsFileRel = "moc_predefs"; - this->MocPredefsFileRel += this->ConfigSuffix; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + this->MocPredefsFileRel += this->ConfigSuffix; + } this->MocPredefsFileRel += ".h"; this->MocPredefsFileAbs = cmSystemTools::CollapseCombinedPath( this->AutogenBuildDir, this->MocPredefsFileRel); @@ -585,6 +585,17 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, } } + // - Old settings file + { + this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory); + cmSystemTools::ConvertToUnixSlashes(this->SettingsFile); + this->SettingsFile += "/AutogenOldSettings"; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + this->SettingsFile += this->ConfigSuffix; + } + this->SettingsFile += ".cmake"; + } + return true; } @@ -1299,18 +1310,18 @@ void cmQtAutoGenerators::MocParseHeaderContent(std::string const& absFilename, }); if (fit == this->MocJobsIncluded.cend()) { if (this->MocRequired(contentText)) { - static std::string const prefix = "moc_"; - static std::string const suffix = this->ConfigSuffix + ".cpp"; - auto job = cm::make_unique<MocJobAuto>(); job->SourceFile = absFilename; { std::string& bld = job->BuildFileRel; bld = this->FilePathChecksum.getPart(absFilename); - bld += "/"; - bld += prefix; + bld += '/'; + bld += "moc_"; bld += cmSystemTools::GetFilenameWithoutLastExtension(absFilename); - bld += suffix; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + bld += this->ConfigSuffix; + } + bld += ".cpp"; } this->MocFindDepends(absFilename, contentText, job->Depends); this->MocJobsAuto.push_back(std::move(job)); @@ -1437,9 +1448,12 @@ bool cmQtAutoGenerators::MocGenerateAll() // Compose mocs compilation file content { - std::string mocs = "/* This file is autogenerated, do not edit*/\n"; + std::string mocs = + "// This file is autogenerated. Changes will be overwritten.\n"; if (this->MocJobsAuto.empty()) { - // Dummy content + // Placeholder content + mocs += + "// No files found that require moc or the moc files are included\n"; mocs += "enum some_compilers { need_more_than_nothing };\n"; } else { // Valid content @@ -1917,14 +1931,11 @@ bool cmQtAutoGenerators::RccGenerateFile(const RccJob& rccJob) bool rccGenerated = false; std::string rccFileAbs; - if (this->ConfigSuffix.empty()) { + if (this->MultiConfig == cmQtAutoGen::SINGLE) { rccFileAbs = rccJob.RccFile; } else { - rccFileAbs = SubDirPrefix(rccJob.RccFile); - rccFileAbs += - cmSystemTools::GetFilenameWithoutLastExtension(rccJob.RccFile); - rccFileAbs += this->ConfigSuffix; - rccFileAbs += cmSystemTools::GetFilenameLastExtension(rccJob.RccFile); + rccFileAbs = + cmQtAutoGen::AppendFilenameSuffix(rccJob.RccFile, this->ConfigSuffix); } std::string const rccFileRel = cmSystemTools::RelativePath( this->AutogenBuildDir.c_str(), rccFileAbs.c_str()); @@ -2064,15 +2075,16 @@ bool cmQtAutoGenerators::RccGenerateFile(const RccJob& rccJob) success = false; } } - // For a multi configuration generator generate a wrapper file - if (success && !this->ConfigSuffix.empty()) { + + // Generate a wrapper source file on demand + if (success && (this->MultiConfig == cmQtAutoGen::WRAP)) { // Wrapper file name std::string const& wrapperFileAbs = rccJob.RccFile; std::string const wrapperFileRel = cmSystemTools::RelativePath( this->AutogenBuildDir.c_str(), wrapperFileAbs.c_str()); // Wrapper file content std::string content = "// This is an autogenerated configuration " - "wrapper file. Do not edit.\n" + "wrapper file. Changes will be overwritten.\n" "#include \""; content += cmSystemTools::GetFilenameName(rccFileRel); content += "\"\n"; @@ -2107,7 +2119,7 @@ void cmQtAutoGenerators::LogBold(std::string const& message) const message.c_str(), true, this->ColorOutput); } -void cmQtAutoGenerators::LogInfo(cmQtAutoGen::GeneratorType genType, +void cmQtAutoGenerators::LogInfo(cmQtAutoGen::Generator genType, std::string const& message) const { std::string msg = cmQtAutoGen::GeneratorName(genType); @@ -2119,7 +2131,7 @@ void cmQtAutoGenerators::LogInfo(cmQtAutoGen::GeneratorType genType, cmSystemTools::Stdout(msg.c_str(), msg.size()); } -void cmQtAutoGenerators::LogWarning(cmQtAutoGen::GeneratorType genType, +void cmQtAutoGenerators::LogWarning(cmQtAutoGen::Generator genType, std::string const& message) const { std::string msg = cmQtAutoGen::GeneratorName(genType); @@ -2140,7 +2152,7 @@ void cmQtAutoGenerators::LogWarning(cmQtAutoGen::GeneratorType genType, cmSystemTools::Stdout(msg.c_str(), msg.size()); } -void cmQtAutoGenerators::LogFileWarning(cmQtAutoGen::GeneratorType genType, +void cmQtAutoGenerators::LogFileWarning(cmQtAutoGen::Generator genType, std::string const& filename, std::string const& message) const { @@ -2152,7 +2164,7 @@ void cmQtAutoGenerators::LogFileWarning(cmQtAutoGen::GeneratorType genType, this->LogWarning(genType, msg); } -void cmQtAutoGenerators::LogError(cmQtAutoGen::GeneratorType genType, +void cmQtAutoGenerators::LogError(cmQtAutoGen::Generator genType, std::string const& message) const { std::string msg; @@ -2167,7 +2179,7 @@ void cmQtAutoGenerators::LogError(cmQtAutoGen::GeneratorType genType, cmSystemTools::Stderr(msg.c_str(), msg.size()); } -void cmQtAutoGenerators::LogFileError(cmQtAutoGen::GeneratorType genType, +void cmQtAutoGenerators::LogFileError(cmQtAutoGen::Generator genType, std::string const& filename, std::string const& message) const { @@ -2180,7 +2192,7 @@ void cmQtAutoGenerators::LogFileError(cmQtAutoGen::GeneratorType genType, } void cmQtAutoGenerators::LogCommandError( - cmQtAutoGen::GeneratorType genType, std::string const& message, + cmQtAutoGen::Generator genType, std::string const& message, std::vector<std::string> const& command, std::string const& output) const { std::string msg; @@ -2210,8 +2222,8 @@ void cmQtAutoGenerators::LogCommandError( * @brief Generates the parent directory of the given file on demand * @return True on success */ -bool cmQtAutoGenerators::MakeParentDirectory( - cmQtAutoGen::GeneratorType genType, std::string const& filename) const +bool cmQtAutoGenerators::MakeParentDirectory(cmQtAutoGen::Generator genType, + std::string const& filename) const { bool success = true; std::string const dirName = cmSystemTools::GetFilenamePath(filename); @@ -2238,7 +2250,7 @@ bool cmQtAutoGenerators::FileDiffers(std::string const& filename, return differs; } -bool cmQtAutoGenerators::FileWrite(cmQtAutoGen::GeneratorType genType, +bool cmQtAutoGenerators::FileWrite(cmQtAutoGen::Generator genType, std::string const& filename, std::string const& content) { diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 0b502de..a7bb538 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -153,38 +153,39 @@ private: // -- Log info void LogBold(std::string const& message) const; - void LogInfo(cmQtAutoGen::GeneratorType genType, + void LogInfo(cmQtAutoGen::Generator genType, std::string const& message) const; // -- Log warning - void LogWarning(cmQtAutoGen::GeneratorType genType, + void LogWarning(cmQtAutoGen::Generator genType, std::string const& message) const; - void LogFileWarning(cmQtAutoGen::GeneratorType genType, + void LogFileWarning(cmQtAutoGen::Generator genType, std::string const& filename, std::string const& message) const; // -- Log error - void LogError(cmQtAutoGen::GeneratorType genType, + void LogError(cmQtAutoGen::Generator genType, std::string const& message) const; - void LogFileError(cmQtAutoGen::GeneratorType genType, + void LogFileError(cmQtAutoGen::Generator genType, std::string const& filename, std::string const& message) const; - void LogCommandError(cmQtAutoGen::GeneratorType genType, + void LogCommandError(cmQtAutoGen::Generator genType, std::string const& message, std::vector<std::string> const& command, std::string const& output) const; // -- Utility - bool MakeParentDirectory(cmQtAutoGen::GeneratorType genType, + bool MakeParentDirectory(cmQtAutoGen::Generator genType, std::string const& filename) const; bool FileDiffers(std::string const& filename, std::string const& content); - bool FileWrite(cmQtAutoGen::GeneratorType genType, - std::string const& filename, std::string const& content); + bool FileWrite(cmQtAutoGen::Generator genType, std::string const& filename, + std::string const& content); bool FindHeader(std::string& header, std::string const& testBasePath) const; bool RunCommand(std::vector<std::string> const& command, std::string& output) const; // -- Meta - std::string ConfigSuffix; std::string InfoFile; + std::string ConfigSuffix; + cmQtAutoGen::MultiConfig MultiConfig; // -- Settings bool IncludeProjectDirsBefore; bool Verbose; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 1b47608..e835b7a 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -602,11 +602,12 @@ bool LanguageData::operator==(const LanguageData& other) const void LanguageData::SetDefines(const std::set<std::string>& defines) { std::vector<std::string> result; + result.reserve(defines.size()); for (std::string const& i : defines) { result.push_back(i); } std::sort(result.begin(), result.end()); - Defines = result; + Defines = std::move(result); } namespace std { diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h index fb5b330..467682d 100644 --- a/Source/cmSourceFileLocation.h +++ b/Source/cmSourceFileLocation.h @@ -90,8 +90,7 @@ private: void Update(cmSourceFileLocation const& loc); void UpdateExtension(const std::string& name); - cmSourceFileLocation& operator=(const cmSourceFileLocation& loc) - CM_EQ_DELETE; + cmSourceFileLocation& operator=(const cmSourceFileLocation& loc) = delete; }; #endif diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 5aa8e5b..85e6366 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -442,6 +442,7 @@ const char* cmStateDirectory::GetProperty(const std::string& prop, std::vector<std::string> child_dirs; std::vector<cmStateSnapshot> const& children = this->DirectoryState->Children; + child_dirs.reserve(children.size()); for (cmStateSnapshot const& ci : children) { child_dirs.push_back(ci.GetDirectory().GetCurrentSource()); } diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 3b6a7ee..55af078 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -4,6 +4,7 @@ #include "cmsys/RegularExpression.hxx" #include <ctype.h> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -15,7 +16,6 @@ #include "cmSystemTools.h" #include "cmTimestamp.h" #include "cmUuid.h" -#include "cm_auto_ptr.hxx" class cmExecutionStatus; @@ -108,8 +108,8 @@ bool cmStringCommand::HandleHashCommand(std::vector<std::string> const& args) return false; } - CM_AUTO_PTR<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); - if (hash.get()) { + std::unique_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); + if (hash) { std::string out = hash->HashString(args[2]); this->Makefile->AddDefinition(args[1], out.c_str()); return true; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 4fd10a4..63c1452 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -700,6 +700,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, double timeout, Encoding encoding) { std::vector<const char*> argv; + argv.reserve(command.size() + 1); for (std::string const& cmd : command) { argv.push_back(cmd.c_str()); } @@ -2065,7 +2066,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0) #undef CM_EXE_PATH_LOCAL_SIZE char* exe_path = exe_path_local; if (_NSGetExecutablePath(exe_path, &exe_path_size) < 0) { - exe_path = (char*)malloc(exe_path_size); + exe_path = static_cast<char*>(malloc(exe_path_size)); _NSGetExecutablePath(exe_path, &exe_path_size); } exe_dir = @@ -2325,12 +2326,12 @@ struct cmSystemToolsRPathInfo }; #endif +#if defined(CMAKE_USE_ELF_PARSER) bool cmSystemTools::ChangeRPath(std::string const& file, std::string const& oldRPath, std::string const& newRPath, std::string* emsg, bool* changed) { -#if defined(CMAKE_USE_ELF_PARSER) if (changed) { *changed = false; } @@ -2496,15 +2497,16 @@ bool cmSystemTools::ChangeRPath(std::string const& file, *changed = true; } return true; +} #else - (void)file; - (void)oldRPath; - (void)newRPath; - (void)emsg; - (void)changed; +bool cmSystemTools::ChangeRPath(std::string const& /*file*/, + std::string const& /*oldRPath*/, + std::string const& /*newRPath*/, + std::string* /*emsg*/, bool* /*changed*/) +{ return false; -#endif } +#endif bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, const char* lhss, const char* rhss) @@ -2638,10 +2640,10 @@ int cmSystemTools::strverscmp(std::string const& lhs, std::string const& rhs) return cm_strverscmp(lhs.c_str(), rhs.c_str()); } +#if defined(CMAKE_USE_ELF_PARSER) bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg, bool* removed) { -#if defined(CMAKE_USE_ELF_PARSER) if (removed) { *removed = false; } @@ -2779,13 +2781,14 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg, *removed = true; } return true; +} #else - (void)file; - (void)emsg; - (void)removed; +bool cmSystemTools::RemoveRPath(std::string const& /*file*/, + std::string* /*emsg*/, bool* /*removed*/) +{ return false; -#endif } +#endif bool cmSystemTools::CheckRPath(std::string const& file, std::string const& newRPath) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 8dce028..e163783 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -15,7 +15,7 @@ #include "cmVisualStudioGeneratorOptions.h" #include "windows.h" -#include "cm_auto_ptr.hxx" +#include <memory> // IWYU pragma: keep static std::string cmVS10EscapeXML(std::string arg) { @@ -1722,7 +1722,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) if (!deployContent.empty()) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(deployContent); + std::unique_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(deployContent); // Deployment location cannot be set on a configuration basis if (!deployLocation.empty()) { this->WriteString("<Link>", 3); @@ -2089,7 +2090,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } if (configDependentFlags) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(flags); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(flags); std::string evaluatedFlags = cge->Evaluate(this->LocalGenerator, *config); clOptions.Parse(evaluatedFlags.c_str()); @@ -2297,16 +2298,16 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions; + std::unique_ptr<Options> pOptions; switch (this->ProjectType) { case vcxproj: - pOptions = CM_AUTO_PTR<Options>(new Options( - this->LocalGenerator, Options::Compiler, gg->GetClFlagTable())); + pOptions = cm::make_unique<Options>( + this->LocalGenerator, Options::Compiler, gg->GetClFlagTable()); break; case csproj: - pOptions = CM_AUTO_PTR<Options>(new Options(this->LocalGenerator, - Options::CSharpCompiler, - gg->GetCSharpFlagTable())); + pOptions = + cm::make_unique<Options>(this->LocalGenerator, Options::CSharpCompiler, + gg->GetCSharpFlagTable()); break; } Options& clOptions = *pOptions; @@ -2520,8 +2521,8 @@ bool cmVisualStudio10TargetGenerator::ComputeRcOptions( { cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions(new Options( - this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable())); + auto pOptions = cm::make_unique<Options>( + this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable()); Options& rcOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); @@ -2581,8 +2582,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( { cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions(new Options( - this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable())); + auto pOptions = cm::make_unique<Options>( + this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()); Options& cudaOptions = *pOptions; // Get compile flags for CUDA in this directory. @@ -2689,8 +2690,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( { cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions(new Options( - this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable())); + auto pOptions = cm::make_unique<Options>( + this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()); Options& cudaLinkOptions = *pOptions; // Determine if we need to do a device link @@ -2760,8 +2761,8 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( { cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions(new Options( - this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable())); + auto pOptions = cm::make_unique<Options>( + this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable()); Options& masmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); @@ -2818,8 +2819,8 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( { cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions(new Options( - this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable())); + auto pOptions = cm::make_unique<Options>( + this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable()); Options& nasmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); @@ -2980,7 +2981,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( if (const char* nativeLibDirectoriesExpression = this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(nativeLibDirectoriesExpression); std::string nativeLibDirs = cge->Evaluate(this->LocalGenerator, configName); @@ -2993,7 +2994,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( this->GeneratorTarget->GetProperty( "ANDROID_NATIVE_LIB_DEPENDENCIES")) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(nativeLibDependenciesExpression); std::string nativeLibDeps = cge->Evaluate(this->LocalGenerator, configName); @@ -3012,7 +3013,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( if (const char* jarDirectoriesExpression = this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) { cmGeneratorExpression ge; - CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(jarDirectoriesExpression); std::string jarDirectories = cge->Evaluate(this->LocalGenerator, configName); @@ -3074,8 +3075,9 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( { cmGlobalVisualStudio10Generator* gg = static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); - CM_AUTO_PTR<Options> pOptions(new Options( - this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), 0, this)); + auto pOptions = + cm::make_unique<Options>(this->LocalGenerator, Options::Linker, + gg->GetLinkFlagTable(), nullptr, this); Options& linkOptions = *pOptions; cmGeneratorTarget::LinkClosure const* linkClosure = diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 172ac62..a080034 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -7,9 +7,10 @@ #include "cmExpandedCommandArgument.h" #include "cmMakefile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" +#include <memory> // IWYU pragma: keep + cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf) : Makefile(mf) , Depth(0) @@ -34,7 +35,8 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // if this is the endwhile for this while loop then execute if (!this->Depth) { // Remove the function blocker for this scope or bail. - CM_AUTO_PTR<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(this, lff)); + std::unique_ptr<cmFunctionBlocker> fb( + mf.RemoveFunctionBlocker(this, lff)); if (!fb.get()) { return false; } diff --git a/Source/cmXCode21Object.cxx b/Source/cmXCode21Object.cxx index 719e627..a9bb2ef 100644 --- a/Source/cmXCode21Object.cxx +++ b/Source/cmXCode21Object.cxx @@ -34,9 +34,7 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v, std::ostream& out, PBXType t) { bool hasOne = false; - for (std::vector<cmXCodeObject*>::const_iterator i = v.begin(); i != v.end(); - ++i) { - cmXCodeObject* obj = *i; + for (auto obj : v) { if (obj->GetType() == OBJECT && obj->GetIsA() == t) { hasOne = true; break; @@ -46,9 +44,7 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v, return; } out << "\n/* Begin " << PBXTypeNames[t] << " section */\n"; - for (std::vector<cmXCodeObject*>::const_iterator i = v.begin(); i != v.end(); - ++i) { - cmXCodeObject* obj = *i; + for (auto obj : v) { if (obj->GetType() == OBJECT && obj->GetIsA() == t) { obj->Print(out); } diff --git a/Source/cmXCode21Object.h b/Source/cmXCode21Object.h index bcd8d93..8e4b80f 100644 --- a/Source/cmXCode21Object.h +++ b/Source/cmXCode21Object.h @@ -14,7 +14,7 @@ class cmXCode21Object : public cmXCodeObject { public: cmXCode21Object(PBXType ptype, Type type); - virtual void PrintComment(std::ostream&); + void PrintComment(std::ostream&) override; static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out, PBXType t); static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out); diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 957adb4..e54f1f3 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -120,8 +120,9 @@ void cmXCodeObject::Print(std::ostream& out) out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator; for (i = this->ObjectAttributes.begin(); i != this->ObjectAttributes.end(); ++i) { - if (i->first == "isa") + if (i->first == "isa") { continue; + } PrintAttribute(out, 3, separator, indentFactor, i->first, i->second, this); } @@ -129,9 +130,9 @@ void cmXCodeObject::Print(std::ostream& out) out << "};\n"; } -void cmXCodeObject::PrintAttribute(std::ostream& out, const int level, - const std::string separator, - const int factor, const std::string& name, +void cmXCodeObject::PrintAttribute(std::ostream& out, int level, + const std::string& separator, int factor, + const std::string& name, const cmXCodeObject* object, const cmXCodeObject* parent) { @@ -203,9 +204,9 @@ void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs, { cmXCodeObject::Indent(1, out); out << "objects = {\n"; - for (unsigned int i = 0; i < objs.size(); ++i) { - if (objs[i]->TypeValue == OBJECT) { - objs[i]->Print(out); + for (auto obj : objs) { + if (obj->TypeValue == OBJECT) { + obj->Print(out); } } cmXCodeObject::Indent(1, out); diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h index b51aac7..b0f1d31 100644 --- a/Source/cmXCodeObject.h +++ b/Source/cmXCodeObject.h @@ -94,8 +94,8 @@ public: } static void Indent(int level, std::ostream& out); void Print(std::ostream& out); - void PrintAttribute(std::ostream& out, const int level, - const std::string separator, const int factor, + void PrintAttribute(std::ostream& out, int level, + const std::string& separator, int factor, const std::string& name, const cmXCodeObject* object, const cmXCodeObject* parent); virtual void PrintComment(std::ostream&) {} @@ -119,9 +119,7 @@ public: // search the attribute list for an object of the specified type cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const { - for (std::vector<cmXCodeObject*>::const_iterator i = this->List.begin(); - i != this->List.end(); ++i) { - cmXCodeObject* o = *i; + for (auto o : this->List) { if (o->IsA == t) { return o; } diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx index bca39af..f1dce64 100644 --- a/Source/cmXCodeScheme.cxx +++ b/Source/cmXCodeScheme.cxx @@ -91,7 +91,7 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout, - std::string configuration, + const std::string& configuration, const std::string& container) { xout.StartElement("TestAction"); @@ -104,12 +104,11 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout, xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES"); xout.StartElement("Testables"); - for (TestObjects::const_iterator it = this->Tests.begin(); - it != this->Tests.end(); ++it) { + for (auto test : this->Tests) { xout.StartElement("TestableReference"); xout.BreakAttributes(); xout.Attribute("skipped", "NO"); - WriteBuildableReference(xout, *it, container); + WriteBuildableReference(xout, test, container); xout.EndElement(); // TestableReference } xout.EndElement(); @@ -127,7 +126,7 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout, - std::string configuration, + const std::string& configuration, const std::string& container) { xout.StartElement("LaunchAction"); @@ -164,7 +163,7 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout, - std::string configuration) + const std::string& configuration) { xout.StartElement("ProfileAction"); xout.BreakAttributes(); @@ -177,7 +176,7 @@ void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout, - std::string configuration) + const std::string& configuration) { xout.StartElement("AnalyzeAction"); xout.BreakAttributes(); @@ -186,7 +185,7 @@ void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout, - std::string configuration) + const std::string& configuration) { xout.StartElement("ArchiveAction"); xout.BreakAttributes(); @@ -223,8 +222,9 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name) // if (std::find(this->ConfigList.begin(), this->ConfigList.end(), name) == this->ConfigList.end() && - this->ConfigList.size() > 0) + !this->ConfigList.empty()) { return this->ConfigList[0]; + } return name; } diff --git a/Source/cmXCodeScheme.h b/Source/cmXCodeScheme.h index def75b1..e5e501a 100644 --- a/Source/cmXCodeScheme.h +++ b/Source/cmXCodeScheme.h @@ -37,13 +37,13 @@ private: void WriteXCodeXCScheme(std::ostream& fout, const std::string& container); void WriteBuildAction(cmXMLWriter& xout, const std::string& container); - void WriteTestAction(cmXMLWriter& xout, std::string configuration, + void WriteTestAction(cmXMLWriter& xout, const std::string& configuration, const std::string& container); - void WriteLaunchAction(cmXMLWriter& xout, std::string configuration, + void WriteLaunchAction(cmXMLWriter& xout, const std::string& configuration, const std::string& container); - void WriteProfileAction(cmXMLWriter& xout, std::string configuration); - void WriteAnalyzeAction(cmXMLWriter& xout, std::string configuration); - void WriteArchiveAction(cmXMLWriter& xout, std::string configuration); + void WriteProfileAction(cmXMLWriter& xout, const std::string& configuration); + void WriteAnalyzeAction(cmXMLWriter& xout, const std::string& configuration); + void WriteArchiveAction(cmXMLWriter& xout, const std::string& configuration); void WriteBuildableReference(cmXMLWriter& xout, const cmXCodeObject* xcObj, const std::string& container); diff --git a/Source/cm_auto_ptr.hxx b/Source/cm_auto_ptr.hxx deleted file mode 100644 index 1ac9220..0000000 --- a/Source/cm_auto_ptr.hxx +++ /dev/null @@ -1,220 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef CM_AUTO_PTR_HXX -#define CM_AUTO_PTR_HXX - -#include "cmConfigure.h" - -#ifdef CMake_HAVE_CXX_AUTO_PTR - -#include <memory> -#define CM_AUTO_PTR std::auto_ptr - -#else - -#define CM_AUTO_PTR cm::auto_ptr - -// The HP compiler cannot handle the conversions necessary to use -// auto_ptr_ref to pass an auto_ptr returned from one function -// directly to another function as in use_auto_ptr(get_auto_ptr()). -// We instead use const_cast to achieve the syntax on those platforms. -// We do not use const_cast on other platforms to maintain the C++ -// standard design and guarantee that if an auto_ptr is bound -// to a reference-to-const then ownership will be maintained. -#if defined(__HP_aCC) -#define cm_AUTO_PTR_REF 0 -#define cm_AUTO_PTR_CONST const -#define cm_AUTO_PTR_CAST(a) cast(a) -#else -#define cm_AUTO_PTR_REF 1 -#define cm_AUTO_PTR_CONST -#define cm_AUTO_PTR_CAST(a) a -#endif - -// In C++11, clang will warn about using dynamic exception specifications -// as they are deprecated. But as this class is trying to faithfully -// mimic std::auto_ptr, we want to keep the 'throw()' decorations below. -// So we suppress the warning. -#if defined(__clang__) && defined(__has_warning) -#if __has_warning("-Wdeprecated") -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated" -#endif -#endif - -namespace cm { - -template <class X> -class auto_ptr; - -#if cm_AUTO_PTR_REF -namespace detail { -// The auto_ptr_ref template is supposed to be a private member of -// auto_ptr but Borland 5.8 cannot handle it. Instead put it in -// a private namespace. -template <class Y> -struct auto_ptr_ref -{ - Y* p_; - - // The extra constructor argument prevents implicit conversion to - // auto_ptr_ref from auto_ptr through the constructor. Normally - // this should be done with the explicit keyword but Borland 5.x - // generates code in the conversion operator to call itself - // infinately. - auto_ptr_ref(Y* p, int) - : p_(p) - { - } -}; -} -#endif - -/** C++98 Standard Section 20.4.5 - Template class auto_ptr. */ -template <class X> -class auto_ptr -{ -#if !cm_AUTO_PTR_REF - template <typename Y> - static inline auto_ptr<Y>& cast(auto_ptr<Y> const& a) - { - return const_cast<auto_ptr<Y>&>(a); - } -#endif - - /** The pointer to the object held. */ - X* x_; - -public: - /** The type of object held by the auto_ptr. */ - typedef X element_type; - - /** Construct from an auto_ptr holding a compatible object. This - transfers ownership to the newly constructed auto_ptr. */ - template <class Y> - auto_ptr(auto_ptr<Y> cm_AUTO_PTR_CONST& a) throw() - : x_(cm_AUTO_PTR_CAST(a).release()) - { - } - - /** Assign from an auto_ptr holding a compatible object. This - transfers ownership to the left-hand-side of the assignment. */ - template <class Y> - auto_ptr& operator=(auto_ptr<Y> cm_AUTO_PTR_CONST& a) throw() // NOLINT - { - this->reset(cm_AUTO_PTR_CAST(a).release()); - return *this; // NOLINT - } - - /** - * Explicitly construct from a raw pointer. This is typically - * called with the result of operator new. For example: - * - * auto_ptr<X> ptr(new X()); - */ - explicit auto_ptr(X* p = nullptr) throw() - : x_(p) - { - } - - /** Construct from another auto_ptr holding an object of the same - type. This transfers ownership to the newly constructed - auto_ptr. */ - auto_ptr(auto_ptr cm_AUTO_PTR_CONST& a) throw() - : x_(cm_AUTO_PTR_CAST(a).release()) - { - } - - /** Assign from another auto_ptr holding an object of the same type. - This transfers ownership to the newly constructed auto_ptr. */ - auto_ptr& operator=(auto_ptr cm_AUTO_PTR_CONST& a) throw() // NOLINT - { - this->reset(cm_AUTO_PTR_CAST(a).release()); - return *this; // NOLINT - } - - /** Destruct and delete the object held. */ - ~auto_ptr() throw() - { - // Assume object destructor is nothrow. - delete this->x_; - } - - /** Dereference and return a reference to the object held. */ - X& operator*() const throw() { return *this->x_; } - - /** Return a pointer to the object held. */ - X* operator->() const throw() { return this->x_; } - - /** Return a pointer to the object held. */ - X* get() const throw() { return this->x_; } - - /** Return a pointer to the object held and reset to hold no object. - This transfers ownership to the caller. */ - X* release() throw() - { - X* x = this->x_; - this->x_ = nullptr; - return x; - } - - /** Assume ownership of the given object. The object previously - held is deleted. */ - void reset(X* p = 0) throw() - { - if (this->x_ != p) { - // Assume object destructor is nothrow. - delete this->x_; - this->x_ = p; - } - } - - /** Convert to an auto_ptr holding an object of a compatible type. - This transfers ownership to the returned auto_ptr. */ - template <class Y> - operator auto_ptr<Y>() throw() - { - return auto_ptr<Y>(this->release()); - } - -#if cm_AUTO_PTR_REF - /** Construct from an auto_ptr_ref. This is used when the - constructor argument is a call to a function returning an - auto_ptr. */ - auto_ptr(detail::auto_ptr_ref<X> r) throw() - : x_(r.p_) - { - } - - /** Assign from an auto_ptr_ref. This is used when a function - returning an auto_ptr is passed on the right-hand-side of an - assignment. */ - auto_ptr& operator=(detail::auto_ptr_ref<X> r) throw() - { - this->reset(r.p_); - return *this; // NOLINT - } - - /** Convert to an auto_ptr_ref. This is used when a function - returning an auto_ptr is the argument to the constructor of - another auto_ptr. */ - template <class Y> - operator detail::auto_ptr_ref<Y>() throw() - { - return detail::auto_ptr_ref<Y>(this->release(), 1); - } -#endif -}; - -} // namespace cm - -// Undo warning suppression. -#if defined(__clang__) && defined(__has_warning) -#if __has_warning("-Wdeprecated") -#pragma clang diagnostic pop -#endif -#endif - -#endif - -#endif diff --git a/Source/cmake.cxx b/Source/cmake.cxx index e61acb1..61595d5 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -24,7 +24,6 @@ #include "cmUtils.hxx" #include "cmVersionConfig.h" #include "cmWorkingDirectory.h" -#include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -111,6 +110,7 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> #include <iostream> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -482,15 +482,15 @@ void cmake::ReadListFile(const std::vector<std::string>& args, snapshot.GetDirectory().SetCurrentSource( cmSystemTools::GetCurrentWorkingDirectory()); snapshot.SetDefaultDefinitions(); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(gg, snapshot)); + cmMakefile mf(gg, snapshot); if (this->GetWorkingMode() != NORMAL_MODE) { std::string file(cmSystemTools::CollapseFullPath(path)); cmSystemTools::ConvertToUnixSlashes(file); - mf->SetScriptModeFile(file.c_str()); + mf.SetScriptModeFile(file.c_str()); - mf->SetArgcArgv(args); + mf.SetArgcArgv(args); } - if (!mf->ReadListFile(path)) { + if (!mf.ReadListFile(path)) { cmSystemTools::Error("Error processing file: ", path); } this->SetHomeDirectory(homeDir); @@ -1874,8 +1874,8 @@ int cmake::CheckBuildSystem() cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); - if (!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) || + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + if (!mf.ReadListFile(this->CheckBuildSystemArgument.c_str()) || cmSystemTools::GetErrorOccuredFlag()) { if (verbose) { std::ostringstream msg; @@ -1889,25 +1889,25 @@ int cmake::CheckBuildSystem() if (this->ClearBuildSystem) { // Get the generator used for this build system. - const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR"); + const char* genName = mf.GetDefinition("CMAKE_DEPENDS_GENERATOR"); if (!genName || genName[0] == '\0') { genName = "Unix Makefiles"; } // Create the generator and use it to clear the dependencies. - CM_AUTO_PTR<cmGlobalGenerator> ggd(this->CreateGlobalGenerator(genName)); - if (ggd.get()) { + std::unique_ptr<cmGlobalGenerator> ggd( + this->CreateGlobalGenerator(genName)); + if (ggd) { cm.GetCurrentSnapshot().SetDefaultDefinitions(); - CM_AUTO_PTR<cmMakefile> mfd( - new cmMakefile(ggd.get(), cm.GetCurrentSnapshot())); - CM_AUTO_PTR<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(mfd.get())); - lgd->ClearDependencies(mfd.get(), verbose); + cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot()); + std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mfd)); + lgd->ClearDependencies(&mfd, verbose); } } // If any byproduct of makefile generation is missing we must re-run. std::vector<std::string> products; - if (const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS")) { + if (const char* productStr = mf.GetDefinition("CMAKE_MAKEFILE_PRODUCTS")) { cmSystemTools::ExpandListArgument(productStr, products); } for (std::string const& p : products) { @@ -1925,8 +1925,8 @@ int cmake::CheckBuildSystem() // Get the set of dependencies and outputs. std::vector<std::string> depends; std::vector<std::string> outputs; - const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS"); - const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS"); + const char* dependsStr = mf.GetDefinition("CMAKE_MAKEFILE_DEPENDS"); + const char* outputsStr = mf.GetDefinition("CMAKE_MAKEFILE_OUTPUTS"); if (dependsStr && outputsStr) { cmSystemTools::ExpandListArgument(dependsStr, depends); cmSystemTools::ExpandListArgument(outputsStr, outputs); @@ -2039,19 +2039,18 @@ void cmake::MarkCliAsUsed(const std::string& variable) void cmake::GenerateGraphViz(const char* fileName) const { #ifdef CMAKE_BUILD_WITH_CMAKE - CM_AUTO_PTR<cmGraphVizWriter> gvWriter( - new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators())); + cmGraphVizWriter gvWriter(this->GetGlobalGenerator()->GetLocalGenerators()); std::string settingsFile = this->GetHomeOutputDirectory(); settingsFile += "/CMakeGraphVizOptions.cmake"; std::string fallbackSettingsFile = this->GetHomeDirectory(); fallbackSettingsFile += "/CMakeGraphVizOptions.cmake"; - gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str()); + gvWriter.ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str()); - gvWriter->WritePerTargetFiles(fileName); - gvWriter->WriteTargetDependersFiles(fileName); - gvWriter->WriteGlobalFile(fileName); + gvWriter.WritePerTargetFiles(fileName); + gvWriter.WriteTargetDependersFiles(fileName); + gvWriter.WriteGlobalFile(fileName); #endif } @@ -2357,7 +2356,7 @@ int cmake::Build(const std::string& dir, const std::string& target, std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n"; return 1; } - CM_AUTO_PTR<cmGlobalGenerator> gen( + std::unique_ptr<cmGlobalGenerator> gen( this->CreateGlobalGenerator(cachedGenerator)); if (!gen.get()) { std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 62a0094..c0c7d03 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -12,7 +12,6 @@ #include "cmSystemTools.h" #include "cmUtils.hxx" #include "cmVersion.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -37,6 +36,7 @@ #include <functional> #include <iostream> #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -348,6 +348,7 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args) std::bind(&cmcmd::HandleCppCheck, a1, a2, a3); // copy the command options to a vector of strings std::vector<std::string> commandOptions; + commandOptions.reserve(coCompileTypes.size()); for (const auto& i : coCompileTypes) { commandOptions.push_back(i.first); } @@ -928,8 +929,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) cmStateSnapshot snapshot = cm.GetCurrentSnapshot(); snapshot.GetDirectory().SetCurrentBinary(startOutDir); snapshot.GetDirectory().SetCurrentSource(startDir); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(ggd, snapshot)); - CM_AUTO_PTR<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(mf.get())); + cmMakefile mf(ggd, snapshot); + std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mf)); // Actually scan dependencies. return lgd->UpdateDependencies(depInfo.c_str(), verbose, color) ? 0 diff --git a/Source/ctest.cxx b/Source/ctest.cxx index fe24a72..f6466fa 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -186,6 +186,7 @@ int main(int argc, char const* const* argv) // copy the args to a vector std::vector<std::string> args; + args.reserve(argc); for (int i = 0; i < argc; ++i) { args.push_back(argv[i]); } diff --git a/Tests/FindOpenGL/CMakeLists.txt b/Tests/FindOpenGL/CMakeLists.txt index 9aa3aba..97c9e60 100644 --- a/Tests/FindOpenGL/CMakeLists.txt +++ b/Tests/FindOpenGL/CMakeLists.txt @@ -1,3 +1,9 @@ +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMake_TEST_FindOpenGL_VND) + set(_vnd_testing TRUE) +else() + set(_vnd_testing FALSE) +endif() + add_test(NAME FindOpenGL.Test COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --build-and-test @@ -6,5 +12,6 @@ add_test(NAME FindOpenGL.Test COMMAND ${build_generator_args} --build-project TestFindOpenGL --build-options ${build_options} + -DOpenGL_TEST_VND=${_vnd_testing} --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) diff --git a/Tests/FindOpenGL/Test/CMakeLists.txt b/Tests/FindOpenGL/Test/CMakeLists.txt index cac3424..3b5ffee 100644 --- a/Tests/FindOpenGL/Test/CMakeLists.txt +++ b/Tests/FindOpenGL/Test/CMakeLists.txt @@ -1,14 +1,70 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.9) project(TestFindOpenGL C) include(CTest) find_package(OpenGL REQUIRED) +# import target for GLU add_executable(test_tgt main.c) target_link_libraries(test_tgt OpenGL::GLU) add_test(NAME test_tgt COMMAND test_tgt) +# OPENGL_LIBRARIES should be whatever libraries are needed to link. add_executable(test_var main.c) target_include_directories(test_var PRIVATE ${OPENGL_INGLUDE_DIRS}) target_link_libraries(test_var PRIVATE ${OPENGL_LIBRARIES}) add_test(NAME test_var COMMAND test_var) + +# VND support adds an ::OpenGL import target. This can be used for OpenGL-only +# code (code that does not manipulate contexts, like our 'main.c'). Without +# VND, ::GL can be used for both context and non-context OpenGL code. +if(OpenGL_TEST_VND) + add_executable(test_comp_none main.c) + target_link_libraries(test_comp_none PRIVATE OpenGL::OpenGL) + add_test(NAME test_comp_none COMMAND test_comp_none) +else() + add_executable(test_comp_none main.c) + target_link_libraries(test_comp_none PRIVATE OpenGL::GL) + add_test(NAME test_comp_none COMMAND test_comp_none) +endif() + +# GLX +if(OpenGL_TEST_VND) + find_package(OpenGL REQUIRED COMPONENTS OpenGL GLX) + add_executable(test_comp_glx main.c) + target_link_libraries(test_comp_glx PRIVATE OpenGL::OpenGL OpenGL::GLX) + add_test(NAME test_comp_glx COMMAND test_comp_glx) +else() + # non-VND systems won't have it, but an optional search for GLX should still + # be okay. + find_package(OpenGL COMPONENTS GLX) + add_executable(test_comp_glx_novnd main.c) + target_link_libraries(test_comp_glx_novnd PRIVATE OpenGL::GL) + add_test(NAME test_comp_glx_novnd COMMAND test_comp_glx_novnd) +endif() + +# EGL is only available on Linux+GLVND at present. +if(OpenGL_TEST_VND) + find_package(OpenGL COMPONENTS OpenGL EGL) + if(OpenGL_EGL_FOUND) + add_executable(test_comp_egl main.c) + target_link_libraries(test_comp_egl PRIVATE OpenGL::OpenGL OpenGL::EGL) + add_test(NAME test_comp_egl COMMAND test_comp_egl) + # EGL-only code should not link to GLX. + execute_process(COMMAND ldd test_comp_egl + OUTPUT_VARIABLE LDD_OUT + ERROR_VARIABLE LDD_ERR) + if("${LDD_OUT}" MATCHES "GLX") + message(FATAL_ERROR "EGL-only code links to GLX!") + endif() + endif() + + # all three COMPONENTS together. + find_package(OpenGL COMPONENTS OpenGL EGL GLX) + if(OpenGL_EGL_FOUND AND OpenGL_GLX_FOUND) + add_executable(test_comp_both main.c) + target_link_libraries(test_comp_both PRIVATE OpenGL::OpenGL OpenGL::EGL + OpenGL::GLX) + add_test(NAME test_comp_both COMMAND test_comp_both) + endif() +endif() diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index 81ab734..ec35b89 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -66,15 +66,6 @@ set_property(TARGET mocOnly PROPERTY AUTOMOC ON) target_link_libraries(mocOnly ${QT_LIBRARIES}) # -- Test -# MOC AUTOMOC_MACRO_NAMES -if (NOT QT_TEST_VERSION STREQUAL 4) - add_executable(mocMacroName mocMacroName/main.cpp mocMacroName/MacroName.cpp) - set_property(TARGET mocMacroName PROPERTY AUTOMOC ON) - set_property(TARGET mocMacroName PROPERTY AUTOMOC_MACRO_NAMES "QO_ALIAS") - target_link_libraries(mocMacroName ${QT_LIBRARIES}) -endif() - -# -- Test # UIC only if(ALLOW_WRAP_CPP) qtx_wrap_cpp(uicOnlyMoc uicOnlySource/uiconly.h) @@ -188,8 +179,10 @@ set_property(TARGET skipRccB PROPERTY AUTOMOC ON) target_link_libraries(skipRccB ${QT_LIBRARIES}) # -- Test -# Source files with the same basename in different subdirectories -add_subdirectory(sameName) +# MOC AUTOMOC_MACRO_NAMES +if (NOT QT_TEST_VERSION STREQUAL 4) + add_subdirectory(mocMacroName) +endif() # -- Test # Tests AUTOMOC with generated sources @@ -217,5 +210,9 @@ add_subdirectory(uicInclude) add_subdirectory(objectLibrary) # -- Test +# Source files with the same basename in different subdirectories +add_subdirectory(sameName) + +# -- Test # Complex test case add_subdirectory(complex) diff --git a/Tests/QtAutogen/mocMacroName/CMakeLists.txt b/Tests/QtAutogen/mocMacroName/CMakeLists.txt new file mode 100644 index 0000000..08e6803 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.9) + +list(APPEND CMAKE_AUTOMOC_MACRO_NAMES "QO1_ALIAS") + +add_executable(mmn main.cpp Gadget.cpp Object.cpp Object1Aliased.cpp Object2Aliased.cpp) +set_property(TARGET mmn PROPERTY AUTOMOC ON) +set_property(TARGET mmn APPEND PROPERTY AUTOMOC_MACRO_NAMES "QO2_ALIAS") +target_link_libraries(mmn ${QT_LIBRARIES}) diff --git a/Tests/QtAutogen/mocMacroName/CustomMacros.hpp b/Tests/QtAutogen/mocMacroName/CustomMacros.hpp new file mode 100644 index 0000000..93e5bfd --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/CustomMacros.hpp @@ -0,0 +1,8 @@ +#ifndef CUSTOM_MACROS_HPP +#define CUSTOM_MACROS_HPP + +#include <QObject> +#define QO1_ALIAS Q_OBJECT +#define QO2_ALIAS Q_OBJECT + +#endif diff --git a/Tests/QtAutogen/mocMacroName/Gadget.cpp b/Tests/QtAutogen/mocMacroName/Gadget.cpp new file mode 100644 index 0000000..167faeb --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Gadget.cpp @@ -0,0 +1,6 @@ +#include "Gadget.hpp" + +Gadget::Gadget() + : test(0) +{ +} diff --git a/Tests/QtAutogen/mocMacroName/Gadget.hpp b/Tests/QtAutogen/mocMacroName/Gadget.hpp new file mode 100644 index 0000000..2587ed2 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Gadget.hpp @@ -0,0 +1,15 @@ +#ifndef GADGET_HPP +#define GADGET_HPP + +#include <QMetaType> + +class Gadget +{ + Q_GADGET + Q_PROPERTY(int test MEMBER test) +public: + Gadget(); + int test; +}; + +#endif diff --git a/Tests/QtAutogen/mocMacroName/MacroAlias.hpp b/Tests/QtAutogen/mocMacroName/MacroAlias.hpp deleted file mode 100644 index cf06f2a..0000000 --- a/Tests/QtAutogen/mocMacroName/MacroAlias.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef MACROALIAS_HPP -#define MACROALIAS_HPP - -#include <QObject> -#define QO_ALIAS Q_OBJECT - -#endif diff --git a/Tests/QtAutogen/mocMacroName/MacroName.cpp b/Tests/QtAutogen/mocMacroName/MacroName.cpp deleted file mode 100644 index 78d04a8..0000000 --- a/Tests/QtAutogen/mocMacroName/MacroName.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "MacroName.hpp" - -MacroName::MacroName() -{ -} - -void MacroName::aSlot() -{ -} diff --git a/Tests/QtAutogen/mocMacroName/MacroName.hpp b/Tests/QtAutogen/mocMacroName/MacroName.hpp deleted file mode 100644 index b6c7306..0000000 --- a/Tests/QtAutogen/mocMacroName/MacroName.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MACRONAME_HPP -#define MACRONAME_HPP - -#include "MacroAlias.hpp" - -// Test Qt object macro hidden in a macro (AUTOMOC_MACRO_NAMES) -class MacroName : public QObject -{ - QO_ALIAS -public: - MacroName(); - -signals: - void aSignal(); - -public slots: - void aSlot(); -}; - -#endif diff --git a/Tests/QtAutogen/mocMacroName/Object.cpp b/Tests/QtAutogen/mocMacroName/Object.cpp new file mode 100644 index 0000000..c0b4f33 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Object.cpp @@ -0,0 +1,9 @@ +#include "Object.hpp" + +Object::Object() +{ +} + +void Object::aSlot() +{ +} diff --git a/Tests/QtAutogen/mocMacroName/Object.hpp b/Tests/QtAutogen/mocMacroName/Object.hpp new file mode 100644 index 0000000..0c40824 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Object.hpp @@ -0,0 +1,19 @@ +#ifndef OBJECT_HPP +#define OBJECT_HPP + +#include <QObject> + +class Object : public QObject +{ + Q_OBJECT + Q_PROPERTY(int test MEMBER test) +public: + Object(); + + Q_SLOT + void aSlot(); + + int test; +}; + +#endif diff --git a/Tests/QtAutogen/mocMacroName/Object1Aliased.cpp b/Tests/QtAutogen/mocMacroName/Object1Aliased.cpp new file mode 100644 index 0000000..b8b4806 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Object1Aliased.cpp @@ -0,0 +1,9 @@ +#include "Object1Aliased.hpp" + +Object1Aliased::Object1Aliased() +{ +} + +void Object1Aliased::aSlot() +{ +} diff --git a/Tests/QtAutogen/mocMacroName/Object1Aliased.hpp b/Tests/QtAutogen/mocMacroName/Object1Aliased.hpp new file mode 100644 index 0000000..6c6bb40 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Object1Aliased.hpp @@ -0,0 +1,20 @@ +#ifndef OBJECTALIASED_HPP +#define OBJECTALIASED_HPP + +#include "CustomMacros.hpp" + +// Test Qt object macro hidden in a macro (AUTOMOC_MACRO_NAMES) +class Object1Aliased : public QObject +{ + QO1_ALIAS +public: + Object1Aliased(); + +signals: + void aSignal(); + +public slots: + void aSlot(); +}; + +#endif diff --git a/Tests/QtAutogen/mocMacroName/Object2Aliased.cpp b/Tests/QtAutogen/mocMacroName/Object2Aliased.cpp new file mode 100644 index 0000000..4b09dd1 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Object2Aliased.cpp @@ -0,0 +1,9 @@ +#include "Object2Aliased.hpp" + +Object2Aliased::Object2Aliased() +{ +} + +void Object2Aliased::aSlot() +{ +} diff --git a/Tests/QtAutogen/mocMacroName/Object2Aliased.hpp b/Tests/QtAutogen/mocMacroName/Object2Aliased.hpp new file mode 100644 index 0000000..b9bdc12 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/Object2Aliased.hpp @@ -0,0 +1,20 @@ +#ifndef OBJECT2ALIASED_HPP +#define OBJECT2ALIASED_HPP + +#include "CustomMacros.hpp" + +// Test Qt object macro hidden in a macro (AUTOMOC_MACRO_NAMES) +class Object2Aliased : public QObject +{ + QO2_ALIAS +public: + Object2Aliased(); + +signals: + void aSignal(); + +public slots: + void aSlot(); +}; + +#endif diff --git a/Tests/QtAutogen/mocMacroName/main.cpp b/Tests/QtAutogen/mocMacroName/main.cpp index 67ee81f..3b45d04 100644 --- a/Tests/QtAutogen/mocMacroName/main.cpp +++ b/Tests/QtAutogen/mocMacroName/main.cpp @@ -1,7 +1,13 @@ -#include "MacroName.hpp" +#include "Gadget.hpp" +#include "Object.hpp" +#include "Object1Aliased.hpp" +#include "Object2Aliased.hpp" int main(int argv, char** args) { - MacroName macroName; + Gadget gadget; + Object object; + Object1Aliased object1Aliased; + Object2Aliased object2Aliased; return 0; } diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index aa4c5ac..5622f8e 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -147,6 +147,7 @@ endif() add_RunCMake_test(GeneratorExpression) add_RunCMake_test(GeneratorPlatform) add_RunCMake_test(GeneratorToolset) +add_RunCMake_test(GetPrerequisites) add_RunCMake_test(GNUInstallDirs -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME}) add_RunCMake_test(GoogleTest) # Note: does not actually depend on Google Test add_RunCMake_test(TargetPropertyGeneratorExpressions) diff --git a/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake b/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake new file mode 100644 index 0000000..3856c54 --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake @@ -0,0 +1,3 @@ +include(RunCMake) + +run_cmake_command(TargetMissing ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TargetMissing.cmake) diff --git a/Tests/RunCMake/GetPrerequisites/TargetMissing-stderr.txt b/Tests/RunCMake/GetPrerequisites/TargetMissing-stderr.txt new file mode 100644 index 0000000..cffe5f8 --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/TargetMissing-stderr.txt @@ -0,0 +1,3 @@ +^warning: target 'does_not_exist' is not absolute\.\.\. +warning: target 'does_not_exist' does not exist\.\.\. +result_var='value;before;call'$ diff --git a/Tests/RunCMake/GetPrerequisites/TargetMissing.cmake b/Tests/RunCMake/GetPrerequisites/TargetMissing.cmake new file mode 100644 index 0000000..84fd32c --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/TargetMissing.cmake @@ -0,0 +1,4 @@ +include(GetPrerequisites) +set(result_var value before call) +get_prerequisites(does_not_exist result_var 0 0 "" "") +message("result_var='${result_var}'") diff --git a/Tests/RunCMake/get_property/source_properties-stderr.txt b/Tests/RunCMake/get_property/source_properties-stderr.txt index 0a46f96..00a9b82 100644 --- a/Tests/RunCMake/get_property/source_properties-stderr.txt +++ b/Tests/RunCMake/get_property/source_properties-stderr.txt @@ -3,4 +3,10 @@ get_property: --><-- get_source_file_property: -->value<-- get_property: -->value<-- get_source_file_property: -->NOTFOUND<-- -get_property: --><--$ +get_property: --><-- +get_source_file_property: -->value<-- +get_property: -->value<-- +get_source_file_property: -->NOTFOUND<-- +get_property: --><-- +get_source_file_property: -->value<-- +get_property: -->value<--$ diff --git a/Tests/RunCMake/get_property/source_properties.cmake b/Tests/RunCMake/get_property/source_properties.cmake index 263ffe1..12d2d07 100644 --- a/Tests/RunCMake/get_property/source_properties.cmake +++ b/Tests/RunCMake/get_property/source_properties.cmake @@ -13,3 +13,13 @@ set_source_files_properties(file.c PROPERTIES empty "" custom value) check_source_file_property(file.c empty) check_source_file_property(file.c custom) check_source_file_property(file.c noexist) + +# Test strange legacy behavior in which the order in which source files are +# first accessed affects how properties are applied without an extension. +# See also issue #15208. +get_property(lang SOURCE ${CMAKE_CURRENT_BINARY_DIR}/file2.c PROPERTY LANGUAGE) +get_property(lang SOURCE ${CMAKE_CURRENT_BINARY_DIR}/file2.h PROPERTY LANGUAGE) +set_property(SOURCE file2 PROPERTY custom value) # set property without extension +check_source_file_property(file2 custom) # should have property +check_source_file_property(file2.h custom) # should not have property +check_source_file_property(file2.c custom) # should have property diff --git a/Tests/VSResource/CMakeLists.txt b/Tests/VSResource/CMakeLists.txt index 718e624..fb47c7e 100644 --- a/Tests/VSResource/CMakeLists.txt +++ b/Tests/VSResource/CMakeLists.txt @@ -56,3 +56,10 @@ endif() set_property(TARGET VSResource PROPERTY VS_GLOBAL_CMakeTestVsGlobalVariable "test val") + +if(CMAKE_GENERATOR MATCHES "Ninja|Visual Studio") + cmake_policy(PUSH) + cmake_policy(SET CMP0037 OLD) + add_library("My ResourceLib" lib.cpp lib.rc) + cmake_policy(POP) +endif() diff --git a/Utilities/IWYU/mapping.imp b/Utilities/IWYU/mapping.imp index 349945a..3240edf 100644 --- a/Utilities/IWYU/mapping.imp +++ b/Utilities/IWYU/mapping.imp @@ -49,12 +49,6 @@ #{ symbol: [ "std::pair", private, "<map>", public ] }, #{ symbol: [ "std::pair", private, "<set>", public ] }, - # IWYU wrongly suggests to include "cm_auto_ptr.hxx" in some places. This - # might be a misinterpretation of a template specialization in <utility>. - # As a workaround, map the symbol auto_ptr to "cmConfigure.h". - # This will still correctly require "cm_auto_ptr.hxx" for CM_AUTO_PTR. - { symbol: [ "cm::auto_ptr", private, "\"cmConfigure.h\"", public ] }, - # __decay_and_strip is used internally in the C++11 standard library. # IWYU does not classify it as internal and suggests to add <type_traits>. # To ignore it, we simply map it to a file that is included anyway. @@ -1270,7 +1270,6 @@ cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_BINARY_DIR \"${CMAKE_ cmake_report cmConfigure.h${_tmp} "#define CMAKE_BIN_DIR \"/bootstrap-not-insalled\"" cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/bootstrap-not-insalled\"" cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP" -cmake_report cmConfigure.h${_tmp} "#define CM_EQ_DELETE" cmake_report cmConfigure.h${_tmp} "#define CM_FALLTHROUGH" cmake_report cmConfigure.h${_tmp} "#define CM_DISABLE_COPY(Class)" |