-
Notifications
You must be signed in to change notification settings - Fork 133
/
CMakeLists.txt
151 lines (123 loc) · 5.82 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.2)
project(earcut_hpp LANGUAGES CXX C)
option(EARCUT_BUILD_TESTS "Build the earcut test program" ON)
option(EARCUT_BUILD_BENCH "Build the earcut benchmark program" ON)
option(EARCUT_BUILD_VIZ "Build the earcut visualizer program" ON)
option(EARCUT_WARNING_IS_ERROR "Treat warnings as errors" OFF)
if (NOT CMAKE_BUILD_TYPE AND NOT GENERATOR_IS_MULTI_CONFIG)
message(STATUS "No build type specified. Setting to 'Release'")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build." FORCE)
endif()
include(GNUInstallDirs)
add_library(earcut_hpp INTERFACE)
add_library(earcut_hpp::earcut_hpp ALIAS earcut_hpp)
target_include_directories(earcut_hpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set(CMAKE_CXX_STANDARD 11)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 3.7)
# Allow C++11 requirements to propagate when using recent CMake versions
target_compile_features(earcut_hpp INTERFACE cxx_std_11)
endif()
file(GLOB FIXTURE_SOURCE_FILES test/fixtures/*.cpp test/fixtures/*.hpp)
source_group(fixtures FILES ${FIXTURE_SOURCE_FILES})
add_library(fixtures OBJECT ${FIXTURE_SOURCE_FILES})
target_compile_options(fixtures PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/Od>)
# In CMake 3.12, use target_link_libraries(fixtures PUBLIC earcut_hpp libtess2).
# Since we support down to CMake 3.2, we need to manually propagate usage requirements of earcut_hpp
target_include_directories(fixtures PRIVATE "$<TARGET_PROPERTY:earcut_hpp,INTERFACE_INCLUDE_DIRECTORIES>")
target_compile_features(fixtures PRIVATE "$<TARGET_PROPERTY:earcut_hpp,INTERFACE_COMPILE_FEATURES>")
file(GLOB COMPARISON_SOURCE_FILES test/comparison/*.cpp test/comparison/*.hpp)
source_group(comparison FILES ${COMPARISON_SOURCE_FILES})
# this is interface since there is no cpp files in the comparison directory
add_library(comparison INTERFACE)
file(GLOB LIBTESS2_SOURCE_FILES test/comparison/libtess2/*.c test/comparison/libtess2/*.h)
source_group(comparison/libtess2 FILES ${LIBTESS2_SOURCE_FILES})
add_library(libtess2 ${LIBTESS2_SOURCE_FILES})
target_compile_options(libtess2 PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/wd4244 /wd4267>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-w>
)
add_library(common INTERFACE)
target_link_libraries(common INTERFACE libtess2 comparison)
# optional: -march=native (builds with the optimizations available on the build machine (only for local use!))
target_compile_options(common INTERFACE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-pipe -Wall -Wextra -Wconversion -Wpedantic>
)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang$" OR CMAKE_COMPILER_IS_GNUCXX)
if ("${CMAKE_CXX_FLAGS}" MATCHES "--coverage")
# We disable debug code for the coverage so it won't see assertion and other things only enabled for debugging
target_compile_definitions(common INTERFACE NDEBUG)
else()
# Here we enable the undefined behavior sanitizer for the tests, benchmarks and the viz
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=undefined" HAVE_FLAG_SANITIZE_UNDEFINED)
if(HAVE_FLAG_SANITIZE_UNDEFINED)
target_compile_options(common INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined>)
# TODO: Replace with target link option once we support CMake 3.13
target_link_libraries(common INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined>)
endif()
endif()
endif()
if (EARCUT_WARNING_IS_ERROR)
target_compile_options(common INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror>
)
endif()
if (EARCUT_BUILD_TESTS)
enable_testing()
add_executable(tests test/tap.cpp test/tap.hpp test/test.cpp $<TARGET_OBJECTS:fixtures>)
target_link_libraries(tests PRIVATE earcut_hpp common)
add_test(NAME earcut_tests COMMAND tests)
endif()
if (EARCUT_BUILD_BENCH)
add_executable(bench test/bench.cpp $<TARGET_OBJECTS:fixtures>)
target_link_libraries(bench PRIVATE earcut_hpp common)
endif()
if (EARCUT_BUILD_VIZ)
add_executable(viz test/viz.cpp $<TARGET_OBJECTS:fixtures>)
# Setup viz target
# OpenGL
# linux: xorg-dev libgl1-mesa-glx libgl1-mesa-dev
# windows: in the windows sdk
find_package(OpenGL REQUIRED)
# GLFW3
find_package(glfw3 QUIET) # try to use the system default
if (NOT glfw3_FOUND)
if(EXISTS "${PROJECT_SOURCE_DIR}/.gitmodules")
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_QUIET
ERROR_QUIET
)
endif()
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target" FORCE)
add_subdirectory(glfw)
endif()
target_compile_definitions(viz PRIVATE GL_SILENCE_DEPRECATION)
# TODO: Using old variables for OpenGL package since they were added in CMake 3.8
target_link_libraries(viz PRIVATE earcut_hpp common glfw ${OPENGL_LIBRARIES})
target_include_directories(viz PRIVATE ${OPENGL_INCLUDE_DIR})
endif()
install(
DIRECTORY include/mapbox
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.hpp"
)
install(TARGETS earcut_hpp EXPORT earcut_hpp-config)
# Since there is two projects, we need to export into the parent directory
export(
TARGETS earcut_hpp
NAMESPACE earcut_hpp::
FILE "${PROJECT_BINARY_DIR}/earcut_hpp-config.cmake"
)
install(EXPORT earcut_hpp-config
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/earcut_hpp"
NAMESPACE earcut_hpp::
)