forked from bedrock-viz/bedrock-viz
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
133 lines (104 loc) · 4.13 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
cmake_minimum_required(VERSION 3.10)
project(bedrock-viz VERSION 0.1.8)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(BUILD_TESTS "Build unit tests" OFF)
option(CODE_COVERAGE "Enable coverage reporting" OFF)
set(BIN_NAME bedrock-viz)
set(LIB_NAME libbedrock-viz)
if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_definitions(BEDROCK_VIZ_DEBUG)
endif(CMAKE_BUILD_TYPE STREQUAL Debug)
add_library(coverage_config INTERFACE)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message("Code Coverage Enabled")
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
configure_file(include/config.h.in config.h)
file(GLOB_RECURSE SRC_FILES src/*.cc)
list(FILTER SRC_FILES EXCLUDE REGEX ".*/main.cc$")
file(GLOB_RECURSE HEADER_FILES include/*.h)
file(GLOB_RECURSE TEST_FILES tests/*.cc)
add_library(${LIB_NAME} STATIC ${SRC_FILES})
if(MSVC)
# TODO remove all insecure c functions
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
set(LEVELDB_BUILD_TESTS OFF CACHE INTERNAL "Don't build LevelDB tests")
set(LEVELDB_BUILD_BENCHMARKS OFF CACHE INTERNAL "Don't build LevelDB benckmarks")
set(LEVELDB_INSTALL OFF CACHE INTERNAL "Don't install LevelDB headers")
add_subdirectory(third_party/leveldb)
set(NBT_BUILD_TESTS OFF CACHE INTERNAL "Don't build nbt++ tests")
add_subdirectory(third_party/libnbtplusplus)
add_subdirectory(third_party/spdlog)
add_subdirectory(third_party/pugixml)
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(Threads REQUIRED)
find_package(Boost COMPONENTS program_options REQUIRED)
include_directories(
${PNG_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/third_party/leveldb/include
${PROJECT_SOURCE_DIR}/third_party/libnbtplusplus/include
${PROJECT_SOURCE_DIR}/third_party/spdlog/include
${PROJECT_SOURCE_DIR}/third_party/pugixml/include
)
target_include_directories(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${LIB_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC requires -lstdc++fs to use <filesystem>
target_link_libraries(${LIB_NAME} stdc++fs)
endif()
target_link_libraries(${LIB_NAME}
coverage_config
leveldb spdlog nbt++ pugixml::static
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY static DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_executable(${BIN_NAME} src/main.cc)
target_link_libraries(${BIN_NAME} PRIVATE ${LIB_NAME})
target_include_directories(${BIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
add_executable(legend utils/legend.cc)
target_link_libraries(legend PRIVATE ${LIB_NAME})
target_include_directories(legend PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
install(TARGETS ${BIN_NAME} DESTINATION bin)
install(DIRECTORY data/ DESTINATION share/bedrock-viz/data)
install(DIRECTORY static/ DESTINATION share/bedrock-viz/static)
# From LevelDB's CMakeLists.txt
if(BUILD_TESTS)
enable_testing()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK OFF CACHE INTERNAL "Don't bulid gmock")
# This project is tested using GoogleTest.
add_subdirectory("third_party/googletest")
set(test_target_name "bedrock-viz-test")
add_executable("${test_target_name}"
"${TEST_FILES}"
)
if(MSVC)
# TODO remove all insecure c functions
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
target_link_libraries("${test_target_name}"
gtest
leveldb spdlog nbt++ pugixml::static
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${LIB_NAME}
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC requires -lstdc++fs to use <filesystem>
target_link_libraries("${test_target_name}" stdc++fs)
endif()
target_include_directories(${test_target_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME "UnitTests" COMMAND "${test_target_name}")
add_test(NAME "IntegrationTests" COMMAND "${test_target_name}")
add_test(NAME "MiscTests" COMMAND "${test_target_name}")
endif(BUILD_TESTS)