-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
134 lines (109 loc) · 4.26 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
cmake_minimum_required(VERSION 3.13)
project(capi VERSION "3.0.8")
# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ")
endif()
set(CMAKE_C_FLAGS "-Wall -Wextra -O2")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -O2")
set(CMAKE_CXX_STANDARD 17)
message("${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake-modules")
message("${CMAKE_MODULE_PATH}")
set(PY_MODULE_TARGET _vis_graph)
set(TEST_TARGET "${PROJECT_NAME}_test")
set(EXAMPLE_TARGET "${PROJECT_NAME}_example")
set(CPP_LIBS_DIR ${CMAKE_SOURCE_DIR}/capi/cpp_libs)
# Git
find_package(Git REQUIRED)
# OpenMP
find_package(OpenMP REQUIRED)
# S2
if (NOT DEFINED S2_LIB)
if (EXISTS /usr/local/lib/libs2.so)
set(S2_LIB /usr/local/lib/libs2.so)
elseif (EXISTS /usr/lib/libs2.so)
set(S2_LIB /usr/lib/libs2.so)
else()
message(FATAL_ERROR "S2 Library was not found")
endif()
endif()
message("S2 Library was found in ${S2_LIB}")
if (NOT DEFINED S2_HEADERS)
if (EXISTS /usr/local/include/s2)
set(S2_HEADERS /usr/local/include/s2)
elseif (EXISTS /usr/include/s2)
set(S2_HEADERS /usr/include/s2)
else()
message(FATAL_ERROR "S2 include folder was not found")
endif()
endif()
message("S2 includes were found in ${S2_HEADERS}")
include_directories(S2_HEADERS)
# Currently, Scikit-build does not support FindPython, so we convert the
# provided hints ourselves.
if(SKBUILD)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
set(Python_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}")
set(Python_LIBRARY "${PYTHON_LIBRARY}")
set(DUMMY "${PYTHON_VERSION_STRING}") # Not needed, silences a warning
endif()
find_package(Python REQUIRED COMPONENTS Interpreter Development)
# Scikit-Build does not add your site-packages to the search path automatically,
# so we need to add it _or_ the pybind11 specific directory here.
execute_process(
COMMAND
"${Python_EXECUTABLE}" -c
"import pybind11; print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE _tmp_dir
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
# Now we can find pybind11
find_package(pybind11 CONFIG REQUIRED)
# Get our source files
set(VIS_GRAPH_IMPL_DIR ${CMAKE_SOURCE_DIR}/capi/src/implementation/visibility_graphs)
file(GLOB_RECURSE VIS_GRAPH_IMPLEMENTATION_FILES "${VIS_GRAPH_IMPL_DIR}/code/*.cpp" "${VIS_GRAPH_IMPL_DIR}/code/*.hpp")
include_directories(${VIS_GRAPH_IMPL_DIR}/code)
# Get fmt library
include_directories(${CPP_LIBS_DIR}/fmt/include)
file(GLOB_RECURSE FMT_SOURCE "${CPP_LIBS_DIR}/fmt/*.cc" "${CPP_LIBS_DIR}/fmt/*.h")
# Get indicators library
include_directories(${CPP_LIBS_DIR}/indicators/include)
file(GLOB_RECURSE PROGRESS_BAR_SOURCE "${CPP_LIBS_DIR}/indicators/*.hpp")
# Get mio library
include_directories(${CPP_LIBS_DIR}/mio)
file(GLOB_RECURSE MIO_SOURCE "${CPP_LIBS_DIR}/mio/*.hpp" "${CPP_LIBS_DIR}/mio/*.cpp")
# Create python module
pybind11_add_module(${PY_MODULE_TARGET} MODULE
${VIS_GRAPH_IMPLEMENTATION_FILES}
${FMT_SOURCE}
${MIO_SOURCE}
${VIS_GRAPH_IMPL_DIR}/bindings.cpp)
target_compile_definitions(${PY_MODULE_TARGET} PRIVATE VERSION_INFO=${PROJECT_VERSION})
target_link_libraries(${PY_MODULE_TARGET} PRIVATE
OpenMP::OpenMP_CXX
${S2_LIB})
install(TARGETS ${PY_MODULE_TARGET} DESTINATION .)
# Setup unit tests
set(TEST_DIR "capi/test")
file(GLOB_RECURSE TEST_FILES "${TEST_DIR}/*.cpp" "${TEST_DIR}/*.hpp")
# Generate a test executable
include_directories(${CPP_LIBS_DIR}/catch2)
file(GLOB_RECURSE CATCH_SOURCE "${CPP_LIBS_DIR}/catch2/*.cpp" "${CPP_LIBS_DIR}/catch2/*.hpp")
add_executable(${TEST_TARGET}
${TEST_FILES}
${VIS_GRAPH_IMPLEMENTATION_FILES}
${CATCH_SOURCE}
${MIO_SOURCE}
${FMT_SOURCE})
target_link_libraries(${TEST_TARGET} PRIVATE
OpenMP::OpenMP_CXX
${S2_LIB})
add_executable(${EXAMPLE_TARGET}
${VIS_GRAPH_IMPLEMENTATION_FILES}
${VIS_GRAPH_IMPL_DIR}/example.cpp
${MIO_SOURCE}
${FMT_SOURCE})
target_link_libraries(${EXAMPLE_TARGET} PRIVATE
OpenMP::OpenMP_CXX
${S2_LIB})