-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
146 lines (134 loc) · 4.51 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Hide symbols by default
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
set(PROJECT_NAME nextSIMutils)
set(LIB_NAME domain_decomp)
set(EXEC_NAME decomp)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
project(${PROJECT_NAME} VERSION ${VERSION_MAJOR}.${VERSION_MINOR} LANGUAGES CXX)
# User definable build options
option(BUILD_TESTS "Build the tests" ON)
# Set RPATH behaviour
set(CMAKE_SKIP_RPATH FALSE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# Embed absolute paths to external libraries that are not part of
# the project, (they are expected to be at the same location on all
# machines the project will be deployed to
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
include(GNUInstallDirs)
# Define RPATH for executables via a relative expression to enable a
# fully relocatable package
file(RELATIVE_PATH relDir1
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
file(RELATIVE_PATH relDir2
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/examples
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH $ORIGIN/${relDir1}:$ORIGIN/${relDir2})
# Dependencies
if (BUILD_TESTS)
set(DOCTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_library(doctest::doctest IMPORTED INTERFACE)
set_property(
TARGET doctest::doctest
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${DOCTEST_INCLUDE_DIR}"
)
endif()
find_package(MPI REQUIRED COMPONENTS CXX)
find_package(PkgConfig)
pkg_search_module(NETCDF netcdf)
if (NETCDF_FOUND)
set(netCDF_INCLUDE_DIR "${NETCDF_INCLUDE_DIRS}")
set(netCDF_LIB_DIR "${NETCDF_LIBRARY_DIRS}")
else()
find_package(netCDF REQUIRED)
endif()
find_package(Zoltan)
if (NOT Zoltan_FOUND)
find_library(Zoltan_LIBRARIES "zoltan" REQUIRED)
endif()
find_package(Boost COMPONENTS program_options REQUIRED)
# Generic options for compilation
add_compile_options(-Wall -Wextra -pedantic -fPIC)
# Library
add_library(${LIB_NAME} SHARED
${PROJECT_SOURCE_DIR}/Grid.cpp
${PROJECT_SOURCE_DIR}/DomainUtils.cpp
${PROJECT_SOURCE_DIR}/Partitioner.cpp
${PROJECT_SOURCE_DIR}/ZoltanPartitioner.cpp
)
set_target_properties(${LIB_NAME} PROPERTIES
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}
SOVERSION ${VERSION_MAJOR}
)
# Create an export header to control symbol visibility
include(GenerateExportHeader)
generate_export_header(${LIB_NAME}
EXPORT_FILE_NAME ${LIB_NAME}_export.hpp
EXPORT_MACRO_NAME LIB_EXPORT
)
# Create an alias to be used within the project and by other projects
add_library(${PROJECT_NAME}::${LIB_NAME} ALIAS ${LIB_NAME})
# Set library dependencies
target_link_libraries(${LIB_NAME}
PUBLIC MPI::MPI_CXX
PRIVATE netcdf ${Zoltan_LIBRARIES}
)
target_link_directories(${LIB_NAME}
PRIVATE ${netCDF_LIB_DIR}
)
target_include_directories(${LIB_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${netCDF_INCLUDE_DIR} ${Zoltan_INCLUDE_DIRS}
)
# Set the header files that need to be installed
set_target_properties(${LIB_NAME} PROPERTIES
PUBLIC_HEADER "Grid.hpp;Partitioner.hpp;DomainUtils.hpp"
)
# Create import targets
install(TARGETS ${LIB_NAME}
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}Config.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)
# Executable
add_executable(${EXEC_NAME}
${PROJECT_SOURCE_DIR}/DomainUtils.cpp
${PROJECT_SOURCE_DIR}/Grid.cpp
${PROJECT_SOURCE_DIR}/Partitioner.cpp
${PROJECT_SOURCE_DIR}/ZoltanPartitioner.cpp
${PROJECT_SOURCE_DIR}/main.cpp)
# Create an alias to be used within the project and by other projects
add_executable(${PROJECT_NAME}::${EXEC_NAME} ALIAS ${EXEC_NAME})
# Set executable dependencies
target_include_directories(${EXEC_NAME}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${netCDF_INCLUDE_DIR} ${Zoltan_INCLUDE_DIRS}
)
target_link_libraries(${EXEC_NAME}
PUBLIC MPI::MPI_CXX
PRIVATE netcdf ${Zoltan_LIBRARIES} Boost::program_options
)
target_link_directories(${EXEC_NAME}
PRIVATE ${netCDF_LIB_DIR}
)
install(TARGETS ${EXEC_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
# Unit tests
if(BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
# Examples
add_subdirectory(examples)