forked from lisitsyn/tapkee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
195 lines (168 loc) · 7.08 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
project (Tapkee)
cmake_minimum_required (VERSION 2.8)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -g")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# cmake version > 3.1
#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)
# set paths
set (TAPKEE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set (TAPKEE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set (TAPKEE_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test/unit")
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/cmake")
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
# Eigen3 detection
find_package(Eigen3 REQUIRED)
include_directories(SYSTEM "${EIGEN3_INCLUDE_DIR}")
# ARPACK detection
find_package(Arpack)
if (ARPACK_FOUND)
link_directories("${ARPACK_PATH}")
endif()
# OpenMP detection
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
# ViennaCL detection
find_package(OpenCL)
if (OPENCL_FOUND)
find_package(ViennaCL)
if (VIENNACL_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCL_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCL_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCL_EXE_LINKER_FLAGS}")
include_directories("${VIENNACL_INCLUDE_DIRS}")
endif()
endif()
include_directories("${TAPKEE_INCLUDE_DIR}")
# CLI executable
add_executable(tapkee "${TAPKEE_SRC_DIR}/cli/main.cpp")
# Examples
option(BUILD_EXAMPLES "Whether to build examples or not" OFF)
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if (ARPACK_FOUND)
target_link_libraries(tapkee arpack)
add_definitions(-DTAPKEE_WITH_ARPACK)
endif()
if (VIENNACL_FOUND)
target_link_libraries(tapkee OpenCL)
add_definitions(-DTAPKEE_WITH_VIENNACL)
endif()
if (TAPKEE_CUSTOM_INSTALL_DIR)
set (TAPKEE_INSTALL_DIR
"${TAPKEE_CUSTOM_INSTALL_DIR}")
else()
set (TAPKEE_INSTALL_DIR
"${CMAKE_INSTALL_PREFIX}/include/tapkee")
endif()
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/utils/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/utils")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/routines/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/routines")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/callbacks/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/callbacks")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/neighbors/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/neighbors")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/traits/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/traits")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/parameters/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/parameters")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/defines/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/defines")
file(GLOB headers "${TAPKEE_INCLUDE_DIR}/tapkee/external/barnes_hut_sne/*.hpp")
install(FILES ${headers} DESTINATION "${TAPKEE_INSTALL_DIR}/external/barnes_hut_sne/")
# G++ specific flags
option(USE_GCOV "Use gcov to analyze test coverage" OFF)
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long -Wshadow")
if (USE_GCOV)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
add_custom_target(lcov DEPENDS tapkee)
add_custom_command(TARGET lcov COMMAND mkdir -p coverage WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
add_custom_command(TARGET lcov COMMAND lcov --directory . --zerocounters WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
add_custom_command(TARGET lcov COMMAND make test WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
add_custom_command(TARGET lcov COMMAND lcov --directory . --capture --output-file ./coverage/out.info WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
add_custom_command(TARGET lcov COMMAND lcov --remove ./coverage/out.info /usr/local/include\\* /usr/include\\* unit\\* --output ./coverage/clean.info "${CMAKE_BINARY_DIR}" VERBATIM)
add_custom_command(TARGET lcov COMMAND genhtml -o ./coverage ./coverage/clean.info --branch-coverage --demangle-cpp WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
endif()
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DTAPKEE_DEBUG)
endif()
option(PRECOMPUTED "Precompute kernel/distance matrices before reducing dimensionality" OFF)
if (PRECOMPUTED)
add_definitions(-DUSE_PRECOMPUTED)
endif()
option(GPL_FREE "Build without GPL-licensed components" OFF)
if (NOT GPL_FREE)
add_definitions(-DTAPKEE_USE_LGPL_COVERTREE)
endif()
option(BUILD_TESTS "Build tests" OFF)
if (BUILD_TESTS)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0/")
add_subdirectory(gtest-1.7.0)
set(GTEST_SOURCE_DIR "${gtest_SOURCE_DIR}")
include_directories(SYSTEM "${GTEST_SOURCE_DIR}/include")
else()
if (NOT GTEST_SOURCE_DIR)
# try with default ubuntu location
set(GTEST_SOURCE_DIR /usr/src/gtest)
endif()
if (NOT GTEST_INCLUDE_DIR)
# try with default ubuntu location
set(GTEST_INCLUDE_DIR /usr/include/gtest)
endif()
if (GTEST_SOURCE_DIR AND GTEST_INCLUDE_DIR)
include_directories("${GTEST_SOURCE_DIR}" "${GTEST_INCLUDE_DIR}/include")
add_library(gtest STATIC "${GTEST_SOURCE_DIR}/src/gtest-all.cc")
add_library(gtest_main STATIC "${GTEST_SOURCE_DIR}/src/gtest_main.cc")
target_link_libraries(gtest_main gtest)
find_package(Threads)
target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT})
else()
message(FATAL_ERROR "gtest-1.7.0 is required to be available in the root of the project or reachable
by GTEST_SOURCE_DIR and GTEST_INCLUDE_DIR")
endif()
endif()
enable_testing()
aux_source_directory("${TAPKEE_TESTS_DIR}" "TAPKEE_TESTS_SOURCES")
foreach(i ${TAPKEE_TESTS_SOURCES})
get_filename_component(exe ${i} NAME_WE)
add_executable(test_${exe} ${i})
target_link_libraries(test_${exe} gtest gtest_main)
if (ARPACK_FOUND)
target_link_libraries(test_${exe} arpack)
endif()
if (VIENNACL_FOUND)
target_link_libraries(test_${exe} OpenCL)
endif()
add_test(
NAME ${exe}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_${exe}"
--gtest_color=yes)
endforeach()
endif()