Hi,
Yes, the deal_ii_setup_target() macro sets compile flags on the target.
For context, the entire
find_package(deal.II ...)
deal_ii_initialize_cached_variables()
project(... CXX)
deal_ii_invoke_autopilot() or deal_ii_setup_target()
is meant for simple projects where we will set up compiler, compiler
flags, debug and release flavors and some custom targets.
If you don't want that behavior, then you cannot use the
deal_ii_initialize_cached_variables() / deal_ii_invoke_autopilot(), or
deal_ii_setup_target() macros.
I suggest to simply write a custom CMakeLists.txt as follows:
make_minimum_required(VERSION 3.20)
set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb" CACHE STRING "")
set(CMAKE_CXX_FLAGS_RELEASE "-O3" CACHE STRING "")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "")
project(step CXX)
# call find_package after project() so that targets get included:
find_package(deal.II 9.7.0 REQUIRED
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
add_executable(test test.cc)
target_link_libraries(test dealii::dealii_release)
This will allow you to switch between Debug and Release build will
always linking against the release library. Similarly, you can always
link against the debug library via
target_link_libraries(test dealii::dealii_debug)
or switch between the two depending on Debug / release via
target_link_libraries(test debug dealii::dealii_debug optimized dealii::dealii_release)
Important: the dealii::dealii_debug and dealii::dealii_release targets
will enforce preprocessor definitions and compile flags that are
necessary for ABI compatiblity. That means if you compile and link
against the debug variant of deal.II we will force -DDEBUG and if you
compile and link against the release variant of deal.II we will force
-DNDEBUG.
So, use a different preprocessor macro to compile in your debug code
paths - you cannot use "#ifdef DEBUG" when compiling against the deal.II
release variant.
Best,
Matthias