diff options
-rw-r--r-- | build_settings.cmake | 3 | ||||
-rw-r--r-- | functions.cmake | 19 |
2 files changed, 14 insertions, 8 deletions
diff --git a/build_settings.cmake b/build_settings.cmake index 7898ccf00fc..59f73dc3e70 100644 --- a/build_settings.cmake +++ b/build_settings.cmake @@ -3,6 +3,9 @@ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") set(OS_IS_MACOSX true) endif() +# Build options +# Whether to build unit tests as part of the 'all' target +set(EXCLUDE_TESTS_FROM_ALL FALSE CACHE BOOL "If TRUE, do not build tests as part of the 'all' target") # Warnings set(WARN_OPTS "-Wuninitialized -Werror -Wall -W -Wchar-subscripts -Wcomment -Wformat -Wparentheses -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings") diff --git a/functions.cmake b/functions.cmake index c75a454923b..46b8083b94c 100644 --- a/functions.cmake +++ b/functions.cmake @@ -192,7 +192,7 @@ endfunction() function(vespa_add_executable TARGET) cmake_parse_arguments(ARG - "" + "TEST" "INSTALL;OUTPUT_NAME" "DEPENDS;AFTER;SOURCES" ${ARGN}) @@ -201,6 +201,16 @@ function(vespa_add_executable TARGET) add_executable(${TARGET} ${ARG_SOURCES}) __add_dependencies_to_target() + # If this is a test executable, add it to the test target for this module + # If building of unit tests is not specified, exclude this target from the all target + if(ARG_TEST) + __add_test_target_to_module(${TARGET}) + + if(EXCLUDE_TESTS_FROM_ALL) + set_target_properties(${TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() + endif() + if(ARG_INSTALL) install(TARGETS ${TARGET} DESTINATION ${ARG_INSTALL}) endif() @@ -344,13 +354,6 @@ function(vespa_add_test) separate_arguments(ARG_COMMAND) endif() - # If there exists a target with the same name as the test, exclude the target from the "all" target - # Instead, add it to the test target for this module - if (TARGET ${ARG_NAME}) - set_target_properties(${ARG_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE) - __add_test_target_to_module(${ARG_NAME}) - endif() - add_test(NAME ${ARG_NAME} COMMAND ${ARG_COMMAND} WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY}) if(ARG_ENVIRONMENT) |