Skip to content
Snippets Groups Projects
Commit a9cb8e74 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Add a policy to deactivate add_all_flags

parent 79ce41c1
No related branches found
No related tags found
1 merge request!1207Remove add_dune_all_flags from dune_add_test
......@@ -20,6 +20,9 @@ include(DuneMacros)
# deactivate global include-directories for dune-common
dune_policy(SET DP_DEFAULT_INCLUDE_DIRS NEW)
# deactivate global calls to add_dune_all_flags in tests
dune_policy(SET DP_TEST_ADD_ALL_FLAGS NEW)
# start a dune project with information from dune.module
dune_project()
......
......@@ -192,17 +192,11 @@
# place to make it easy to construct regular expressions from the label
# names for :code:`ctest -L ${label_regex}`.
#
# .. cmake_param:: NO_LINK_PROJECT_LIBRARIES
# .. cmake_param:: NO_ADD_ALL_FLAGS
# :option:
#
# Disable the automatic linking of all <ProjectName>_INTERFACE_LIBRARIES
# and instead just link against `Dune::Common`.
#
# .. cmake_param:: NO_ADD_DUNE_ALL_FLAGS
# :option:
#
# Disable the call to :ref:`add_dune_all_flags` for the test target. This
# call can be globally enabled by the variable `DUNE_ADD_TEST_ADD_DUNE_ALL_FLAGS`
# Disable the call to :ref:`add_dune_all_flags` for the test target if
# activated globally by the Dune policy `DP_TEST_ADD_ALL_FLAGS=OLD`.
#
# This function defines the Dune way of adding a test to the testing suite.
# You may either add the executable yourself through :ref:`add_executable`
......@@ -222,11 +216,6 @@
# If not in use, you have to build tests through the target :code:`build_tests`. This option
# does not apply on non-mutable targets (i.e., aliased and imported targets).
#
# .. cmake_variable:: DUNE_ADD_TEST_ADD_DUNE_ALL_FLAGS
#
# Globally enable the call to :ref:`add_dune_all_flags` for all test targets
# except for those that are configured with the option `NO_ADD_DUNE_ALL_FLAGS`.
#
# .. cmake_variable:: PYTHON_TEST
#
# This flag specifies a python test and is set by the dune_python_add_test command. It disables the check on the existence of the target file.
......@@ -237,6 +226,10 @@ include_guard(GLOBAL)
enable_testing()
include(CTest)
include(DunePolicy)
dune_define_policy(DP_TEST_ADD_ALL_FLAGS dune-common 2.13
"OLD behavior: Automatically call add_dune_all_flags on all test targets. NEW behavior: flags must be set for each test target separately, e.g., using add_dune_pkg_flags, or in directory scope using dune_enable_all_packages.")
# Introduce a target that triggers the building of all tests
add_custom_target(build_tests)
......@@ -274,7 +267,7 @@ if(NOT DUNE_MAX_TEST_CORES)
endif()
function(dune_add_test)
set(OPTIONS EXPECT_COMPILE_FAIL EXPECT_FAIL SKIP_ON_77 COMPILE_ONLY PYTHON_TEST NO_LINK_PROJECT_LIBRARIES NO_ADD_DUNE_ALL_FLAGS)
set(OPTIONS EXPECT_COMPILE_FAIL EXPECT_FAIL SKIP_ON_77 COMPILE_ONLY PYTHON_TEST NO_ADD_ALL_FLAGS)
set(SINGLEARGS NAME TARGET TIMEOUT WORKING_DIRECTORY)
set(MULTIARGS SOURCES COMPILE_DEFINITIONS COMPILE_FLAGS LINK_LIBRARIES CMD_ARGS MPI_RANKS COMMAND CMAKE_GUARD LABELS)
cmake_parse_arguments(ADDTEST "${OPTIONS}" "${SINGLEARGS}" "${MULTIARGS}" ${ARGN})
......@@ -361,28 +354,24 @@ function(dune_add_test)
endif()
# add some default libraries to link against
if(NOT ADDTEST_NO_LINK_PROJECT_LIBRARIES)
get_property(PROJECT_INTERFACE_LIBRARIES GLOBAL PROPERTY ${ProjectName}_INTERFACE_LIBRARIES)
if(${PROJECT_INTERFACE_LIBRARIES})
list(APPEND ADDTEST_LINK_LIBRARIES ${PROJECT_INTERFACE_LIBRARIES})
else()
list(APPEND ADDTEST_LINK_LIBRARIES Dune::Common)
endif()
list(REMOVE_DUPLICATES ADDTEST_LINK_LIBRARIES)
endif()
list(APPEND ADDTEST_LINK_LIBRARIES Dune::Common)
list(REMOVE_DUPLICATES ADDTEST_LINK_LIBRARIES)
# Add the executable if it is not already present
if(ADDTEST_SOURCES)
add_executable(${ADDTEST_NAME} ${ADDTEST_SOURCES})
if(DUNE_ADD_TEST_ADD_DUNE_ALL_FLAGS AND NOT NO_ADD_DUNE_ALL_FLAGS)
# add all flags to the target!
# add all flags to the target if corresponding policy is OLD and not explicitly disabled.
dune_policy(GET DP_TEST_ADD_ALL_FLAGS _add_all_flags)
if(_add_all_flags STREQUAL "OLD" AND NOT NO_ADD_ALL_FLAGS)
add_dune_all_flags(${ADDTEST_NAME})
endif()
unset(_add_all_flags)
# This is just a placeholder
target_compile_definitions(${ADDTEST_NAME} PUBLIC ${ADDTEST_COMPILE_DEFINITIONS})
target_compile_options(${ADDTEST_NAME} PUBLIC ${ADDTEST_COMPILE_FLAGS})
target_link_libraries(${ADDTEST_NAME} PUBLIC ${ADDTEST_LINK_LIBRARIES})
target_link_libraries(${ADDTEST_NAME} PRIVATE ${DUNE_LIBS})
set(ADDTEST_TARGET ${ADDTEST_NAME})
endif()
......
......@@ -216,6 +216,12 @@ Policies Introduced by Dune 2.10
If the module follows a common directory layout, a default set of include directories
can be set on a target at once using the CMake function ``dune_default_include_directories(<target> <scope>)``.
Policies Introduced by Dune 2.11
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``DP_TEST_ADD_ALL_FLAGS`` (dune-common, set to NEW by default in version 2.13)
*OLD behavior:* Automatically call ``add_dune_all_flags`` on all test targets inside of ``dune_add_test``.
*NEW behavior:* Flags must be set for each test target separately, e.g., by using ``add_dune_pkg_flags``, or in directory scope using ``dune_enable_all_packages``.
.. _faq:
......
......@@ -48,6 +48,7 @@ try
//
// dune_add_test(NAME assertandreturntest_runtime_fail
// SOURCES assertandreturntest.cc
// LINK_LIBRARIES dunecommon
// COMPILE_DEFINITIONS "TEST_RUNTIME_FAIL"
// EXPECT_FAIL
// LABELS quick)
......
......@@ -13,8 +13,21 @@ add_python_targets(common
project
utility
)
dune_add_pybind11_module(NAME _common)
dune_add_pybind11_module(NAME _common SOURCES _common.cc)
target_link_libraries(_common PUBLIC Dune::Common)
if( DUNE_ENABLE_PYTHONMODULE_PRECOMPILE )
foreach(FV_NUM RANGE 0 4)
add_library(registerfvector_${FV_NUM} OBJECT registerfvector.cc)
target_compile_definitions(registerfvector_${FV_NUM} PRIVATE FV_NUM=${FV_NUM})
target_link_libraries(registerfvector_${FV_NUM} PRIVATE Dune::Common)
# Register the object in the pybind11 module _common
target_link_libraries(_common PRIVATE registerfvector_${FV_NUM})
endforeach()
endif()
if(SKBUILD)
install(TARGETS _common LIBRARY DESTINATION python/dune/common)
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment