-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·128 lines (119 loc) · 4.5 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.21)
PROJECT(TinyVisualizer)
#COMPILE SETTINGS
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Compiler optimization level")
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF()
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
MESSAGE(STATUS "Build type: Debug")
IF(MSVC)
SET(CMAKE_CXX_FLAGS "/openmp /bigobj /Wall /std:c++17 ${CMAKE_CXX_FLAGS}")
ELSE(MSVC)
ADD_COMPILE_DEFINITIONS(_GLIBCXX_DEBUG=1)
ADD_COMPILE_DEFINITIONS(_GLIBCXX_USE_CXX11_ABI=1)
SET(CMAKE_CXX_FLAGS "-fopenmp -O0 -Wall -fPIC -std=c++17 -Wno-unused-function -Wno-unused-local-typedefs ${CMAKE_CXX_FLAGS}")
ENDIF(MSVC)
ELSE()
MESSAGE(STATUS "Build type: Release")
IF(MSVC)
SET(CMAKE_CXX_FLAGS "/openmp /bigobj /Wall /std:c++17 ${CMAKE_CXX_FLAGS}")
ELSE(MSVC)
ADD_COMPILE_DEFINITIONS(_GLIBCXX_USE_CXX11_ABI=1)
SET(CMAKE_CXX_FLAGS "-fopenmp -O3 -Wall -fPIC -std=c++17 -Wno-unused-function -Wno-unused-local-typedefs ${CMAKE_CXX_FLAGS}")
ENDIF(MSVC)
ENDIF()
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
#RTTI Enabled
OPTION(USE_RTTI "Whether to enable native RTTI" ON)
IF(USE_RTTI)
REMOVE_DEFINITIONS(-DCUSTOM_RTTI_SUPPORT)
ELSE(USE_RTTI)
ADD_DEFINITIONS(-DCUSTOM_RTTI_SUPPORT)
IF(MSVC)
SET(CMAKE_CXX_FLAGS "/GR- ${CMAKE_CXX_FLAGS}")
ELSE(MSVC)
SET(CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}")
ENDIF(MSVC)
ENDIF(USE_RTTI)
#C++11 ABI
OPTION(USE_CXX11_ABI "Whether to use C++11's ABI" ON)
IF(NOT ${USE_CXX11_ABI})
MESSAGE(STATUS "Disabling C++11's ABI")
SET(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 ${CMAKE_CXX_FLAGS}")
ELSE()
MESSAGE(STATUS "Enabling C++11's ABI")
ENDIF()
#LIBRARY
INCLUDE("${PROJECT_SOURCE_DIR}/cmake/LoadLibs.cmake")
#THIRD PARTY HEADERS
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/extern ${PROJECT_SOURCE_DIR}/extern/imgui ${PROJECT_SOURCE_DIR}/extern/glad/include)
MACRO(SEARCH_SOURCE NAME DIRPRJ)
FILE(GLOB_RECURSE header${NAME} ${PROJECT_SOURCE_DIR}/${DIRPRJ}/*.h ${PROJECT_SOURCE_DIR}/${DIRPRJ}/*.hpp ${PROJECT_SOURCE_DIR}/${DIRPRJ}/*.hh)
FILE(GLOB_RECURSE source${NAME} ${PROJECT_SOURCE_DIR}/${DIRPRJ}/*.cpp ${PROJECT_SOURCE_DIR}/${DIRPRJ}/*.cc ${PROJECT_SOURCE_DIR}/${DIRPRJ}/*.c)
ENDMACRO(SEARCH_SOURCE)
SEARCH_SOURCE(TinyVisualizer TinyVisualizer)
SEARCH_SOURCE(GLAD extern/glad)
SEARCH_SOURCE(Python Python)
#BUILD LIBRARY
IF(MSVC)
ADD_LIBRARY(TinyVisualizer STATIC ${sourceTinyVisualizer} ${headerTinyVisualizer} ${sourceGLAD} ${headerGLAD} ${IMGUI})
ELSE(MSVC)
ADD_LIBRARY(TinyVisualizer SHARED ${sourceTinyVisualizer} ${headerTinyVisualizer} ${sourceGLAD} ${headerGLAD} ${IMGUI})
ENDIF(MSVC)
SET_TARGET_PROPERTIES(TinyVisualizer PROPERTIES PUBLIC_HEADER "${headerTinyVisualizer}")
TARGET_LINK_LIBRARIES(TinyVisualizer ${ALL_LIBRARIES})
#PYTHON LIBRARY
IF(Python2_FOUND OR Python3_FOUND)
ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/extern/pybind11)
IF(MSVC)
PYBIND11_ADD_MODULE(pyTinyVisualizer STATIC ${sourcePython} ${headerPython})
ELSE(MSVC)
PYBIND11_ADD_MODULE(pyTinyVisualizer SHARED ${sourcePython} ${headerPython})
ENDIF(MSVC)
TARGET_LINK_LIBRARIES(pyTinyVisualizer PRIVATE TinyVisualizer ${ALL_LIBRARIES})
ENDIF()
#INSTALL LIBRARY
IF(MSVC)
SET(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}")
ELSE(MSVC)
SET(CMAKE_INSTALL_PREFIX "/usr/local")
ENDIF(MSVC)
INSTALL(TARGETS TinyVisualizer
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_BUILD_TYPE}
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_BUILD_TYPE}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/TinyVisualizer)
INSTALL(DIRECTORY extern/glad/include
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN gl.h PATTERN khrplatform.h)
INSTALL(DIRECTORY extern/imgui
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
FILES_MATCHING PATTERN imgui.h PATTERN imconfig.h)
INSTALL(DIRECTORY cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN FindTinyVisualizer.cmake)
#EXE
MACRO(ADD_EXE NAME)
ADD_EXECUTABLE(${NAME} Main/${NAME}.cpp)
TARGET_LINK_LIBRARIES(${NAME} TinyVisualizer ${ALL_LIBRARIES})
ENDMACRO(ADD_EXE)
#DEBUG
ADD_EXE(mainBox2D)
ADD_EXE(mainBullet3D)
ADD_EXE(mainVisibility)
ADD_EXE(mainSphericalBoxAndPoints)
ADD_EXE(mainSelection2D)
ADD_EXE(mainSelection3D)
ADD_EXE(mainMultiview)
ADD_EXE(mainTerrain)
ADD_EXE(mainChecker)
ADD_EXE(mainOctree)
ADD_EXE(mainBezier)
ADD_EXE(mainLight)
ADD_EXE(mainArrow)
ADD_EXE(mainCell)
ADD_EXE(mainCellCmd)
ADD_EXE(mainImGui)
ADD_EXE(mainMesh)