Skip to content

Commit fe8dcda

Browse files
committed
use config file instead of target compile definitions
This commit updates PCMS configuration options to use a configuration file. This should do a better job of ensuring that downstream applications are setting up the correct configuration options if they do not build with CMake. It also has the benefit of making it easier to identify what options PCMS was configured with without parsing the CMake package files.
1 parent b7e9029 commit fe8dcda

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ 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)
28+
option(PCMS_ENABLE_PRINT "PCMS print statements enabled" ON)
2929
option(PCMS_ENABLE_SPDLOG "use spdlog for logging" ON)
3030

3131
if(PCMS_ENABLE_SPDLOG)

src/CMakeLists.txt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ set(PCMS_SOURCES
4141
pcms/adapter/xgc/xgc_field_adapter.h)
4242

4343
configure_file(pcms/version.h.in pcms/version.h)
44+
configure_file(pcms/configuration.h.in pcms/configuration.h)
45+
list(APPEND PCMS_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/pcms/version.h ${CMAKE_CURRENT_BINARY_DIR}/pcms/configuration.h)
46+
4447

4548
if(PCMS_ENABLE_XGC)
4649
list(APPEND PCMS_SOURCES pcms/adapter/xgc/xgc_reverse_classification.cpp)
@@ -70,25 +73,14 @@ target_link_libraries(pcms_core PUBLIC meshfields::meshfields redev::redev
7073
MPI::MPI_CXX Kokkos::kokkos perfstubs)
7174
if(PCMS_ENABLE_OMEGA_H)
7275
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)
7776
endif()
7877

7978
if(PCMS_HAS_ASAN)
8079
target_compile_options(pcms_core PRIVATE -fsanitize=address
8180
-fno-omit-frame-pointer)
8281
endif()
8382

84-
if(PCMS_PRINT_ENABLED)
85-
add_definitions(-DPCMS_PRINT_ENABLED)
86-
target_compile_definitions(pcms_core INTERFACE -DPCMS_PRINT_ENABLED)
87-
endif()
88-
8983
if(PCMS_ENABLE_SPDLOG)
90-
add_definitions(-DPCMS_SPDLOG_ENABLED)
91-
target_compile_definitions(pcms_core INTERFACE -DPCMS_SPDLOG_ENABLED)
9284
target_link_libraries(pcms_core PUBLIC spdlog::spdlog)
9385
endif()
9486

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)