-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
158 lines (131 loc) · 7.22 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
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.1)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmakes")
include(Common)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Sets the configuration to build (Debug, Release, etc...)")
endif()
# Compile and Link settings
set(COMPILE_AND_LINK_EXTRA_FLAGS "")
if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(COMPILE_AND_LINK_EXTRA_FLAGS "${COMPILE_AND_LINK_EXTRA_FLAGS} -fsigned-char")
elseif(NOT CMAKE_VERSION VERSION_LESS "3.1")
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_C_STANDARD "11")
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD "11")
endif()
if (CMAKE_COMPILER_IS_GNUCXX)
set(COMPILE_AND_LINK_EXTRA_FLAGS "${COMPILE_AND_LINK_EXTRA_FLAGS} -Wall -Wextra -Wundef")
endif ()
option (WARNINGS_AS_ERRORS "Specifies whether to treat warnings as errors. Recommended at developing time." OFF)
if (WARNINGS_AS_ERRORS)
if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
set(COMPILE_AND_LINK_EXTRA_FLAGS "${COMPILE_AND_LINK_EXTRA_FLAGS} -Werror")
elseif (MSVC)
set(COMPILE_AND_LINK_EXTRA_FLAGS "${COMPILE_AND_LINK_EXTRA_FLAGS} /WX")
else ()
message (WARNING "You've specified \"WARNINGS_AS_ERRORS\" as \"ON\", but we don't know how to make it for your compiler. If you wish you can specifiy the required flags manually.")
endif ()
endif ()
if (MINGW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-attributes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes")
endif()
# Activating the default multi-processor build setting for all Visual Studio versions
if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /EHsc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILE_AND_LINK_EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_AND_LINK_EXTRA_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COMPILE_AND_LINK_EXTRA_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${COMPILE_AND_LINK_EXTRA_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${COMPILE_AND_LINK_EXTRA_FLAGS}")
# set build output locations
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
if (WIN32)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
endif()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
#cmake_dependent_option( BUILD_MSVC_STATIC_RUNTIME "Specifies whether to the static runtime (/MT and /MTd) or the DLL runtime (/MD and /MDd).
#NOTE: This will also affect which set of dependency libraries are linked with." FALSE "MSVC" FALSE )
#if (WIN32)
# add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOMINMAX)
# if (MSVC AND BUILD_MSVC_STATIC_RUNTIME)
# foreach(_BUILD_CONFIG DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
# foreach(_BUILD_VARS CMAKE_CXX_FLAGS_${_BUILD_CONFIG} CMAKE_C_FLAGS_${_BUILD_CONFIG})
# string(REGEX REPLACE /MD /MT ${_BUILD_VARS} ${${_BUILD_VARS}})
# endforeach()
# endforeach()
# endif()
#endif()
if (WIN32 OR APPLE)
set(BUILD_SUFFIX "_d" CACHE STRING "String holding a suffix appended to the name of output binaries (under CMake build, only used for debug).")
else()
set(BUILD_SUFFIX "" CACHE STRING "String holding a suffix appended to the name of output binaries (under CMake build, only used for debug).")
endif()
if (BUILD_SUFFIX)
set(HAS_BUILD_SUFFIX TRUE)
set(CMAKE_DEBUG_POSTFIX ${BUILD_SUFFIX})
endif()
## Search for ccache
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set(ENV(CCACHE_CPP2) "yes")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
################################################################################
if (WIN32)
#find_package(WindowsSDK)
message ("CMAKE_VS_PLATFORM_NAME: ${CMAKE_VS_PLATFORM_NAME}")
message ("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
#set(WinSDK C:/Program Files (x86)/Windows Kits/10)
get_filename_component(WindowsSDK_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE)
message(STATUS "WindowsSDK_ROOT: ${WindowsSDK_ROOT}")
list(APPEND WindowsSDK_INCLUDE_DIR ${WindowsSDK_ROOT}/Include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/shared)
list(APPEND WindowsSDK_INCLUDE_DIR ${WindowsSDK_ROOT}/Include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/um)
list(APPEND WindowsSDK_INCLUDE_DIR ${WindowsSDK_ROOT}/Include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/winrt)
list(APPEND WindowsSDK_INCLUDE_DIR ${WindowsSDK_ROOT}/Include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/ucrt)
list(APPEND WindowsSDK_LIB_DIR ${WindowsSDK_ROOT}/Lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/shared/${CMAKE_VS_PLATFORM_NAME})
list(APPEND WindowsSDK_LIB_DIR ${WindowsSDK_ROOT}/Lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/um/${CMAKE_VS_PLATFORM_NAME})
list(APPEND WindowsSDK_LIB_DIR ${WindowsSDK_ROOT}/Lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/winrt/${CMAKE_VS_PLATFORM_NAME})
list(APPEND WindowsSDK_LIB_DIR ${WindowsSDK_ROOT}/Lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/ucrt/${CMAKE_VS_PLATFORM_NAME})
message ("WindowsSDK include dir: ${WindowsSDK_INCLUDE_DIR}")
message ("WindowsSDK library dir: ${WindowsSDK_LIB_DIR}")
include_directories(${WindowsSDK_INCLUDE_DIR})
link_directories(${WindowsSDK_LIB_DIR})
add_definitions(-D_WIN32 -D_MBCS)
endif ()
# project settings
project(OpenGL)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/3rd/glm
${CMAKE_CURRENT_SOURCE_DIR}/3rd/glfw-3.3/include
${CMAKE_CURRENT_SOURCE_DIR}/3rd/glad/include
${CMAKE_CURRENT_SOURCE_DIR}/3rd/stb
${CMAKE_CURRENT_SOURCE_DIR}/3rd/assimp/include
)
link_directories(
${CMAKE_BINARY_DIR}/lib
${CMAKE_BINARY_DIR}/bin
)
add_subdirectory(3rd)
add_subdirectory(src)