-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
123 lines (99 loc) · 4.16 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
# MIT License
# Copyright (c) 2017 Alberto Taiuti
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 2.8)
project(spirv-utils)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Build mode: debug")
else()
message(STATUS "Build mode: release")
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Export commands for YCM
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Set custom cmake modules path
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
# Set default cmake build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo\
MinSizeRel. Default is Debug."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG}")
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 /EHsc")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra")
endif()
if(UNIX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Color error output
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -stdlib=libc++")
endif()
endif()
message(STATUS "Compiler custom flags are: ${CMAKE_CXX_FLAGS}")
message(STATUS "Compiler debug flags are: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "Compiler release flags are: ${CMAKE_CXX_FLAGS_RELEASE}")
# Setup handy variables
set(SUT_SOURCE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}")
set(SPIRV-HEADERS_SOURCE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/external/SPIRV-Headers")
set(CATCH_SOURCE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/external/catch")
# Add external projects
add_subdirectory(${SPIRV-HEADERS_SOURCE_DIR})
# Set headers and sources
set(SUT_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/spv_utils.h)
set(SUT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/source/spv_utils.cpp)
# Create library
add_library(sut
${SUT_HEADERS}
${SUT_SOURCES})
# Set include directories for targets
target_include_directories(sut PUBLIC
${SUT_SOURCE_DIR}/include
${SPIRV-HEADERS_SOURCE_DIR}/include)
option(SUT_BUILD_TESTS "Build the tests" OFF)
if(SUT_BUILD_TESTS)
add_subdirectory(unit_tests)
endif(SUT_BUILD_TESTS)
option(SUT_BUILD_EXAMPLES "Build the examples" ON)
if(SUT_BUILD_EXAMPLES)
add_executable(main_example ${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp)
target_include_directories(main_example PUBLIC
${SUT_SOURCE_DIR}/include
${SPIRV-HEADERS_SOURCE_DIR}/include)
target_link_libraries(main_example sut)
add_executable(invert_position_y_example ${CMAKE_CURRENT_SOURCE_DIR}/source/invert_position_y.cpp)
target_include_directories(invert_position_y_example PUBLIC
${SUT_SOURCE_DIR}/include
${SPIRV-HEADERS_SOURCE_DIR}/include)
target_link_libraries(invert_position_y_example sut)
endif(SUT_BUILD_EXAMPLES)