Skip to content

Commit b747946

Browse files
authored
Merge pull request #219 from jacobmerson/cmake-issues
The file configuration.h.in gets configured to have all of the defines instead of including them in the build process with target_add_definitions. This should make it easier to link against an installed version of pcms if you don't use CMake. Also, makes it easier to see what options pcms was configured with by just looking into that file.
2 parents c6791b3 + 1b0addf commit b747946

File tree

10 files changed

+115
-91
lines changed

10 files changed

+115
-91
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ jobs:
200200
-DPETSC_DIR=${{ runner.temp }}/petsc-openmpi \
201201
-DPETSC_ARCH=ubuntu-kokkos \
202202
-DPCMS_TIMEOUT=10 \
203+
-DPCMS_ENABLE_SPDLOG=OFF \
203204
-DCatch2_DIR=${{ runner.temp }}/build-Catch2-openmpi/install/lib/cmake/Catch2 \
204205
-DOmega_h_DIR=${{ runner.temp }}/build-omega_h-openmpi/install/lib/cmake/Omega_h \
205206
-Dmeshfields_DIR=${{ runner.temp }}/build-meshFields-openmpi/install/lib/cmake/meshfields \
@@ -235,4 +236,4 @@ jobs:
235236
echo "Some C/C++ files have clang-tidy issues. Please fix them with clang-tidy-18."
236237
exit 1
237238
fi
238-
echo "All C/C++ files pass clang-tidy checks"
239+
echo "All C/C++ files pass clang-tidy checks"

.github/workflows/cmake-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ jobs:
201201
-DPETSC_DIR=${{ runner.temp }}/petsc
202202
-DPETSC_ARCH=ubuntu-kokkos
203203
-DPCMS_TIMEOUT=10
204+
-DPCMS_ENABLE_SPDLOG=OFF
204205
-DCatch2_DIR=${{ runner.temp }}/build-Catch2/install/lib/cmake/Catch2
205206
-DOmega_h_DIR=${{ runner.temp }}/build-omega_h/install/lib/cmake/Omega_h
206207
-Dmeshfields_DIR=${{ runner.temp }}/build-meshFields/install/lib/cmake/meshfields

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ option(PCMS_ENABLE_XGC "enable xgc field adapter" ON)
2525
option(PCMS_ENABLE_OMEGA_H "enable Omega_h field adapter" OFF)
2626
option(PCMS_ENABLE_C "Enable pcms C api" ON)
2727

28-
option(PCMS_PRINT_ENABLED "PCMS print statements enabled" ON)
29-
find_package(spdlog QUIET)
28+
option(PCMS_ENABLE_PRINT "PCMS print statements enabled" ON)
29+
option(PCMS_ENABLE_SPDLOG "use spdlog for logging" ON)
30+
31+
if(PCMS_ENABLE_SPDLOG)
32+
find_package(spdlog REQUIRED)
33+
endif()
3034

3135
# find package before fortran enabled, so we don't require the adios2 fortran
3236
# interfaces this is important because adios2 build with clang/gfortran is
@@ -58,7 +62,7 @@ if(PCMS_ENABLE_OMEGA_H)
5862
endif()
5963
endif()
6064
# adios2 adds C and Fortran depending on how it was built
61-
find_package(ADIOS2 CONFIG 2.5 REQUIRED)
65+
find_package(ADIOS2 CONFIG 2.10.2 REQUIRED)
6266
find_package(Kokkos CONFIG 4.5 REQUIRED)
6367

6468
find_package(meshfields REQUIRED)

