-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
103 lines (81 loc) · 4.27 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
cmake_minimum_required(VERSION 3.22)
project(mpix-harmonize VERSION 0.1 LANGUAGES C DESCRIPTION "Implementation of MPIX_Harmonize")
# option() should ignore existing variables
cmake_policy(SET CMP0077 NEW)
include(GNUInstallDirs)
include(FetchContent)
include(CMakePackageConfigHelpers)
find_package(MPI REQUIRED)
set(MPITS_CLOCK "monotonic" CACHE STRING "time source in libmpits")
set_property(CACHE MPITS_CLOCK PROPERTY STRINGS mpi_wtime monotonic realtime)
message(STATUS "mpits clock: ${MPITS_CLOCK}")
if(${MPITS_CLOCK} STREQUAL "mpi_wtime")
set(ENABLE_GETTIME_MONOTONIC OFF CACHE BOOL "Enable gettime(MONOTONIC)")
set(ENABLE_GETTIME_REALTIME OFF CACHE BOOL "Enable gettime(REALTIME)")
elseif(${MPITS_CLOCK} STREQUAL "monotonic")
set(ENABLE_GETTIME_MONOTONIC ON CACHE BOOL "Enable gettime(MONOTONIC)")
set(ENABLE_GETTIME_REALTIME OFF CACHE BOOL "Enable gettime(REALTIME)")
elseif(${MPITS_CLOCK} STREQUAL "realtime")
set(ENABLE_GETTIME_MONOTONIC OFF CACHE BOOL "Enable gettime(MONOTONIC)")
set(ENABLE_GETTIME_REALTIME ON CACHE BOOL "Enable gettime(REALTIME)")
else()
message(FATAL_ERROR "Invalid value for MPITS_CLOCK: ${MPITS_CLOCK}. Allowed values are: mpi_wtime, monotonic, or realtime.")
endif()
# Configure the installation paths
set(MPIX_HARMONIZE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
set(MPIX_HARMONIZE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(MPIX_HARMONIZE_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
set(MPIX_HARMONIZE_INSTALL_LIBEXECDIR ${CMAKE_INSTALL_LIBEXECDIR})
set(MPIX_HARMONIZE_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR})
set(MPIX_HARMONIZE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_DATADIR}/cmake/mpix-harmonize)
FetchContent_Declare(
MPITS
GIT_REPOSITORY [email protected]:hunsa/mpi-time-sync.git
GIT_TAG main)
FetchContent_MakeAvailable(MPITS)
export(EXPORT mpits-targets FILE "${PROJECT_BINARY_DIR}/mpits-targets.cmake")
set(MPITS_CONFIG ${CMAKE_INSTALL_PREFIX}/share/cmake/mpits/mpits-config.cmake)
if (NOT TARGET MPITS::mpits)
message(FATAL "FAILED TO FIND MPITS")
endif()
add_library(mpix-harmonize SHARED mpix_harmonize.c)
add_library(MPIXHarmonize::mpix-harmonize ALIAS mpix-harmonize)
target_link_libraries(mpix-harmonize PUBLIC MPITS::mpits MPI::MPI_C)
set_target_properties(mpix-harmonize PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(mpix-harmonize PROPERTIES PUBLIC_HEADER mpix_harmonize.h)
set_target_properties(mpix-harmonize PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_LIBDIR})
# check if we're being built as a sub-project
STRING(COMPARE EQUAL ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} MPIX_HARMONIZE_BUILD_INPLACE)
if(NOT MPIX_HARMONIZE_BUILD_INPLACE)
include_directories(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}")
endif(NOT MPIX_HARMONIZE_BUILD_INPLACE)
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
# make sure the include directory is part of the interface
target_include_directories(mpix-harmonize
INTERFACE
$<INSTALL_INTERFACE:${MPIX_HARMONIZE_INSTALL_INCLUDEDIR}>
$<$<NOT:${MPIX_HARMONIZE_BUILD_INPLACE}>:
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
install(TARGETS mpix-harmonize
EXPORT mpix-harmonize
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT mpix-harmonize # rules to export the targets built here
FILE MPIXHarmonizeTargets.cmake
NAMESPACE MPIXHarmonize::
DESTINATION ${MPIX_HARMONIZE_INSTALL_CMAKEDIR})
configure_package_config_file(mpixharmonize-config.cmake.in
${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/mpixharmonize-config.cmake
INSTALL_DESTINATION ${MPIX_HARMONIZE_INSTALL_CMAKEDIR}
PATH_VARS MPIX_HARMONIZE_INSTALL_LIBDIR
MPIX_HARMONIZE_INSTALL_INCLUDEDIR
MPIX_HARMONIZE_INSTALL_BINDIR
MPIX_HARMONIZE_INSTALL_LIBEXECDIR
MPIX_HARMONIZE_INSTALL_CMAKEDIR)
install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/mpixharmonize-config.cmake
DESTINATION ${MPIX_HARMONIZE_INSTALL_CMAKEDIR})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mpix-harmonize.pc.in ${CMAKE_CURRENT_BINARY_DIR}/mpix-harmonize.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mpix-harmonize.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
install(FILES)