diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CPackComponent.cmake | 10 | ||||
-rw-r--r-- | Modules/CPackIFW.cmake | 13 | ||||
-rw-r--r-- | Modules/Compiler/IAR-C.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/IAR-CXX.cmake | 2 | ||||
-rw-r--r-- | Modules/FindCUDA.cmake | 22 | ||||
-rw-r--r-- | Modules/FindCUDA/select_compute_arch.cmake | 12 | ||||
-rw-r--r-- | Modules/FindCygwin.cmake | 10 | ||||
-rw-r--r-- | Modules/FindGTest.cmake | 2 | ||||
-rw-r--r-- | Modules/FindHDF5.cmake | 77 | ||||
-rw-r--r-- | Modules/FindJava.cmake | 2 | ||||
-rw-r--r-- | Modules/FindLibXml2.cmake | 7 | ||||
-rw-r--r-- | Modules/FindPkgConfig.cmake | 3 | ||||
-rw-r--r-- | Modules/GoogleTest.cmake | 216 | ||||
-rw-r--r-- | Modules/GoogleTestAddTests.cmake | 100 | ||||
-rw-r--r-- | Modules/Platform/Android-Common.cmake | 12 | ||||
-rw-r--r-- | Modules/UseSWIG.cmake | 6 |
16 files changed, 453 insertions, 44 deletions
diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake index 3a10b99..2374fbd 100644 --- a/Modules/CPackComponent.cmake +++ b/Modules/CPackComponent.cmake @@ -37,6 +37,16 @@ # components defined by the project. The user may set it to only include the # specified components. # +# Instead of specifying all the desired components, it is possible to obtain a +# list of all defined components and then remove the unwanted ones from the +# list. The :command:`get_cmake_property` command can be used to obtain the +# ``COMPONENTS`` property, then the :command:`list(REMOVE_ITEM)` command can be +# used to remove the unwanted ones. For example, to use all defined components +# except ``foo`` and ``bar``:: +# +# get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) +# list(REMOVE_ITEM CPACK_COMPONENTS_ALL "foo" "bar") +# # .. variable:: CPACK_<GENNAME>_COMPONENT_INSTALL # # Enable/Disable component install for CPack generator <GENNAME>. diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake index c1cb52f..0210410 100644 --- a/Modules/CPackIFW.cmake +++ b/Modules/CPackIFW.cmake @@ -221,6 +221,19 @@ # You can use :command:`cpack_ifw_add_package_resources` command to resolve # relative paths. # +# .. variable:: CPACK_IFW_PACKAGE_FILE_EXTENSION +# +# The target binary extension. +# +# On Linux, the name of the target binary is automatically extended with +# '.run', if you do not specify the extension. +# +# On Windows, the target is created as an application with the extension +# '.exe', which is automatically added, if not supplied. +# +# On Mac, the target is created as an DMG disk image with the extension +# '.dmg', which is automatically added, if not supplied. +# # .. variable:: CPACK_IFW_REPOSITORIES_ALL # # The list of remote repositories. diff --git a/Modules/Compiler/IAR-C.cmake b/Modules/Compiler/IAR-C.cmake index 48a9a16..55e019e 100644 --- a/Modules/Compiler/IAR-C.cmake +++ b/Modules/Compiler/IAR-C.cmake @@ -5,6 +5,9 @@ include(Compiler/CMakeCommonCompilerMacros) # The toolchains for ARM and AVR are quite different: if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + + set(CMAKE_C_EXTENSION_COMPILE_OPTION -e) + set(CMAKE_C90_STANDARD_COMPILE_OPTION "") set(CMAKE_C90_EXTENSION_COMPILE_OPTION -e) diff --git a/Modules/Compiler/IAR-CXX.cmake b/Modules/Compiler/IAR-CXX.cmake index 7a6ba2b..8d86100 100644 --- a/Modules/Compiler/IAR-CXX.cmake +++ b/Modules/Compiler/IAR-CXX.cmake @@ -17,6 +17,8 @@ if("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") endif() endif() + set(CMAKE_CXX_EXTENSION_COMPILE_OPTION -e) + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -e) diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 5dc55d4..bd7d0c0 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -2,6 +2,20 @@ # FindCUDA # -------- # +# .. note:: +# +# The FindCUDA module has been superseded by first-class support +# for the CUDA language in CMake. It is no longer necessary to +# use this module or call ``find_package(CUDA)``. This module +# now exists only for compatibility with projects that have not +# been ported. +# +# Instead, list ``CUDA`` among the languages named in the top-level +# call to the :command:`project` command, or call the +# :command:`enable_language` command with ``CUDA``. +# Then one can add CUDA (``.cu``) sources to programs directly +# in calls to :command:`add_library` and :command:`add_executable`. +# # Tools for building CUDA C files: libraries and build dependencies. # # This script locates the NVIDIA CUDA C tools. It should work on linux, @@ -589,7 +603,6 @@ macro(cuda_unset_include_and_libraries) unset(CUDA_npps_LIBRARY CACHE) unset(CUDA_nvcuvenc_LIBRARY CACHE) unset(CUDA_nvcuvid_LIBRARY CACHE) - unset(CUDA_USE_STATIC_CUDA_RUNTIME CACHE) unset(CUDA_GPU_DETECT_OUTPUT CACHE) endmacro() @@ -802,12 +815,17 @@ endif() if(CUDA_cudart_static_LIBRARY) # If static cudart available, use it by default, but provide a user-visible option to disable it. option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) - set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) else() # If not available, silently disable the option. set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "") +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) +else() set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY) endif() + if(NOT CUDA_VERSION VERSION_LESS "5.0") cuda_find_library_local_first(CUDA_cudadevrt_LIBRARY cudadevrt "\"cudadevrt\" library") mark_as_advanced(CUDA_cudadevrt_LIBRARY) diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake index 8fb44d8..b604a17 100644 --- a/Modules/FindCUDA/select_compute_arch.cmake +++ b/Modules/FindCUDA/select_compute_arch.cmake @@ -30,12 +30,17 @@ endif () if (CUDA_VERSION VERSION_GREATER "7.5") list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Pascal") - list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1" "6.1+PTX") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1") else() list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX") endif () - +if (CUDA_VERSION VERSION_GREATER "8.5") + list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Volta") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "7.0" "7.0+PTX") +else() + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.1+PTX") +endif() ################################################################################################ # A function for automatic detection of GPUs installed (if autodetection is enabled) @@ -141,6 +146,9 @@ function(CUDA_SELECT_NVCC_ARCH_FLAGS out_variable) elseif(${arch_name} STREQUAL "Pascal") set(arch_bin 6.0 6.1) set(arch_ptx 6.1) + elseif(${arch_name} STREQUAL "Volta") + set(arch_bin 7.0 7.0) + set(arch_ptx 7.0) else() message(SEND_ERROR "Unknown CUDA Architecture Name ${arch_name} in CUDA_SELECT_NVCC_ARCH_FLAGS") endif() diff --git a/Modules/FindCygwin.cmake b/Modules/FindCygwin.cmake index b2ed703..086c7dc 100644 --- a/Modules/FindCygwin.cmake +++ b/Modules/FindCygwin.cmake @@ -9,10 +9,12 @@ if (WIN32) find_program(CYGWIN_INSTALL_PATH - cygwin.bat - "C:/Cygwin" - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]" - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]" + NAMES cygwin.bat + PATHS + "C:/Cygwin" + "C:/Cygwin64" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]" ) get_filename_component(CYGWIN_INSTALL_PATH "${CYGWIN_INSTALL_PATH}" DIRECTORY) mark_as_advanced( diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake index c4b4535..cb71ef1 100644 --- a/Modules/FindGTest.cmake +++ b/Modules/FindGTest.cmake @@ -71,7 +71,7 @@ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # # See :module:`GoogleTest` for information on the :command:`gtest_add_tests` -# command. +# and :command:`gtest_discover_tests` commands. include(${CMAKE_CURRENT_LIST_DIR}/GoogleTest.cmake) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index 48d5de4..de20049 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -396,6 +396,45 @@ macro( _HDF5_parse_compile_line endforeach() endmacro() +# Select a preferred imported configuration from a target +function(_HDF5_select_imported_config target imported_conf) + # We will first assign the value to a local variable _imported_conf, then assign + # it to the function argument at the end. + get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) + if (NOT _imported_conf) + # Get available imported configurations by examining target properties + get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) + if(HDF5_FIND_DEBUG) + message(STATUS "Found imported configurations: ${_imported_conf}") + endif() + # Find the imported configuration that we prefer. + # We do this by making list of configurations in order of preference, + # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf + set(_preferred_confs ${CMAKE_BUILD_TYPE}) + list(GET _imported_conf 0 _fallback_conf) + list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) + if(HDF5_FIND_DEBUG) + message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") + endif() + # Now find the first of these that is present in imported_conf + cmake_policy(PUSH) + cmake_policy(SET CMP0057 NEW) # support IN_LISTS + foreach (_conf IN LISTS _preferred_confs) + if (${_conf} IN_LIST _imported_conf) + set(_imported_conf ${_conf}) + break() + endif() + endforeach() + cmake_policy(POP) + endif() + if(HDF5_FIND_DEBUG) + message(STATUS "Selected imported configuration: ${_imported_conf}") + endif() + # assign value to function argument + set(${imported_conf} ${_imported_conf} PARENT_SCOPE) +endfunction() + + if(NOT HDF5_ROOT) set(HDF5_ROOT $ENV{HDF5_ROOT}) endif() @@ -452,30 +491,39 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") endif() # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. - get_target_property(_imported_conf ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_CONFIGURATIONS) - get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} ) - if (NOT _lang_location) + _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_location) # no import lib, just try LOCATION - get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_lang_location) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() endif() - if( _lang_location ) - set(HDF5_${_lang}_LIBRARY ${_lang_location}) + if( _hdf5_lang_location ) + set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) set(HDF5_${_lang}_FOUND True) endif() if(FIND_HL) - get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} ) - if (NOT _lang_hl_location) - get_target_property(_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_hl_location) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_hl_lang_location) + get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() endif() - if( _lang_hl_location ) - set(HDF5_${_lang}_HL_LIBRARY ${_lang_hl_location}) - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) - set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + if( _hdf5_lang_hl_location ) + set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) set(HDF5_HL_FOUND True) endif() + unset(_hdf5_lang_hl_location) endif() + unset(_hdf5_imported_conf) + unset(_hdf5_lang_location) endforeach() endif() endif() @@ -873,11 +921,14 @@ if (HDF5_FIND_DEBUG) message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS) message(STATUS "HDF5_${__lang}_DEFINITIONS: ${HDF5_${__lang}_DEFINITIONS}") message(STATUS "HDF5_${__lang}_INCLUDE_DIR: ${HDF5_${__lang}_INCLUDE_DIR}") message(STATUS "HDF5_${__lang}_INCLUDE_DIRS: ${HDF5_${__lang}_INCLUDE_DIRS}") message(STATUS "HDF5_${__lang}_LIBRARY: ${HDF5_${__lang}_LIBRARY}") message(STATUS "HDF5_${__lang}_LIBRARIES: ${HDF5_${__lang}_LIBRARIES}") + message(STATUS "HDF5_${__lang}_HL_LIBRARY: ${HDF5_${__lang}_HL_LIBRARY}") + message(STATUS "HDF5_${__lang}_HL_LIBRARIES: ${HDF5_${__lang}_HL_LIBRARIES}") endforeach() endif() diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake index d762452..eb2242b 100644 --- a/Modules/FindJava.cmake +++ b/Modules/FindJava.cmake @@ -90,7 +90,7 @@ list(APPEND _JAVA_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.9;JavaHome]/bin" "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.8;JavaHome]/bin" "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.7;JavaHome]/bin" - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\2.6;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.6;JavaHome]/bin" "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.5;JavaHome]/bin" "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.4;JavaHome]/bin" "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.3;JavaHome]/bin" diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake index f68628d..8ac2980 100644 --- a/Modules/FindLibXml2.cmake +++ b/Modules/FindLibXml2.cmake @@ -50,6 +50,13 @@ find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h PATH_SUFFIXES libxml2 ) +# CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of +# the cache entry storing the find_library result. Use the +# value if it was set by the project or user. +if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY) + set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES}) +endif() + find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 HINTS ${PC_LIBXML_LIBDIR} diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 8ac1691..76afa8a 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -323,6 +323,9 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma endif() endif() endif() + if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT CMAKE_CROSSCOMPILING) + list(APPEND _lib_dirs "libdata/pkgconfig") + endif() list(APPEND _lib_dirs "lib/pkgconfig") list(APPEND _lib_dirs "share/pkgconfig") diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index 7415e06..41bd1dc 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -5,7 +5,33 @@ GoogleTest ---------- -This module defines functions to help use the Google Test infrastructure. +This module defines functions to help use the Google Test infrastructure. Two +mechanisms for adding tests are provided. :command:`gtest_add_tests` has been +around for some time, originally via ``find_package(GTest)``. +:command:`gtest_discover_tests` was introduced in CMake 3.10. + +The (older) :command:`gtest_add_tests` scans source files to identify tests. +This is usually effective, with some caveats, including in cross-compiling +environments, and makes setting additional properties on tests more convenient. +However, its handling of parameterized tests is less comprehensive, and it +requires re-running CMake to detect changes to the list of tests. + +The (newer) :command:`gtest_discover_tests` discovers tests by asking the +compiled test executable to enumerate its tests. This is more robust and +provides better handling of parameterized tests, and does not require CMake +to be re-run when tests change. However, it may not work in a cross-compiling +environment, and setting test properties is less convenient. + +More details can be found in the documentation of the respective functions. + +Both commands are intended to replace use of :command:`add_test` to register +tests, and will create a separate CTest test for each Google Test test case. +Note that this is in some cases less efficient, as common set-up and tear-down +logic cannot be shared by multiple test cases executing in the same instance. +However, it provides more fine-grained pass/fail information to CTest, which is +usually considered as more beneficial. By default, the CTest test name is the +same as the Google Test name (i.e. ``suite.testcase``); see also +``TEST_PREFIX`` and ``TEST_SUFFIX``. .. command:: gtest_add_tests @@ -22,12 +48,25 @@ This module defines functions to help use the Google Test infrastructure. [TEST_LIST outVar] ) + ``gtest_add_tests`` attempts to identify tests by scanning source files. + Although this is generally effective, it uses only a basic regular expression + match, which can be defeated by atypical test declarations, and is unable to + fully "split" parameterized tests. Additionally, it requires that CMake be + re-run to discover any newly added, removed or renamed tests (by default, + this means that CMake is re-run when any test source file is changed, but see + ``SKIP_DEPENDENCY``). However, it has the advantage of declaring tests at + CMake time, which somewhat simplifies setting additional properties on tests, + and always works in a cross-compiling environment. + + The options are: + ``TARGET target`` - This must be a known CMake target. CMake will substitute the location of - the built executable when running the test. + Specifies the Google Test executable, which must be a known CMake + executable target. CMake will substitute the location of the built + executable when running the test. ``SOURCES src1...`` - When provided, only the listed files will be scanned for test cases. If + When provided, only the listed files will be scanned for test cases. If this option is not given, the :prop_tgt:`SOURCES` property of the specified ``target`` will be used to obtain the list of sources. @@ -35,31 +74,30 @@ This module defines functions to help use the Google Test infrastructure. Any extra arguments to pass on the command line to each test case. ``WORKING_DIRECTORY dir`` - Specifies the directory in which to run the discovered test cases. If this + Specifies the directory in which to run the discovered test cases. If this option is not provided, the current binary directory is used. ``TEST_PREFIX prefix`` - Allows the specified ``prefix`` to be prepended to the name of each - discovered test case. This can be useful when the same source files are - being used in multiple calls to ``gtest_add_test()`` but with different - ``EXTRA_ARGS``. + Specifies a ``prefix`` to be prepended to the name of each discovered test + case. This can be useful when the same source files are being used in + multiple calls to ``gtest_add_test()`` but with different ``EXTRA_ARGS``. ``TEST_SUFFIX suffix`` Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of - every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` can be - specified. + every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may + be specified. ``SKIP_DEPENDENCY`` Normally, the function creates a dependency which will cause CMake to be - re-run if any of the sources being scanned are changed. This is to ensure - that the list of discovered tests is updated. If this behavior is not + re-run if any of the sources being scanned are changed. This is to ensure + that the list of discovered tests is updated. If this behavior is not desired (as may be the case while actually writing the test cases), this option can be used to prevent the dependency from being added. ``TEST_LIST outVar`` The variable named by ``outVar`` will be populated in the calling scope - with the list of discovered test cases. This allows the caller to do things - like manipulate test properties of the discovered tests. + with the list of discovered test cases. This allows the caller to do + things like manipulate test properties of the discovered tests. .. code-block:: cmake @@ -77,7 +115,7 @@ This module defines functions to help use the Google Test infrastructure. set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10) set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20) - For backward compatibility reasons, the following form is also supported:: + For backward compatibility, the following form is also supported:: gtest_add_tests(exe args files...) @@ -99,8 +137,89 @@ This module defines functions to help use the Google Test infrastructure. add_executable(FooTest FooUnitTest.cxx) gtest_add_tests(FooTest "${FooTestArgs}" AUTO) +.. command:: gtest_discover_tests + + Automatically add tests with CTest by querying the compiled test executable + for available tests:: + + gtest_discover_tests(target + [EXTRA_ARGS arg1...] + [WORKING_DIRECTORY dir] + [TEST_PREFIX prefix] + [TEST_SUFFIX suffix] + [NO_PRETTY_TYPES] [NO_PRETTY_VALUES] + [PROPERTIES name1 value1...] + [TEST_LIST var] + ) + + ``gtest_discover_tests`` sets up a post-build command on the test executable + that generates the list of tests by parsing the output from running the test + with the ``--gtest_list_tests`` argument. Compared to the source parsing + approach of :command:`gtest_add_tests`, this ensures that the full list of + tests, including instantiations of parameterized tests, is obtained. Since + test discovery occurs at build time, it is not necessary to re-run CMake when + the list of tests changes. + However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set + in order to function in a cross-compiling environment. + + Additionally, setting properties on tests is somewhat less convenient, since + the tests are not available at CMake time. Additional test properties may be + assigned to the set of tests as a whole using the ``PROPERTIES`` option. If + more fine-grained test control is needed, custom content may be provided + through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES` + directory property. The set of discovered tests is made accessible to such a + script via the ``<target>_TESTS`` variable. + + The options are: + + ``target`` + Specifies the Google Test executable, which must be a known CMake + executable target. CMake will substitute the location of the built + executable when running the test. + + ``EXTRA_ARGS arg1...`` + Any extra arguments to pass on the command line to each test case. + + ``WORKING_DIRECTORY dir`` + Specifies the directory in which to run the discovered test cases. If this + option is not provided, the current binary directory is used. + + ``TEST_PREFIX prefix`` + Specifies a ``prefix`` to be prepended to the name of each discovered test + case. This can be useful when the same test executable is being used in + multiple calls to ``gtest_discover_tests()`` but with different + ``EXTRA_ARGS``. + + ``TEST_SUFFIX suffix`` + Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of + every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may + be specified. + + ``NO_PRETTY_TYPES`` + By default, the type index of type-parameterized tests is replaced by the + actual type name in the CTest test name. If this behavior is undesirable + (e.g. because the type names are unwieldy), this option will suppress this + behavior. + + ``NO_PRETTY_VALUES`` + By default, the value index of value-parameterized tests is replaced by the + actual value in the CTest test name. If this behavior is undesirable + (e.g. because the value strings are unwieldy), this option will suppress + this behavior. + + ``PROPERTIES name1 value1...`` + Specifies additional properties to be set on all tests discovered by this + invocation of ``gtest_discover_tests``. + + ``TEST_LIST var`` + Make the list of tests available in the variable ``var``, rather than the + default ``<target>_TESTS``. This can be useful when the same test + executable is being used in multiple calls to ``gtest_discover_tests()``. + Note that this variable is only available in CTest. + #]=======================================================================] +#------------------------------------------------------------------------------ function(gtest_add_tests) if (ARGC LESS 1) @@ -224,3 +343,68 @@ function(gtest_add_tests) endif() endfunction() + +#------------------------------------------------------------------------------ +function(gtest_discover_tests TARGET) + cmake_parse_arguments( + "" + "NO_PRETTY_TYPES;NO_PRETTY_VALUES" + "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST" + "EXTRA_ARGS;PROPERTIES" + ${ARGN} + ) + + if(NOT _WORKING_DIRECTORY) + set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + endif() + if(NOT _TEST_LIST) + set(_TEST_LIST ${TARGET}_TESTS) + endif() + + # Define rule to generate test list for aforementioned test executable + set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include.cmake") + set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests.cmake") + get_property(crosscompiling_emulator + TARGET ${TARGET} + PROPERTY CROSSCOMPILING_EMULATOR + ) + add_custom_command( + TARGET ${TARGET} POST_BUILD + BYPRODUCTS "${ctest_tests_file}" + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TARGET=${TARGET}" + -D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>" + -D "TEST_EXECUTOR=${crosscompiling_emulator}" + -D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}" + -D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}" + -D "TEST_PROPERTIES=${_PROPERTIES}" + -D "TEST_PREFIX=${_TEST_PREFIX}" + -D "TEST_SUFFIX=${_TEST_SUFFIX}" + -D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}" + -D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}" + -D "TEST_LIST=${_TEST_LIST}" + -D "CTEST_FILE=${ctest_tests_file}" + -P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}" + VERBATIM + ) + + file(WRITE "${ctest_include_file}" + "if(EXISTS \"${ctest_tests_file}\")\n" + " include(\"${ctest_tests_file}\")\n" + "else()\n" + " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n" + "endif()\n" + ) + + # Add discovered tests to directory TEST_INCLUDE_FILES + set_property(DIRECTORY + APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}" + ) + +endfunction() + +############################################################################### + +set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT + ${CMAKE_CURRENT_LIST_DIR}/GoogleTestAddTests.cmake +) diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake new file mode 100644 index 0000000..7d0d909 --- /dev/null +++ b/Modules/GoogleTestAddTests.cmake @@ -0,0 +1,100 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +set(prefix "${TEST_PREFIX}") +set(suffix "${TEST_SUFFIX}") +set(extra_args ${TEST_EXTRA_ARGS}) +set(properties ${TEST_PROPERTIES}) +set(script) +set(suite) +set(tests) + +function(add_command NAME) + set(_args "") + foreach(_arg ${ARGN}) + if(_arg MATCHES "[^-./:a-zA-Z0-9_]") + set(_args "${_args} [==[${_arg}]==]") + else() + set(_args "${_args} ${_arg}") + endif() + endforeach() + set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) +endfunction() + +# Run test executable to get list of available tests +if(NOT EXISTS "${TEST_EXECUTABLE}") + message(FATAL_ERROR + "Specified test executable '${TEST_EXECUTABLE}' does not exist" + ) +endif() +execute_process( + COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --gtest_list_tests + OUTPUT_VARIABLE output + RESULT_VARIABLE result +) +if(NOT ${result} EQUAL 0) + message(FATAL_ERROR + "Error running test executable '${TEST_EXECUTABLE}':\n" + " Result: ${result}\n" + " Output: ${output}\n" + ) +endif() + +string(REPLACE "\n" ";" output "${output}") + +# Parse output +foreach(line ${output}) + # Skip header + if(NOT line MATCHES "gtest_main\\.cc") + # Do we have a module name or a test name? + if(NOT line MATCHES "^ ") + # Module; remove trailing '.' to get just the name... + string(REGEX REPLACE "\\.( *#.*)?" "" suite "${line}") + if(line MATCHES "#" AND NOT NO_PRETTY_TYPES) + string(REGEX REPLACE "/[0-9]\\.+ +#.*= +" "/" pretty_suite "${line}") + else() + set(pretty_suite "${suite}") + endif() + string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}") + else() + # Test name; strip spaces and comments to get just the name... + string(REGEX REPLACE " +" "" test "${line}") + if(test MATCHES "#" AND NOT NO_PRETTY_VALUES) + string(REGEX REPLACE "/[0-9]+#GetParam..=" "/" pretty_test "${test}") + else() + string(REGEX REPLACE "#.*" "" pretty_test "${test}") + endif() + string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}") + string(REGEX REPLACE "#.*" "" test "${test}") + # ...and add to script + add_command(add_test + "${prefix}${pretty_suite}.${pretty_test}${suffix}" + ${TEST_EXECUTOR} + "${TEST_EXECUTABLE}" + "--gtest_filter=${suite}.${test}" + "--gtest_also_run_disabled_tests" + ${extra_args} + ) + if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED") + add_command(set_tests_properties + "${prefix}${pretty_suite}.${pretty_test}${suffix}" + PROPERTIES DISABLED TRUE + ) + endif() + add_command(set_tests_properties + "${prefix}${pretty_suite}.${pretty_test}${suffix}" + PROPERTIES + WORKING_DIRECTORY "${TEST_WORKING_DIR}" + ${properties} + ) + list(APPEND tests "${prefix}${pretty_suite}.${pretty_test}${suffix}") + endif() + endif() +endforeach() + +# Create a list of all discovered tests, which users may use to e.g. set +# properties on the tests +add_command(set ${TEST_LIST} ${tests}) + +# Write CTest script +file(WRITE "${CTEST_FILE}" "${script}") diff --git a/Modules/Platform/Android-Common.cmake b/Modules/Platform/Android-Common.cmake index 5faada3..80a8f41 100644 --- a/Modules/Platform/Android-Common.cmake +++ b/Modules/Platform/Android-Common.cmake @@ -160,13 +160,19 @@ macro(__android_compiler_common lang) # Do not do this for a standalone toolchain because it is already # tied to a specific API version. if(CMAKE_ANDROID_NDK) + if(CMAKE_SYSROOT_COMPILE) + set(_cmake_sysroot_compile "${CMAKE_SYSROOT_COMPILE}") + else() + set(_cmake_sysroot_compile "${CMAKE_SYSROOT}") + endif() if(NOT CMAKE_ANDROID_NDK_DEPRECATED_HEADERS) list(APPEND CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES - "${CMAKE_SYSROOT_COMPILE}/usr/include" - "${CMAKE_SYSROOT_COMPILE}/usr/include/${CMAKE_ANDROID_ARCH_HEADER_TRIPLE}" + "${_cmake_sysroot_compile}/usr/include" + "${_cmake_sysroot_compile}/usr/include/${CMAKE_ANDROID_ARCH_HEADER_TRIPLE}" ) else() - list(APPEND CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES "${CMAKE_SYSROOT}/usr/include") + list(APPEND CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES "${_cmake_sysroot_compile}/usr/include") endif() + unset(_cmake_sysroot_compile) endif() endmacro() diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 456a6bd..c8b1cd7 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -121,8 +121,10 @@ macro(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile) endif() foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSIONS}) - set(${outfiles} ${${outfiles}} - "${generatedpath}/${SWIG_GET_EXTRA_OUTPUT_FILES_module_basename}${it}") + set(extra_file "${generatedpath}/${SWIG_GET_EXTRA_OUTPUT_FILES_module_basename}${it}") + list(APPEND ${outfiles} ${extra_file}) + # Treat extra outputs as plain files regardless of language. + set_property(SOURCE "${extra_file}" PROPERTY LANGUAGE "") endforeach() endmacro() |