-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
73 lines (63 loc) · 2.47 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
cmake_minimum_required(VERSION 3.0)
project(SEUTraffic)
set(CMAKE_CXX_STANDARD "11" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DRAPIDJSON_HAS_STDSTRING=1")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
set(REQUIRED_SUBMODULES
"extern/pybind11/CMakeLists.txt"
"extern/rapidjson/include"
)
foreach(REQUIRED_SUBMODULE ${REQUIRED_SUBMODULES})
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/${REQUIRED_SUBMODULE}")
# update submodule
# https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update, this may take some time...")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
break()
else()
message(STATUS "Found Submodule: ${REQUIRED_SUBMODULE}")
endif()
endforeach()
foreach(REQUIRED_SUBMODULE ${REQUIRED_SUBMODULES})
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/${REQUIRED_SUBMODULE}")
message(FATAL_ERROR "The submodule ${REQUIRED_SUBMODULE} was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
endforeach()
add_subdirectory(extern/pybind11)
include_directories(extern/rapidjson/include)
include_directories(extern/milo)
add_subdirectory(src)
# Tests
find_package(GTest)
if(GTEST_FOUND)
enable_testing()
add_subdirectory(test)
endif()
if (${CMAKE_BUILD_TYPE} STREQUAL Debug)
add_subdirectory(tools/debug)
endif()
pybind11_add_module(${PROJECT_NAME} MODULE src/seutraffic.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_LIB_NAME})
if(VERSION)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DVERSION=${VERSION})
endif()