-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathCMakeLists.txt
99 lines (75 loc) · 2.76 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
cmake_minimum_required(VERSION 3.15...3.28)
enable_testing()
include(cmake/git.cmake)
include(cmake/init_build_type.cmake)
include(cmake/options.cmake)
project(SC
LANGUAGES C
HOMEPAGE_URL https://www.p4est.org/
DESCRIPTION "The SC library supports parallel scientific applications."
VERSION ${PROJECT_VERSION})
include(GNUInstallDirs)
include(cmake/config.cmake) # options.cmake before config.cmake to determine user intent
include(cmake/compilers.cmake) # compilers.cmake must be AFTER find_package() calls in config.cmake in general
set(CMAKE_C_STANDARD 99)
message(STATUS "libsc ${PROJECT_VERSION} "
"install prefix: ${CMAKE_INSTALL_PREFIX}")
# --- iniparser
add_library(iniparser OBJECT iniparser/inistring.c iniparser/dictionary.c iniparser/iniparser.c)
target_include_directories(iniparser PRIVATE iniparser src ${PROJECT_BINARY_DIR}/include)
target_link_libraries(iniparser PRIVATE $<$<BOOL:${SC_ENABLE_MPI}>:MPI::MPI_C>)
# --- libb64
add_library(libb64 OBJECT libb64/cencode.c libb64/cdecode.c)
target_include_directories(libb64 PRIVATE libb64)
# --- sc
add_library(sc $<TARGET_OBJECTS:iniparser> $<TARGET_OBJECTS:libb64>)
set_property(TARGET sc PROPERTY EXPORT_NAME SC)
set_property(TARGET sc PROPERTY SOVERSION ${SC_SOVERSION})
target_include_directories(sc
PRIVATE iniparser libb64
PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# optionally link with external libraries
if ( SC_ENABLE_MPI )
target_link_libraries(sc PUBLIC MPI::MPI_C)
endif()
if ( SC_HAVE_ZLIB )
target_link_libraries(sc PUBLIC ZLIB::ZLIB)
endif()
if( SC_HAVE_JSON )
target_link_libraries(sc PUBLIC jansson::jansson)
endif()
if ( SC_NEED_M )
target_link_libraries(sc PUBLIC m)
endif()
if ( WIN32 )
target_link_libraries(sc PUBLIC ${WINSOCK_LIBRARIES})
endif()
# imported target, for use from parent project
add_library(SC::SC INTERFACE IMPORTED GLOBAL)
target_link_libraries(SC::SC INTERFACE sc)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ ${PROJECT_BINARY_DIR}/include/
TYPE INCLUDE
FILES_MATCHING PATTERN "*.h"
)
install(TARGETS sc EXPORT ${PROJECT_NAME}-targets)
add_subdirectory(src)
if(SC_BUILD_TESTING)
include(cmake/valgrind.cmake)
add_subdirectory(test)
endif()
if(SC_BUILD_EXAMPLES AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
add_subdirectory(example)
endif()
# --- packaging
include(cmake/pkgconf.cmake)
include(cmake/install.cmake)
include(FeatureSummary)
add_feature_info(MPI SC_ENABLE_MPI "MPI features of libsc")
add_feature_info(ZLIB SC_HAVE_ZLIB "ZLIB features of libsc")
add_feature_info(shared SC_BUILD_SHARED_LIBS "shared libsc library")
add_feature_info(json SC_HAVE_JSON "JSON features of libsc")
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)