-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
128 lines (105 loc) · 5.56 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
# ============================================================================
# Require minimal version of cmake
# ============================================================================
cmake_minimum_required (VERSION 3.6)
# ============================================================================
# Set project name and languages
# ============================================================================
project (odexp
VERSION 1.0.0
LANGUAGES C)
# ============================================================================
# Set project version number
# ============================================================================
set (odexp_VERSION_MAJOR 1)
set (odexp_VERSION_MINOR 0)
# ============================================================================
# configure a header file to pass some of the CMake settings to the source code
# ============================================================================
configure_file (
"${PROJECT_SOURCE_DIR}/src/odexpConfig.h.in"
"${PROJECT_BINARY_DIR}/odexpConfig.h"
)
# ============================================================================
# add the binary tree to the search path for include files so that we will find odexpConfig.h
# ============================================================================
include_directories("${PROJECT_BINARY_DIR}")
# ============================================================================
# Find GSL
# ============================================================================
find_package(GSL REQUIRED)
# ============================================================================
# add library target
# ============================================================================
add_library(odexp SHARED
src/datastruct.c
src/main.c
src/methods_odexp.c
src/rand_gen.c
src/utils_odexp.c
src/lrexp.c
src/loader.c
src/options.c
)
target_link_libraries(odexp GSL::gsl GSL::gslcblas)
target_link_libraries(odexp /usr/local/opt/readline/lib/libreadline.dylib)
target_link_libraries(odexp /usr/local/opt/readline/lib/libhistory.dylib)
set_target_properties(odexp PROPERTIES VERSION ${PROJECT_VERSION})
target_compile_options(odexp PRIVATE -Werror -Wall -Wextra)
# ============================================================================
# Declare public API of your library
# ============================================================================
set_target_properties(odexp PROPERTIES PUBLIC_HEADER src/odexp.h)
# ============================================================================
# private headers should not been installed
# ============================================================================
target_include_directories(odexp PRIVATE src)
# ============================================================================
# Get GNU standard installation directories (GNUInstallDirs module)
# ============================================================================
include(GNUInstallDirs)
# ============================================================================
# Installation dirs
# ============================================================================
IF ( NOT DEFINED MANDIR )
set( MANDIR ${CMAKE_INSTALL_PREFIX}/share/man/man1 )
ENDIF ( NOT DEFINED MANDIR )
message( "** Manual files will be installed in ${MANDIR}" )
IF ( NOT DEFINED BINDIR )
set( BINDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR} )
ENDIF ( NOT DEFINED BINDIR )
message( "** Executable files will be installed in ${BINDIR}" )
# ============================================================================
# Set compilation flags (general and then build-type specific)
# ============================================================================
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wno-sign-compare -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-unknown-warning-option -Wno-nullability-completeness -Wno-availability")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Wno-sign-compare -O3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-nullability-completeness")
# set(CMAKE_BUILD_TYPE Debug)
# ============================================================================
# declare files to install
# ============================================================================
install(TARGETS odexp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# ============================================================================
# add a rule to expand @ macros (@ONLY ask to cmake to not expand variables
# of the form ${VAR})
# ============================================================================
configure_file(src/odexp.pc.in odexp.pc @ONLY)
# ============================================================================
# Add custom command for manpage
# ============================================================================
ADD_CUSTOM_TARGET( manpages ALL )
ADD_CUSTOM_COMMAND( TARGET manpages
COMMAND cp ${PROJECT_SOURCE_DIR}/src/odexp.mdoc ${CMAKE_BINARY_DIR}/odexp.1
COMMAND mandoc -T markdown ${PROJECT_SOURCE_DIR}/src/odexp.mdoc >${PROJECT_SOURCE_DIR}/README.md
DEPENDS ${CMAKE_BINARY_DIR}/odexp.1
)
# ============================================================================
# install generated files
# ============================================================================
install(FILES ${CMAKE_BINARY_DIR}/odexp.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
install(FILES ${CMAKE_BINARY_DIR}/odexp.1 DESTINATION ${MANDIR})
install(PROGRAMS ${CMAKE_SOURCE_DIR}/src/odexp DESTINATION ${BINDIR} )