Skip to content

Commit

Permalink
build: add back compiler flags using library interface as in kokkos#12
Browse files Browse the repository at this point in the history
  • Loading branch information
dssgabriel committed Sep 19, 2024
1 parent 4d7526c commit 22bd01f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
57 changes: 39 additions & 18 deletions src/KokkosComm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

set(TARGET_LIBRARY kokkoscomm)

include(${PROJECT_SOURCE_DIR}/cmake/flags.cmake)

add_library(KokkosComm INTERFACE)
add_library(KokkosComm::KokkosComm ALIAS KokkosComm)

Expand All @@ -41,6 +39,16 @@ target_sources(
FILES impl/KokkosComm_contiguous.hpp
)

# Configuration header
target_sources(
KokkosComm
INTERFACE
FILE_SET kokkoscomm_config_headers
TYPE HEADERS
BASE_DIRS ${CMAKE_BINARY_DIR}/src
FILES ${PROJECT_BINARY_DIR}/src/KokkosComm/config.hpp
)

if(KOKKOSCOMM_ENABLE_MPI)
# Public MPI headers
target_sources(
Expand Down Expand Up @@ -75,31 +83,44 @@ if(KOKKOSCOMM_ENABLE_MPI)
)
endif()

target_sources(
KokkosComm
INTERFACE
FILE_SET kokkoscomm_config_headers
TYPE HEADERS
BASE_DIRS ${CMAKE_BINARY_DIR}/src
FILES ${PROJECT_BINARY_DIR}/src/KokkosComm/config.hpp
)
# --- COMPILE FLAGS --- #
include(CheckCXXCompilerFlag)

macro(kokkoscomm_check_and_add_compile_options)
set(target ${ARGV0})
set(flag ${ARGV1})

check_cxx_compiler_flag(${flag} HAS_${flag})
if(HAS_${flag})
target_compile_options(${target} INTERFACE ${flag})
endif()
endmacro()

# Compile flags & features
kokkoscomm_add_cxx_flags(TARGET KokkosComm INTERFACE)
# KokkosComm is a C++20 project
add_library(KokkosCommFlags INTERFACE)
add_library(KokkosComm::KokkosCommFlags ALIAS KokkosCommFlags)
target_compile_features(KokkosCommFlags INTERFACE cxx_std_20)
set_target_properties(KokkosCommFlags PROPERTIES CXX_EXTENSIONS OFF)

kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wall)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wextra)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wshadow)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wpedantic)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -pedantic)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wcast-align)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wformat=2)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wmissing-include-dirs)
kokkoscomm_check_and_add_compile_options(KokkosCommFlags -Wno-gnu-zero-variadic-macro-arguments)

# Linking
target_link_libraries(KokkosComm INTERFACE Kokkos::kokkos)
target_link_libraries(KokkosComm INTERFACE KokkosComm::KokkosCommFlags Kokkos::kokkos)
if(KOKKOSCOMM_ENABLE_MPI)
target_link_libraries(KokkosComm INTERFACE MPI::MPI_CXX)
endif()

# -- PACKAGING -- #
include(GNUInstallDirs)

# Install library
install(
TARGETS
${PROJECT_NAME}
TARGETS KokkosComm KokkosCommFlags
EXPORT KokkosCommTargets
FILE_SET
kokkoscomm_public_headers
Expand Down
3 changes: 0 additions & 3 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ target_sources(
mpi/test_reduce.cpp
mpi/test_allgather.cpp
)
if(KOKKOSCOMM_ENABLE_TESTS)
kokkoscomm_add_cxx_flags(TARGET test-main)
endif()
target_link_libraries(
test-main
PRIVATE
Expand Down

0 comments on commit 22bd01f

Please sign in to comment.