-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
153 lines (123 loc) · 4.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
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
cmake_minimum_required(VERSION 3.14)
project(ANN LANGUAGES C VERSION 0.1.1.5)
cmake_policy(SET CMP0079 NEW)
### CMAKE MODULE
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/.cmake" ${CMAKE_MODULE_PATH})
INCLUDE(BuildType)
INCLUDE(ConfigChecks)
INCLUDE(FindGraphviz)
INCLUDE(GNUInstallDirs)
INCLUDE(Doxygen)
INCLUDE(FindPythonModule)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")
INCLUDE(CodeCoverage)
endif()
find_package (Python3 COMPONENTS Interpreter Development)
find_python_module(setuptools)
FIND_PACKAGE(SWIG)
FIND_PACKAGE(PythonLibs)
### FLAGS
add_definitions(-Wall -Wextra -pedantic -Wformat=2 -std=c99)
set (CMAKE_C_FLAGS_DEBUG "-fsanitize=address -fsanitize=leak -g3 -Og -DDEBUG=1")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "-fsanitize=address -fsanitize=leak")
set (CMAKE_MODULE_LINKER_FLAGS_DEBUG "-fsanitize=address -fsanitize=leak")
if ((CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage") AND COVERAGE_OK)
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_COVERAGE}")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CMAKE_EXE_LINKER_FLAGS_COVERAGE}")
set (CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${CMAKE_SHARED_LINKER_FLAGS_COVERAGE}")
endif()
set (CMAKE_C_FLAGS_RELEASE "-Ofast")
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "-Ofast")
set (CMAKE_MODULE_LINKER_FLAGS_RELEASE "-Ofast")
### CONFIGURE FILE
set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
set(PRIVATE_LIBS "-l${PROJECT_NAME}")
configure_file (
"${PROJECT_SOURCE_DIR}/pkgconf/ANN.pc.in"
"${PROJECT_BINARY_DIR}/pkgconf/ANN.pc"
@ONLY
)
configure_file (
"${PROJECT_SOURCE_DIR}/Doxyfile.in"
"${PROJECT_BINARY_DIR}/Doxyfile"
@ONLY
)
### STATIC LIBRARY BUILDING RULES
add_subdirectory(include/ANN/)
add_subdirectory(src/)
target_include_directories("${PROJECT_NAME}" PUBLIC
"${PROJECT_BINARY_DIR}/include/"
)
set(ANN_INCLUDE_DIR "${PROJECT_BINARY_DIR}/include/")
include_directories(${ANN_INCLUDE_DIR})
### TEST AND MAIN
add_subdirectory(Test/)
add_subdirectory(Main/)
target_link_libraries(ANNTest ANN)
target_link_libraries(ANNMain ANN)
### PYTHON MODULE
if ((CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") AND Python3_FOUND AND PY_SETUPTOOLS_FOUND AND SWIG_FOUND)
string(TOLOWER "${PROJECT_NAME}" PYANN)
set(PYANN "py${PYANN}")
set(PYANN_LOW "${PYANN}_low")
include(${SWIG_USE_FILE})
include_directories(${PYTHON_INCLUDE_DIRS})
SET(CMAKE_SWIG_FLAGS "-Wall")
add_subdirectory(python/)
endif()
##### TARGETS
add_custom_target(check
COMMAND ASAN_OPTIONS=allocator_may_return_null=1 ${CMAKE_BINARY_DIR}/Test/ANNTest -j1
COMMENT "Running test !!!"
DEPENDS ANNTest
)
add_custom_target(run
COMMAND ${CMAKE_BINARY_DIR}/Main/ANNMain
COMMENT "Running Main !!!"
DEPENDS ANNMain
)
add_custom_target(gdb
COMMAND gdb ${CMAKE_BINARY_DIR}/Main/ANNMain
COMMENT "Running Main on gdb !!!"
DEPENDS ANNMain
)
if ((CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage") AND COVERAGE_OK)
SETUP_TARGET_FOR_COVERAGE(
coverage # Name for custom target.
${CMAKE_BINARY_DIR}/Main/ANNMain # Name of the test driver executable that runs the tests.
# NOTE! This should always have a ZERO as exit code
# otherwise the coverage generation will not complete.
coverage # Name of output directory.
ANNMain # dependency
)
endif()
### INSTALL TARGET
# install
set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(INSTALL_LICENSE_DIR "${CMAKE_INSTALL_PREFIX}/share/licences" CACHE PATH "Installation directory for LICENSE files")
install(
TARGETS
${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
) # headers
install(DIRECTORY "${PROJECT_BINARY_DIR}/pkgconf/"
DESTINATION "${INSTALL_PKGCONFIG_DIR}"
) # pkg config file
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE"
DESTINATION "${INSTALL_LICENSE_DIR}/${PROJECT_NAME}/"
) # LICENSE
# uninstall
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/.cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()