Skip to content

Commit

Permalink
Create dealii::dealii target and add compile options
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Mar 30, 2023
1 parent d19e53a commit a82dd4c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/step-1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(TARGET_SRC
# Usually, you will not need to modify anything beyond this point...

cmake_minimum_required(VERSION 3.13.4)
project(${TARGET})

find_package(deal.II 9.5.0
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
Expand All @@ -34,6 +35,5 @@ if(NOT ${deal.II_FOUND})
)
endif()

deal_ii_initialize_cached_variables()
project(${TARGET})
deal_ii_invoke_autopilot()
add_executable(${TARGET} ${TARGET_SRC})
target_link_libraries(${TARGET} dealii::dealii)
46 changes: 46 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,27 @@ add_subdirectory(sundials)
add_subdirectory(trilinos)
add_subdirectory(arborx)

#
# Define a "dealii", i.e., "${DEAL_II_TARGET_NAME}", target that contains
# DEAL_II_CXX_FLAGS[_DEBUG|_RELEASE] and otherwsie aliases dealii_debug or
# dealii_release depending on the downstream CMAKE_BUILD_TYPE.
#

add_library(${DEAL_II_TARGET_NAME} INTERFACE)
separate_arguments(_compile_options UNIX_COMMAND "${DEAL_II_CXX_FLAGS}")
shell_escape_option_groups(_compile_options)
target_compile_options(${DEAL_II_TARGET_NAME} INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:${_compile_options}>
)


foreach(build ${DEAL_II_BUILD_TYPES})
string(TOLOWER ${build} build_lowercase)
if("${build}" MATCHES "DEBUG")
set(build_camelcase "Debug")
elseif("${build}" MATCHES "RELEASE")
set(build_camelcase "Release")
endif()

#
# Combine all ${build} OBJECT targets to a ${build} library:
Expand Down Expand Up @@ -127,6 +146,14 @@ foreach(build ${DEAL_II_BUILD_TYPES})
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DEAL_II_EXECUTABLE_RELDIR}"
)

separate_arguments(_compile_options UNIX_COMMAND
"${DEAL_II_CXX_FLAGS_${build}}"
)
shell_escape_option_groups(_compile_options)
target_compile_options(${DEAL_II_TARGET_NAME} INTERFACE
"$<$<CONFIG:${build_camelcase}>:$<$<COMPILE_LANGUAGE:CXX>:${_compile_options}>>"
)

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set_target_properties(${DEAL_II_TARGET_NAME}_${build_lowercase}
PROPERTIES
Expand Down Expand Up @@ -170,8 +197,27 @@ foreach(build ${DEAL_II_BUILD_TYPES})
LIBRARY DESTINATION ${DEAL_II_LIBRARY_RELDIR}
ARCHIVE DESTINATION ${DEAL_II_LIBRARY_RELDIR}
)

target_link_libraries(${DEAL_II_TARGET_NAME} INTERFACE
"$<$<CONFIG:${build_camelcase}>:${DEAL_II_TARGET_NAME}::${DEAL_II_TARGET_NAME}_${build_lowercase}>"
)
endforeach()

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR})
export(TARGETS ${DEAL_II_TARGET_NAME}
NAMESPACE "${DEAL_II_TARGET_NAME}::"
FILE ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake
APPEND
)

install(TARGETS ${DEAL_II_TARGET_NAME}
COMPONENT library
EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets
RUNTIME DESTINATION ${DEAL_II_EXECUTABLE_RELDIR}
LIBRARY DESTINATION ${DEAL_II_LIBRARY_RELDIR}
ARCHIVE DESTINATION ${DEAL_II_LIBRARY_RELDIR}
)

install(EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets
NAMESPACE "${DEAL_II_TARGET_NAME}::"
DESTINATION ${DEAL_II_PROJECT_CONFIG_RELDIR}
Expand Down

0 comments on commit a82dd4c

Please sign in to comment.