-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
211 lines (182 loc) · 6.43 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
if(NOT EMBED_libfmftsaxs)
cmake_minimum_required(VERSION 3.0)
endif()
set(libfmftsaxs_version_major 1)
set(libfmftsaxs_version_minor 0)
set(libfmftsaxs_version_patch 0)
set(libfmftsaxs_version
"${libfmftsaxs_version_major}.${libfmftsaxs_version_minor}.${libfmftsaxs_version_patch}")
project(fmftsaxs
LANGUAGES C
VERSION ${libfmftsaxs_version})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
#################
# BUILD OPTIONS #
#################
option( SONAME "Set the (SO)VERSION of the target" ON )
option( BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" OFF )
option( PROFILE "Generate profiling information" OFF )
option( BUILD_TESTS "Build tests" ON )
option( BUILD_DOCS "Create and install the HTML based
API documentation (requires Doxygen)" ON )
option( USE_LTO "Use Link Time Optimization" ON )
option( MPI "Message passing interface" OFF )
option( VERBOSE "Verbosity" ON )
# Default installation directory is set to $HOME
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX $ENV{HOME} CACHE PATH "Base directory for installation" FORCE)
endif()
set (CMAKE_PREFIX_PATH $ENV{HOME})
##################
# COMPILER FLAGS #
##################
if (BUILD_SHARED_LIBS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC")
endif ()
if(PROFILE)
set(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
endif()
if (MPI)
add_definitions(-D_MPI_)
set(CMAKE_C_COMPILER mpicc)
endif ()
if (VERBOSE)
add_definitions(-D_SXS_VERBOSE_)
endif ()
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -Wall -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wextra -Wfatal-errors -Wstrict-prototypes -g -pg")
set(CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE}")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND USE_LTO)
include(CheckCCompilerFlag)
check_c_compiler_flag(-flto HAS_LINK_TIME_OPTIMIZATION)
#check whether ar supports plugins
set(AR_SUPPORT 1)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
execute_process(
COMMAND ar --help
COMMAND grep plugin
OUTPUT_VARIABLE AR_SUPPORT)
endif()
if(HAS_LINK_TIME_OPTIMIZATION AND AR_SUPPORT)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -flto")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
endif()
endif()
endif()
############
# SOURCES #
############
file(GLOB LIBLBFGSB_SOURCES
lbfgsb/src/lbfgsb.c
lbfgsb/src/linesearch.c
lbfgsb/src/subalgorithms.c
lbfgsb/src/print.c
lbfgsb/src/linpack.c
lbfgsb/src/miniCBLAS.c
lbfgsb/src/timer.c)
file(GLOB LIBLBFGSB_PUBLIC_HEADERS lbfgsb/src/lbfgsb.h)
file(GLOB libfmftsaxs_SOURCES src/*.c)
file(GLOB libfmftsaxs_PUBLIC_HEADERS src/*.h )
#################
# FIND PACKAGES #
#################
find_package(mol2 REQUIRED)
if (MPI)
find_package(MPI REQUIRED)
endif ()
############
# LIBRARY #
############
#set install subdirs
set(LIB_INSTALL_DIR "lib" CACHE PATH "Where to install libraries to.")
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "Where to install headers to.")
set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}" CACHE PATH "Where to install configs to.")
add_library(lbfgsb OBJECT ${LIBLBFGSB_SOURCES})
add_library(fmftsaxs ${libfmftsaxs_SOURCES} $<TARGET_OBJECTS:lbfgsb>)
target_link_libraries(fmftsaxs fftw3 mol2 gmp check rt m)
target_include_directories(fmftsaxs
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_HOME_DIRECTORY}/lbfgsb/src>"
"$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")
set_target_properties(fmftsaxs PROPERTIES PUBLIC_HEADER "${libfmftsaxs_PUBLIC_HEADERS};${LIBLBFGSB_PUBLIC_HEADERS}")
set_target_properties(fmftsaxs PROPERTIES VERSION "${libfmftsaxs_version}")
if (MPI)
target_include_directories(fmftsaxs
PUBLIC
"$<BUILD_INTERFACE:${MPI_INCLUDE_PATH}>")
if(MPI_COMPILE_FLAGS)
set_target_properties(fmftsaxs
PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
endif()
if(MPI_LINK_FLAGS)
set_target_properties(fmftsaxs
PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif ()
add_subdirectory(tools)
############
# INSTALL #
############
install(TARGETS fmftsaxs
EXPORT fmftsaxsTargets
LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
PUBLIC_HEADER DESTINATION "${INCLUDE_INSTALL_DIR}/fmftsaxs")
############
# CONFIG #
############
include(CMakePackageConfigHelpers)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/fmftsaxs/fmftsaxsConfigVersion.cmake
VERSION ${libfmftsaxs_version}
COMPATIBILITY AnyNewerVersion)
configure_package_config_file(cmake/fmftsaxsConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/fmftsaxs/fmftsaxsConfig.cmake
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/fmftsaxs/fmftsaxsConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/fmftsaxs/fmftsaxsConfigVersion.cmake
DESTINATION ${CONFIG_INSTALL_DIR})
install(EXPORT fmftsaxsTargets
FILE fmftsaxsTargets.cmake
DESTINATION ${CONFIG_INSTALL_DIR})
#################
# DOCUMENTATION #
#################
# add a target to generate API documentation with Doxygen
if(BUILD_DOCS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
#set install dirs
set(DOC_INSTALL_DIR "doc" CACHE PATH "Where to install docs to.")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/"
DESTINATION "${DOC_INSTALL_DIR}/fmftsaxs")
else()
message("Could not find Doxygen.")
endif(DOXYGEN_FOUND)
endif(BUILD_DOCS)
###########
# TESTING #
###########
if(BUILD_TESTS)
find_package(Check REQUIRED)
if(CHECK_FOUND)
enable_testing()
add_subdirectory(tests)
else()
message("Could not find Check for testing")
endif()
endif()