Skip to content

Commit f570f5a

Browse files
committed
Make CMakeFiles.txt compatible with source files
1 parent 8faa4c0 commit f570f5a

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

CMakeLists.txt

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ endif()
3131
# To preserve RPATH when installing
3232
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
3333

34-
option(BUILD_SHARED_LIBS "Builds shared libraries using CMake conventions" OFF)
35-
3634
option(USE_CLANG_TIDY "Enable clang-tidy static code analysis" OFF)
3735
# Enable clang-tidy if USE_CLANG_TIDY is ON
3836
if(USE_CLANG_TIDY)
@@ -80,14 +78,41 @@ endif()
8078

8179
find_package(nlohmann_json REQUIRED)
8280

83-
add_library(OpenPFC INTERFACE)
81+
option(BUILD_SHARED_LIBS "Build OpenPFC as a shared library" OFF)
82+
83+
# Create library
84+
add_library(OpenPFC
85+
src/openpfc/world.cpp
86+
# src/openpfc/core/decomposition.cpp
87+
# src/openpfc/core/fft.cpp
88+
# Add more .cpp files as you go
89+
)
90+
91+
# Public API (headers)
8492
target_include_directories(OpenPFC
85-
INTERFACE
86-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
87-
$<INSTALL_INTERFACE:include>
88-
)
89-
target_link_libraries(OpenPFC INTERFACE Heffte::Heffte MPI::MPI_CXX)
90-
target_compile_features(OpenPFC INTERFACE cxx_std_17)
93+
PUBLIC
94+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
95+
$<INSTALL_INTERFACE:include>
96+
)
97+
98+
# Options
99+
option(OpenPFC_ENABLE_MPI "Enable MPI support" ON)
100+
option(OpenPFC_ENABLE_HEFFTE "Enable HeFFTe FFT support" ON)
101+
102+
# Conditionally find MPI
103+
if(OpenPFC_ENABLE_MPI)
104+
find_package(MPI REQUIRED)
105+
target_link_libraries(OpenPFC PUBLIC MPI::MPI_CXX)
106+
endif()
107+
108+
# Conditionally find HeFFTe
109+
if(OpenPFC_ENABLE_HEFFTE)
110+
find_package(Heffte REQUIRED)
111+
target_link_libraries(OpenPFC PUBLIC Heffte::Heffte)
112+
endif()
113+
114+
# Require C++17
115+
target_compile_features(OpenPFC PUBLIC cxx_std_17)
91116

92117
option(OpenPFC_BUILD_APPS "Build OpenPFC applications" ON)
93118
option(OpenPFC_BUILD_EXAMPLES "Build OpenPFC examples" ON)
@@ -120,12 +145,10 @@ endif()
120145

121146
if(OpenPFC_ENABLE_CODE_COVERAGE)
122147
message(STATUS "📊 Enabling code coverage")
123-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
124-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
148+
target_compile_options(OpenPFC PUBLIC --coverage)
149+
target_link_options(OpenPFC PUBLIC --coverage)
125150
endif()
126151

127-
install(DIRECTORY include/openpfc DESTINATION include)
128-
129152
# Install nlohmann_json headers, but only if nlohmann_json_SOURCE_DIR is
130153
# defined, i.e. the package is built from source during the configure step.
131154
# This is to avoid installing the headers if the package is installed from
@@ -139,10 +162,22 @@ endif()
139162

140163
# generate cmake file containing code to import all targets
141164

142-
install(TARGETS OpenPFC EXPORT OpenPFCTargets DESTINATION include)
165+
# Install headers
166+
install(DIRECTORY include/openpfc DESTINATION include)
167+
168+
# Install library binary
169+
install(TARGETS OpenPFC
170+
EXPORT OpenPFCTargets
171+
ARCHIVE DESTINATION lib # .a files
172+
LIBRARY DESTINATION lib # .so files
173+
RUNTIME DESTINATION bin # executable files (not needed now but future proof)
174+
)
175+
176+
# Install CMake config file
143177
install(EXPORT OpenPFCTargets
144-
FILE OpenPFCTargets.cmake
145-
DESTINATION lib/cmake/OpenPFC
178+
FILE OpenPFCTargets.cmake
179+
NAMESPACE OpenPFC::
180+
DESTINATION lib/cmake/OpenPFC
146181
)
147182

148183
# generate config and write package config

nix/openpfc/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ stdenv.mkDerivation {
2626
"-DOpenPFC_BUILD_EXAMPLES=${if enableExamples then "ON" else "OFF"}"
2727
"-DOpenPFC_BUILD_APPS=${if enableApps then "ON" else "OFF"}"
2828
"-DOpenPFC_BUILD_DOCUMENTATION=${if enableDocs then "ON" else "OFF"}"
29+
"-DOpenPFC_ENABLE_CODE_COVERAGE=OFF"
2930
"-DHeffte_DIR=${heffte}/lib/cmake/Heffte"
3031
];
3132
}

tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ add_executable(openpfc-tests
1919
test_multi_index.cpp
2020
test_simulator.cpp
2121
test_time.cpp)
22+
2223
target_link_libraries(openpfc-tests PRIVATE OpenPFC Catch2::Catch2)
2324

25+
if(OpenPFC_ENABLE_CODE_COVERAGE)
26+
target_compile_options(openpfc-tests PUBLIC --coverage)
27+
target_link_options(openpfc-tests PUBLIC --coverage)
28+
endif()
29+
2430
# Disable automatic test discovery during the build
2531
# Comment out or remove the following line:
2632
# catch_discover_tests(openpfc-tests)

0 commit comments

Comments
 (0)