-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
85 lines (76 loc) · 2.73 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
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(PreventInSourceBuilds)
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build as shared library" ON)
endif()
if(NOT DEFINED LIB_MAN)
option(LIB_MAN "Build libcerf man pages" ON)
endif()
if(NOT DEFINED LIB_RUN)
option(LIB_RUN "Build executables for command-line computation" ON)
endif()
if(NOT DEFINED CERF_CPP)
option(CERF_CPP "Build libcerf as native C++" OFF)
endif()
if(CERF_CPP)
project(cerfcpp CXX)
message("Build C++ library libcerfcpp")
# add_compile_definitions(CERF_AS_CPP) # requires CMake 3.13, therefore more explicitly:
if(MSVC)
add_compile_options(/DCERF_AS_CPP)
else()
add_compile_options(-DCERF_AS_CPP)
endif()
set(CMAKE_CXX_STANDARD 11)
else()
message("Build C library libcerf")
project(cerf C)
set(CMAKE_C_STANDARD 99)
endif()
set(CERF_SOVERSION 2) # API version
set(CERF_VERSION ${CERF_SOVERSION}.1) # minor version
include(GNUInstallDirs)
if(MSVC)
if (NOT CERF_CPP)
message(FATAL_ERROR "Under MSVC, only CERF_CPP=ON is supported")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # parallel compilation
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS}")
set(MS_NOWARN "/wd4018 /wd4068 /wd4101 /wd4244 /wd4267 /wd4305 /wd4715 /wd4996")
set(MS_D "-D_CRT_SECURE_NO_WARNINGS -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${MS_NOWARN} ${MS_D}")
set(CTEST_CONFIGURATION_TYPE "${JOB_BUILD_CONFIGURATION}")
if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else()
# required for post-build validation under vcpkg:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") # multithreaded, debug
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else()
option(PEDANTIC "Compile with pedantic warnings" ON)
option(WERROR "Treat warnings as errors" OFF)
add_compile_options(-O2 -Wno-sign-compare -fno-omit-frame-pointer)
if(PEDANTIC)
add_compile_options(-pedantic -Wall)
endif()
if(WERROR)
add_compile_options(-Werror)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${DEB_FLAGS} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -w")
endif()
include(CTest)
configure_file("libcerf.pc.in" "libcerf.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcerf.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
add_subdirectory(lib)
# add_subdirectory(test)
# if(LIB_RUN)
# add_subdirectory(run)
# endif()
# if(LIB_MAN)
# add_subdirectory(man)
# endif()