@@ -31,8 +31,6 @@ endif()
3131# To preserve RPATH when installing
3232set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
3333
34- option (BUILD_SHARED_LIBS "Builds shared libraries using CMake conventions" OFF )
35-
3634option (USE_CLANG_TIDY "Enable clang-tidy static code analysis" OFF )
3735# Enable clang-tidy if USE_CLANG_TIDY is ON
3836if (USE_CLANG_TIDY)
@@ -80,14 +78,41 @@ endif()
8078
8179find_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)
8492target_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
92117option (OpenPFC_BUILD_APPS "Build OpenPFC applications" ON )
93118option (OpenPFC_BUILD_EXAMPLES "Build OpenPFC examples" ON )
@@ -120,12 +145,10 @@ endif()
120145
121146if (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)
125150endif ()
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
143177install (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
0 commit comments