src/CMakeLists.txt

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,53 @@
11
# TODO split out the field transfer library
2-
set(PCMS_HEADERS
3-
pcms.h
4-
pcms/arrays.h
5-
pcms/assert.h
6-
pcms/bounding_box.h
7-
pcms/common.h
8-
pcms/coordinate.h
9-
pcms/coordinate_systems.h
10-
pcms/coordinate_transform.h
11-
pcms/field.h
12-
pcms/create_field.h
13-
pcms/field_communicator.h
14-
pcms/field_communicator2.h
15-
pcms/field_evaluation_methods.h
16-
pcms/memory_spaces.h
17-
pcms/types.h
18-
pcms/array_mask.h
19-
pcms/inclusive_scan.h
20-
pcms/profile.h
21-
pcms/print.h
22-
pcms/partition.h
23-
pcms/coupler.h
24-
pcms/coordinate_system.h
25-
pcms/field_layout.h
26-
pcms/adapter/point_cloud/point_cloud_layout.h
27-
pcms/adapter/point_cloud/point_cloud.h
28-
pcms/adapter/omega_h/omega_h_field_layout.h
29-
pcms/adapter/omega_h/omega_h_field2.h)
2+
set(
3+
PCMS_HEADERS
4+
pcms.h
5+
pcms/arrays.h
6+
pcms/assert.h
7+
pcms/bounding_box.h
8+
pcms/common.h
9+
pcms/coordinate.h
10+
pcms/coordinate_systems.h
11+
pcms/coordinate_transform.h
12+
pcms/field.h
13+
pcms/create_field.h
14+
pcms/field_communicator.h
15+
pcms/field_communicator2.h
16+
pcms/field_evaluation_methods.h
17+
pcms/memory_spaces.h
18+
pcms/types.h
19+
pcms/array_mask.h
20+
pcms/inclusive_scan.h
21+
pcms/profile.h
22+
pcms/print.h
23+
pcms/partition.h
24+
pcms/coupler.h
25+
pcms/coordinate_system.h
26+
pcms/field_layout.h
27+
pcms/adapter/point_cloud/point_cloud_layout.h
28+
pcms/adapter/point_cloud/point_cloud.h
29+
pcms/adapter/omega_h/omega_h_field_layout.h
30+
pcms/adapter/omega_h/omega_h_field2.h
31+
)
3032

31-
set(PCMS_SOURCES
32-
pcms.cpp
33-
pcms/assert.cpp
34-
pcms/print.cpp
35-
pcms/create_field.cpp
36-
pcms/adapter/xgc/xgc_field_adapter.h
37-
pcms/adapter/point_cloud/point_cloud_layout.cpp
38-
pcms/adapter/point_cloud/point_cloud.cpp
39-
pcms/adapter/omega_h/omega_h_field_layout.cpp
40-
pcms/adapter/omega_h/omega_h_field2.cpp
41-
pcms/adapter/xgc/xgc_field_adapter.h)
33+
set(
34+
PCMS_SOURCES
35+
pcms.cpp
36+
pcms/assert.cpp
37+
pcms/print.cpp
38+
pcms/create_field.cpp
39+
pcms/adapter/xgc/xgc_field_adapter.h
40+
pcms/adapter/point_cloud/point_cloud_layout.cpp
41+
pcms/adapter/point_cloud/point_cloud.cpp
42+
pcms/adapter/omega_h/omega_h_field_layout.cpp
43+
pcms/adapter/omega_h/omega_h_field2.cpp
44+
pcms/adapter/xgc/xgc_field_adapter.h
45+
)
4246

4347
configure_file(pcms/version.h.in pcms/version.h)
48+
configure_file(pcms/configuration.h.in pcms/configuration.h)
49+
list(APPEND PCMS_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/pcms/version.h ${CMAKE_CURRENT_BINARY_DIR}/pcms/configuration.h)
50+
4451

4552
if(PCMS_ENABLE_XGC)
4653
list(APPEND PCMS_SOURCES pcms/adapter/xgc/xgc_reverse_classification.cpp)
@@ -55,40 +62,36 @@ if(PCMS_ENABLE_OMEGA_H)
5562
pcms/transfer_field.h
5663
pcms/transfer_field2.h
5764
pcms/uniform_grid.h
58-
pcms/point_search.h)
65+
pcms/point_search.h
66+
)
5967
endif()
6068

6169
find_package(Kokkos REQUIRED)
6270
find_package(perfstubs REQUIRED)
6371

6472
add_library(pcms_core ${PCMS_SOURCES})
65-
set_target_properties(pcms_core PROPERTIES OUTPUT_NAME pcmscore EXPORT_NAME
66-
core)
73+
set_target_properties(
74+
pcms_core PROPERTIES OUTPUT_NAME pcmscore EXPORT_NAME
75+
core
76+
)
6777
add_library(pcms::core ALIAS pcms_core)
6878
target_compile_features(pcms_core PUBLIC cxx_std_17)
69-
target_link_libraries(pcms_core PUBLIC meshfields::meshfields redev::redev
70-
MPI::MPI_CXX Kokkos::kokkos perfstubs)
79+
target_link_libraries(
80+
pcms_core PUBLIC meshfields::meshfields redev::redev
81+
MPI::MPI_CXX Kokkos::kokkos perfstubs
82+
)
7183
if(PCMS_ENABLE_OMEGA_H)
7284
target_link_libraries(pcms_core PUBLIC Omega_h::omega_h)
73-
target_compile_definitions(pcms_core PUBLIC -DPCMS_HAS_OMEGA_H)
74-
endif()
75-
if(PCMS_ENABLE_SERVER)
76-
target_compile_definitions(pcms_core PUBLIC -DPCMS_HAS_SERVER)
7785
endif()
7886

