From a1d6d8f7259ade901a87b33edbef8b31bffb5e26 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Fri, 6 Feb 2015 11:31:19 +0000 Subject: Document when modules were added to ECM. --- modules/ECMAddTests.cmake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/ECMAddTests.cmake') diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index ed1e0f66..de06315d 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -36,6 +36,8 @@ # This is a convenient version of ecm_add_test() for when you have many tests # that consist of a single source file each. It behaves like calling # ecm_add_test() once for each source file, with the same named arguments. +# +# Since pre-1.0.0. #============================================================================= # Copyright 2013 Alexander Richardson -- cgit v1.2.1 From 1b636b43d2bf4dca0332a2e2b36affa67fbe1e0b Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Mon, 11 May 2015 13:56:28 +0100 Subject: Add unit tests for ECMAddTests module. REVIEW: 123722 --- modules/ECMAddTests.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'modules/ECMAddTests.cmake') diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index de06315d..bdb60691 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -23,9 +23,13 @@ # give an indication of where to look for a failing test. # # If the flag GUI is passed the test binary will be a GUI executable, otherwise -# the resulting binary will be a console application. The test will be linked +# the resulting binary will be a console application (regardless of the value +# of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). The test will be linked # against the libraries and/or targets passed to LINK_LIBRARIES. # +# The generated target executable will have the effects of ecm_mark_as_test() +# (from the :module:`ECMMarkAsTest` module) applied to it. +# # # :: # @@ -52,6 +56,7 @@ # (To distribute this file outside of extra-cmake-modules, substitute the full # License text for the above reference.) +include(CMakeParseArguments) include(ECMMarkAsTest) include(ECMMarkNonGuiExecutable) @@ -73,7 +78,11 @@ function(ecm_add_test) endif() set(_testname "${ECM_ADD_TEST_NAME_PREFIX}${_targetname}") - add_executable(${_targetname} ${_sources}) + set(gui_args) + if(ECM_ADD_TEST_GUI) + set(gui_args WIN32 MACOSX_BUNDLE) + endif() + add_executable(${_targetname} ${gui_args} ${_sources}) if(NOT ECM_ADD_TEST_GUI) ecm_mark_nongui_executable(${_targetname}) endif() -- cgit v1.2.1 From 0c224194ea7f12eaed32af746fc9138537f1919c Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Mon, 11 May 2015 13:56:28 +0100 Subject: Add PROPERTIES argument to ecm_add_test and ecm_add_tests. This is particularly useful with ecm_add_tests, where you may want to force a suite of tests to run in serial, or alter the timeout for multiple tests at once. BUG: 345797 REVIEW: 123722 --- modules/ECMAddTests.cmake | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/ECMAddTests.cmake') diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index bdb60691..ee7e63e3 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -9,7 +9,8 @@ # ecm_add_test( LINK_LIBRARIES [ [...]] # [TEST_NAME ] # [NAME_PREFIX ] -# [GUI]) +# [GUI] +# [PROPERTIES [ [...]]]) # # Add a new unit test using the passed source files. The parameter TEST_NAME is # used to set the name of the resulting test, and the target built for and run @@ -27,6 +28,8 @@ # of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). The test will be linked # against the libraries and/or targets passed to LINK_LIBRARIES. # +# The PROPERTIES argument sets the given properties on the test. +# # The generated target executable will have the effects of ecm_mark_as_test() # (from the :module:`ECMMarkAsTest` module) applied to it. # @@ -35,7 +38,8 @@ # # ecm_add_tests( LINK_LIBRARIES [ [...]] # [NAME_PREFIX ] -# [GUI]) +# [GUI] +# [PROPERTIES [ [...]]]) # # This is a convenient version of ecm_add_test() for when you have many tests # that consist of a single source file each. It behaves like calling @@ -63,7 +67,7 @@ include(ECMMarkNonGuiExecutable) function(ecm_add_test) set(options GUI) set(oneValueArgs TEST_NAME NAME_PREFIX) - set(multiValueArgs LINK_LIBRARIES) + set(multiValueArgs LINK_LIBRARIES PROPERTIES) cmake_parse_arguments(ECM_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(_sources ${ECM_ADD_TEST_UNPARSED_ARGUMENTS}) list(LENGTH _sources _sourceCount) @@ -89,12 +93,15 @@ function(ecm_add_test) add_test(NAME ${_testname} COMMAND ${_targetname}) target_link_libraries(${_targetname} ${ECM_ADD_TEST_LINK_LIBRARIES}) ecm_mark_as_test(${_targetname}) + if (ECM_ADD_TEST_PROPERTIES) + set_tests_properties(${_testname} PROPERTIES ${ECM_ADD_TEST_PROPERTIES}) + endif() endfunction() function(ecm_add_tests) set(options GUI) set(oneValueArgs NAME_PREFIX) - set(multiValueArgs LINK_LIBRARIES) + set(multiValueArgs LINK_LIBRARIES PROPERTIES) cmake_parse_arguments(ECM_ADD_TESTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(ECM_ADD_TESTS_GUI) set(_exe_type GUI) @@ -106,6 +113,7 @@ function(ecm_add_tests) NAME_PREFIX ${ECM_ADD_TESTS_NAME_PREFIX} LINK_LIBRARIES ${ECM_ADD_TESTS_LINK_LIBRARIES} ${_exe_type} + PROPERTIES ${ECM_ADD_TESTS_PROPERTIES} ) endforeach() endfunction() -- cgit v1.2.1 From 70b13693478b296b8a3cd1654baa8013434358c5 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Sat, 16 May 2015 14:06:34 +0100 Subject: Revert "Add PROPERTIES argument to ecm_add_test and ecm_add_tests." This reverts commit 0c224194ea7f12eaed32af746fc9138537f1919c. Stephen Kelly pointed out that this is probably not the best approach to the problem, and runs counter to the direction KDE's CMake code has been going (splitting functions up and using CMake built-ins where possible). I have a better solution in mind, which I'll post a review for later. CCMAIL: kde-buildsystem@kde.org CCBUG: 345797 --- modules/ECMAddTests.cmake | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'modules/ECMAddTests.cmake') diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index ee7e63e3..bdb60691 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -9,8 +9,7 @@ # ecm_add_test( LINK_LIBRARIES [ [...]] # [TEST_NAME ] # [NAME_PREFIX ] -# [GUI] -# [PROPERTIES [ [...]]]) +# [GUI]) # # Add a new unit test using the passed source files. The parameter TEST_NAME is # used to set the name of the resulting test, and the target built for and run @@ -28,8 +27,6 @@ # of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). The test will be linked # against the libraries and/or targets passed to LINK_LIBRARIES. # -# The PROPERTIES argument sets the given properties on the test. -# # The generated target executable will have the effects of ecm_mark_as_test() # (from the :module:`ECMMarkAsTest` module) applied to it. # @@ -38,8 +35,7 @@ # # ecm_add_tests( LINK_LIBRARIES [ [...]] # [NAME_PREFIX ] -# [GUI] -# [PROPERTIES [ [...]]]) +# [GUI]) # # This is a convenient version of ecm_add_test() for when you have many tests # that consist of a single source file each. It behaves like calling @@ -67,7 +63,7 @@ include(ECMMarkNonGuiExecutable) function(ecm_add_test) set(options GUI) set(oneValueArgs TEST_NAME NAME_PREFIX) - set(multiValueArgs LINK_LIBRARIES PROPERTIES) + set(multiValueArgs LINK_LIBRARIES) cmake_parse_arguments(ECM_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(_sources ${ECM_ADD_TEST_UNPARSED_ARGUMENTS}) list(LENGTH _sources _sourceCount) @@ -93,15 +89,12 @@ function(ecm_add_test) add_test(NAME ${_testname} COMMAND ${_targetname}) target_link_libraries(${_targetname} ${ECM_ADD_TEST_LINK_LIBRARIES}) ecm_mark_as_test(${_targetname}) - if (ECM_ADD_TEST_PROPERTIES) - set_tests_properties(${_testname} PROPERTIES ${ECM_ADD_TEST_PROPERTIES}) - endif() endfunction() function(ecm_add_tests) set(options GUI) set(oneValueArgs NAME_PREFIX) - set(multiValueArgs LINK_LIBRARIES PROPERTIES) + set(multiValueArgs LINK_LIBRARIES) cmake_parse_arguments(ECM_ADD_TESTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(ECM_ADD_TESTS_GUI) set(_exe_type GUI) @@ -113,7 +106,6 @@ function(ecm_add_tests) NAME_PREFIX ${ECM_ADD_TESTS_NAME_PREFIX} LINK_LIBRARIES ${ECM_ADD_TESTS_LINK_LIBRARIES} ${_exe_type} - PROPERTIES ${ECM_ADD_TESTS_PROPERTIES} ) endforeach() endfunction() -- cgit v1.2.1 From 9f96174b61fbc1145fda4cfba573361a0aa8746d Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Mon, 18 May 2015 11:30:10 +0100 Subject: Rework ECMAddTests documentation to emphasis ecm_add_tests(). ecm_add_test is the less useful (and less used) version of the functions (because you really might as well just use add_executable() and add_test() manually in that case). REVIEW: 123841 --- modules/ECMAddTests.cmake | 50 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'modules/ECMAddTests.cmake') diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index bdb60691..cee6da4b 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -2,44 +2,46 @@ # ECMAddTests # ----------- # -# Add test executables. +# Convenience functions for adding tests. # # :: # -# ecm_add_test( LINK_LIBRARIES [ [...]] -# [TEST_NAME ] -# [NAME_PREFIX ] -# [GUI]) +# ecm_add_tests( LINK_LIBRARIES [ [...]] +# [NAME_PREFIX ] +# [GUI]) # -# Add a new unit test using the passed source files. The parameter TEST_NAME is -# used to set the name of the resulting test, and the target built for and run -# by the test. It may be omitted if there is exactly one source file. In that -# case the name of the source file (without the file extension) will be used as -# the test name. +# A convenience function for adding multiple tests, each consisting of a +# single source file. For each file in , an executable target will be +# created (the name of which will be the basename of the source file). This +# will be linked against the libraries given with LINK_LIBRARIES. Each +# executable will be added as a test with the same name. # -# If NAME_PREFIX is given, this prefix will be prepended to the test name, but -# not the target name. As a result, it will not prevent clashes between tests +# If NAME_PREFIX is given, this prefix will be prepended to the test names, but +# not the target names. As a result, it will not prevent clashes between tests # with the same name in different parts of the project, but it can be used to # give an indication of where to look for a failing test. # -# If the flag GUI is passed the test binary will be a GUI executable, otherwise -# the resulting binary will be a console application (regardless of the value -# of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). The test will be linked -# against the libraries and/or targets passed to LINK_LIBRARIES. +# If the flag GUI is passed the test binaries will be GUI executables, otherwise +# the resulting binaries will be console applications (regardless of the value +# of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). Be aware that this changes +# the executable entry point on Windows (although some frameworks, such as Qt, +# abstract this difference away). # -# The generated target executable will have the effects of ecm_mark_as_test() +# The generated target executables will have the effects of ecm_mark_as_test() # (from the :module:`ECMMarkAsTest` module) applied to it. # -# # :: # -# ecm_add_tests( LINK_LIBRARIES [ [...]] -# [NAME_PREFIX ] -# [GUI]) +# ecm_add_test( LINK_LIBRARIES [ [...]] +# [TEST_NAME ] +# [NAME_PREFIX ] +# [GUI]) +# +# This is a single-test form of ecm_add_tests that allows multiple source files +# to be used for a single test. If using multiple source files, TEST_NAME must +# be given; this will be used for both the target and test names (and, as with +# ecm_add_tests(), the NAME_PREFIX argument will be prepended to the test name). # -# This is a convenient version of ecm_add_test() for when you have many tests -# that consist of a single source file each. It behaves like calling -# ecm_add_test() once for each source file, with the same named arguments. # # Since pre-1.0.0. -- cgit v1.2.1 From be390dcc4d77d7faa95d040b1a346ac3c0405eac Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Mon, 18 May 2015 19:12:06 +0100 Subject: Add arguments to ecm_add_tests for listing added tests. This makes it convenient to make further modifications to the tests, such as setting properties on either the tests or the targets. CHANGELOG: New arguments for ecm_add_tests(). BUG: 345797 REVIEW: 123841 --- modules/ECMAddTests.cmake | 62 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'modules/ECMAddTests.cmake') diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake index cee6da4b..e9e2fc53 100644 --- a/modules/ECMAddTests.cmake +++ b/modules/ECMAddTests.cmake @@ -8,7 +8,9 @@ # # ecm_add_tests( LINK_LIBRARIES [ [...]] # [NAME_PREFIX ] -# [GUI]) +# [GUI] +# [TARGET_NAMES_VAR ] +# [TEST_NAMES_VAR ]) # # A convenience function for adding multiple tests, each consisting of a # single source file. For each file in , an executable target will be @@ -27,6 +29,11 @@ # the executable entry point on Windows (although some frameworks, such as Qt, # abstract this difference away). # +# The TARGET_NAMES_VAR and TEST_NAMES_VAR arguments, if given, should specify a +# variable name to receive the list of generated target and test names, +# respectively. This makes it convenient to apply properties to them as a +# whole, for example, using set_target_properties() or set_tests_properties(). +# # The generated target executables will have the effects of ecm_mark_as_test() # (from the :module:`ECMMarkAsTest` module) applied to it. # @@ -47,6 +54,7 @@ #============================================================================= # Copyright 2013 Alexander Richardson +# Copyright 2015 Alex Merry # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file COPYING-CMAKE-SCRIPTS for details. @@ -64,13 +72,15 @@ include(ECMMarkNonGuiExecutable) function(ecm_add_test) set(options GUI) - set(oneValueArgs TEST_NAME NAME_PREFIX) + # TARGET_NAME_VAR and TEST_NAME_VAR are undocumented args used by + # ecm_add_tests + set(oneValueArgs TEST_NAME NAME_PREFIX TARGET_NAME_VAR TEST_NAME_VAR) set(multiValueArgs LINK_LIBRARIES) - cmake_parse_arguments(ECM_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(_sources ${ECM_ADD_TEST_UNPARSED_ARGUMENTS}) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(_sources ${ARG_UNPARSED_ARGUMENTS}) list(LENGTH _sources _sourceCount) - if(ECM_ADD_TEST_TEST_NAME) - set(_targetname ${ECM_ADD_TEST_TEST_NAME}) + if(ARG_TEST_NAME) + set(_targetname ${ARG_TEST_NAME}) elseif(${_sourceCount} EQUAL "1") #use the source file name without extension as the testname get_filename_component(_targetname ${_sources} NAME_WE) @@ -79,35 +89,53 @@ function(ecm_add_test) message(FATAL_ERROR "ecm_add_test() called with multiple source files but without setting \"TEST_NAME\"") endif() - set(_testname "${ECM_ADD_TEST_NAME_PREFIX}${_targetname}") + set(_testname ${ARG_NAME_PREFIX}${_targetname}) set(gui_args) - if(ECM_ADD_TEST_GUI) + if(ARG_GUI) set(gui_args WIN32 MACOSX_BUNDLE) endif() add_executable(${_targetname} ${gui_args} ${_sources}) - if(NOT ECM_ADD_TEST_GUI) + if(NOT ARG_GUI) ecm_mark_nongui_executable(${_targetname}) endif() add_test(NAME ${_testname} COMMAND ${_targetname}) - target_link_libraries(${_targetname} ${ECM_ADD_TEST_LINK_LIBRARIES}) + target_link_libraries(${_targetname} ${ARG_LINK_LIBRARIES}) ecm_mark_as_test(${_targetname}) + if (ARG_TARGET_NAME_VAR) + set(${ARG_TARGET_NAME_VAR} "${_targetname}" PARENT_SCOPE) + endif() + if (ARG_TEST_NAME_VAR) + set(${ARG_TEST_NAME_VAR} "${_testname}" PARENT_SCOPE) + endif() endfunction() function(ecm_add_tests) set(options GUI) - set(oneValueArgs NAME_PREFIX) + set(oneValueArgs NAME_PREFIX TARGET_NAMES_VAR TEST_NAMES_VAR) set(multiValueArgs LINK_LIBRARIES) - cmake_parse_arguments(ECM_ADD_TESTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - if(ECM_ADD_TESTS_GUI) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(ARG_GUI) set(_exe_type GUI) else() set(_exe_type "") endif() - foreach(_test_source ${ECM_ADD_TESTS_UNPARSED_ARGUMENTS}) + set(test_names) + set(target_names) + foreach(_test_source ${ARG_UNPARSED_ARGUMENTS}) ecm_add_test(${_test_source} - NAME_PREFIX ${ECM_ADD_TESTS_NAME_PREFIX} - LINK_LIBRARIES ${ECM_ADD_TESTS_LINK_LIBRARIES} - ${_exe_type} + NAME_PREFIX ${ARG_NAME_PREFIX} + LINK_LIBRARIES ${ARG_LINK_LIBRARIES} + TARGET_NAME_VAR target_name + TEST_NAME_VAR test_name + ${_exe_type} ) + list(APPEND _test_names "${test_name}") + list(APPEND _target_names "${target_name}") endforeach() + if (ARG_TARGET_NAMES_VAR) + set(${ARG_TARGET_NAMES_VAR} "${_target_names}" PARENT_SCOPE) + endif() + if (ARG_TEST_NAMES_VAR) + set(${ARG_TEST_NAMES_VAR} "${_test_names}" PARENT_SCOPE) + endif() endfunction() -- cgit v1.2.1