forked from district10/geobuf-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
97 lines (86 loc) · 3.33 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
cmake_minimum_required(VERSION 3.15...3.27)
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)
# set(CMAKE_BUILD_TYPE "Debug")
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "" FORCE)
message(STATUS "Set build type to default: ${CMAKE_BUILD_TYPE}")
else()
message(STATUS "Your build type: ${CMAKE_BUILD_TYPE}")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pragma-once-outside-header")
endif()
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}")
add_definitions(-DPROJECT_BINARY_DIR="${PROJECT_BINARY_DIR}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/headers/include)
include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/geobuf)
option(BUILD_SHARED_LIBS "Build shared library." OFF)
set(HEADER_ROOT "${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}")
file(GLOB_RECURSE HEADERS src/**/*.hpp)
file(GLOB_RECURSE SOURCES src/**/*.cpp)
add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
install(TARGETS ${PROJECT_NAME} DESTINATION ${PROJECT_NAME})
add_executable(pbf_decoder src/geobuf/pbf_decoder.cpp)
target_compile_definitions(pbf_decoder PUBLIC -DPBF_DECODER_ENABLE_MAIN)
install(TARGETS pbf_decoder RUNTIME DESTINATION ${PROJECT_NAME})
option(BUILD_EXAMPLES "Build examples." ON)
if(BUILD_EXAMPLES)
file(GLOB SRCS examples/*.cpp)
foreach(src ${SRCS})
string(
REGEX
REPLACE "(^.*/|.cpp$)"
""
exe
${src})
add_executable(${exe} ${src})
target_link_libraries(${exe} ${PROJECT_NAME})
install(TARGETS ${exe} RUNTIME DESTINATION ${PROJECT_NAME})
endforeach(src)
endif()
option(BUILD_TESTS "Build tests." ON)
if(BUILD_TESTS)
file(GLOB SRCS tests/test_*.cpp)
foreach(src ${SRCS})
string(
REGEX
REPLACE "(^.*/|.cpp$)"
""
exe
${src})
add_executable(${exe} ${src})
target_link_libraries(${exe} ${PROJECT_NAME})
install(TARGETS ${exe} RUNTIME DESTINATION ${PROJECT_NAME})
endforeach(src)
endif()
add_custom_target(test_all COMMAND make -C .. test_all)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
set(PYBIND_SRCS src/main.cpp src/pybind11_rapidjson.cpp src/pybind11_geojson.cpp)
python_add_library(
_core
MODULE
${PYBIND_SRCS}
WITH_SOABI)
target_link_libraries(_core PRIVATE pybind11::headers ${PROJECT_NAME})
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
install(TARGETS _core DESTINATION ${PROJECT_NAME})