7987
if(PCMS_HAS_ASAN)
80-
target_compile_options(pcms_core PRIVATE -fsanitize=address
81-
-fno-omit-frame-pointer)
82-
endif()
83-
84-
if(PCMS_PRINT_ENABLED)
85-
add_definitions(-DPCMS_PRINT_ENABLED)
86-
target_compile_definitions(pcms_core INTERFACE -DPCMS_PRINT_ENABLED)
88+
target_compile_options(
89+
pcms_core PRIVATE -fsanitize=address
90+
-fno-omit-frame-pointer
91+
)
8792
endif()
8893

89-
if(spdlog_FOUND)
90-
add_definitions(-DPCMS_SPDLOG_ENABLED)
91-
target_compile_definitions(pcms_core INTERFACE -DPCMS_SPDLOG_ENABLED)
94+
if(PCMS_ENABLE_SPDLOG)
9295
target_link_libraries(pcms_core PUBLIC spdlog::spdlog)
9396
endif()
9497

@@ -97,8 +100,9 @@ set_target_properties(pcms_core PROPERTIES PUBLIC_HEADER "${PCMS_HEADERS}")
97100
target_include_directories(
98101
pcms_core
99102
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
100-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
101-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
103+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
104+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
105+
)
102106
install(
103107
TARGETS pcms_core
104108
EXPORT pcms_core-targets
@@ -107,23 +111,29 @@ install(
107111
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
108112
INCLUDES
109113
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
110-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pcms)
114+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pcms
115+
)
111116

112117
configure_package_config_file(
113118
"${CMAKE_SOURCE_DIR}/config.cmake.in" "${CMAKE_BINARY_DIR}/pcms-config.cmake"
114-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms)
119+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms
120+
)
115121
write_basic_package_version_file(
116122
"${PROJECT_BINARY_DIR}/pcms-config-version.cmake"
117-
COMPATIBILITY AnyNewerVersion)
123+
COMPATIBILITY AnyNewerVersion
124+
)
118125

119-
install(FILES "${PROJECT_BINARY_DIR}/pcms-config.cmake"
120-
"${PROJECT_BINARY_DIR}/pcms-config-version.cmake"
121-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms)
126+
install(
127+
FILES "${PROJECT_BINARY_DIR}/pcms-config.cmake"
128+
"${PROJECT_BINARY_DIR}/pcms-config-version.cmake"
129+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms
130+
)
122131

123132
install(
124133
EXPORT pcms_core-targets
125134
NAMESPACE pcms::
126-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms)
135+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms
136+
)
127137

128138
add_library(pcms_pcms INTERFACE)
129139
target_link_libraries(pcms_pcms INTERFACE pcms::core)
@@ -147,11 +157,15 @@ install(
147157
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
148158
INCLUDES
149159
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
150-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pcms)
160+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pcms
161+
)
151162
# install external headers
152-
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcms/external/
153-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pcms/external)
163+
install(
164+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcms/external/
165+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pcms/external
166+
)
154167
install(
155168
EXPORT pcms-targets
156169
NAMESPACE pcms::
157-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms)
170+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pcms
171+
)

