forked from bedrock-viz/bedrock-viz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
125 lines (94 loc) · 3.58 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
cmake_minimum_required(VERSION 3.10)
project(bedrock-viz VERSION 0.1.1)
set(CMAKE_CXX_STANDARD 17)
option(BEDROCK_VIZ_BUILD_TESTS "Build unit tests" OFF)
if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_definitions(BEDROCK_VIZ_DEBUG)
endif(CMAKE_BUILD_TYPE STREQUAL Debug)
configure_file(src/config.h.in config.h)
file(GLOB_RECURSE SRC_FILES src/*.cc)
file(GLOB_RECURSE HEADER_FILES src/*.h)
list(FILTER SRC_FILES EXCLUDE REGEX ".*_test.cc$")
add_executable(bedrock-viz
${SRC_FILES}
${HEADER_FILES}
)
if(MSVC)
target_sources(bedrock-viz PRIVATE "src/getopt/getopt.c")
# 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)
include_directories(
${PNG_INCLUDE_DIR}
${ZLIB_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(bedrock-viz PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC requires -lstdc++fs to use <filesystem>
target_link_libraries(bedrock-viz stdc++fs)
endif()
target_link_libraries(bedrock-viz
leveldb spdlog nbt++ pugixml::static
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
file(COPY data
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY static
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
install(TARGETS bedrock-viz DESTINATION bin)
install(DIRECTORY data/ DESTINATION share/bedrock-viz/data)
install(DIRECTORY static/ DESTINATION share/bedrock-viz/static)
# From LevelDB's CMakeLists.txt
if(BEDROCK_VIZ_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")
file(GLOB_RECURSE SRC_FILES_NO_MAIN src/*.cc)
list(FILTER SRC_FILES_NO_MAIN EXCLUDE REGEX ".*_test.cc$")
list(FILTER SRC_FILES_NO_MAIN EXCLUDE REGEX ".*/main.cc$")
function(viz_test test_file)
get_filename_component(test_target_name "${test_file}" NAME_WE)
add_executable("${test_target_name}"
${SRC_FILES_NO_MAIN}
${HEADER_FILES}
"${test_file}"
)
if(MSVC)
target_sources("${test_target_name}" PRIVATE "src/getopt/getopt.c")
# 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}
)
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 "${test_target_name}" COMMAND "${test_target_name}")
endfunction(viz_test)
viz_test("src/example_test.cc")
endif(BEDROCK_VIZ_BUILD_TESTS)