src/pcms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static_assert(std::is_same_v<LO, redev::LO>,
99
"pcms and redev LO types must match");
1010
static_assert(std::is_same_v<GO, redev::GO>,
1111
"pcms and redev GO types must match");
12-
#ifdef PCMS_HAS_OMEGA_H
12+
#ifdef PCMS_ENABLE_OMEGA_H
1313
static_assert(std::is_same_v<Real, Omega_h::Real>,
1414
"pcms and Omega_h real types must match");
1515
static_assert(std::is_same_v<LO, Omega_h::LO>,

src/pcms.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef PCMS_H_
22
#define PCMS_H_
33

4+
#include "pcms/configuration.h"
45
#include "pcms/common.h"
56
#include "pcms/field_communicator.h"
67
#include "pcms/adapter/omega_h/omega_h_field.h"

src/pcms/adapter/xgc/xgc_reverse_classification.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include "mdspan/mdspan.hpp"
99
#include "pcms/arrays.h"
1010
#include "pcms/memory_spaces.h"
11+
#include "pcms/configuration.h"
1112
// #include <filesystem>
12-
#ifdef PCMS_HAS_OMEGA_H
13+
#ifdef PCMS_ENABLE_OMEGA_H
1314
#include <Omega_h_mesh.hpp>
1415
#include "pcms/assert.h"
1516
#endif
@@ -86,7 +87,7 @@ ReverseClassificationVertex ReadReverseClassificationVertex(std::string,
8687
MPI_Comm,
8788
int root = 0);
8889

89-
#ifdef PCMS_HAS_OMEGA_H
90+
#ifdef PCMS_ENABLE_OMEGA_H
9091
enum class IndexBase
9192
{
9293
Zero = 0,

src/pcms/capi/client.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ namespace pcms
1313
using FieldAdapterVariant =
1414
std::variant<std::monostate, pcms::XGCFieldAdapter<double>,
1515
pcms::XGCFieldAdapter<float>, pcms::XGCFieldAdapter<int>,
16-
pcms::XGCFieldAdapter<long>, pcms::DummyFieldAdapter
17-
// #ifdef PCMS_HAS_OMEGA_H
18-
// ,
19-
// pcms::OmegaHFieldAdapter<double>,
20-
// pcms::OmegaHFieldAdapter<int>
21-
// #endif
22-
>;
16+
pcms::XGCFieldAdapter<long>, pcms::DummyFieldAdapter>;
2317

2418
} // namespace pcms
2519

src/pcms/configuration.h.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#cmakedefine PCMS_ENABLE_SERVER
2+
#cmakedefine PCMS_ENABLE_CLIENT
3+
#cmakedefine PCMS_ENABLE_XGC
4+
#cmakedefine PCMS_ENABLE_OMEGA_H
5+
#cmakedefine PCMS_ENABLE_C
6+
#cmakedefine PCMS_ENABLE_PRINT
7+
#cmakedefine PCMS_ENABLE_SPDLOG
8+
#cmakedefine PCMS_ENABLE_Fortran

src/pcms/print.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef PCMS_PRINT_H
22
#define PCMS_PRINT_H
33

4-
#ifdef PCMS_SPDLOG_ENABLED
4+
#ifdef PCMS_ENABLE_SPDLOG
55
#include "spdlog/spdlog.h"
66
#include <spdlog/fmt/bundled/printf.h>
77
#endif
@@ -25,24 +25,24 @@ void setStderr(FILE* err);
2525
template <typename... Args>
2626
void printError(const char* fmt, const Args&... args)
2727
{
28-
#if defined(PCMS_SPDLOG_ENABLED) && defined(PCMS_PRINT_ENABLED)
28+
#if defined(PCMS_ENABLE_SPDLOG) && defined(PCMS_ENABLE_PRINT)
2929
spdlog::error("{}", fmt::sprintf(fmt, args...));
30-
#elif defined(PCMS_PRINT_ENABLED)
30+
#elif defined(PCMS_ENABLE_PRINT)
3131
fprintf(getStdout(), fmt, args...);
3232
#endif
3333
}
3434

3535
template <typename... Args>
3636
KOKKOS_INLINE_FUNCTION void printInfo(const char* fmt, const Args&... args)
3737
{
38-
#if defined(PCMS_SPDLOG_ENABLED) && defined(PCMS_PRINT_ENABLED) && \
38+
#if defined(PCMS_ENABLE_SPDLOG) && defined(PCMS_ENABLE_PRINT) && \
3939
!defined(ACTIVE_GPU_EXECUTION)
4040
spdlog::info("{}", fmt::sprintf(fmt, args...));
41-
#elif defined(PCMS_PRINT_ENABLED) && !defined(ACTIVE_GPU_EXECUTION)
41+
#elif defined(PCMS_ENABLE_PRINT) && !defined(ACTIVE_GPU_EXECUTION)
4242
fprintf(getStdout(), fmt, args...);
4343
#endif
4444
}
4545

4646
} // namespace pcms
4747

48-
#endif // PCMS_PRINT_H
48+
#endif // PCMS_PRINT_H

0 commit comments

Comments
 (0)