forked from KhronosGroup/SPIRV-Reflect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
116 lines (101 loc) · 6.11 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
cmake_minimum_required(VERSION 3.1)
project(spirv-reflect)
OPTION(SPIRV_REFLECT_EXECUTABLE "Build spirv-reflect executable" ON)
OPTION(SPIRV_REFLECT_EXAMPLES "Build stripper examples" ON)
OPTION(SPIRV_REFLECT_STRIPPER "Build stripper utility" OFF)
OPTION(SPIRV_REFLECT_STATIC_LIB "Build a SPIRV-Reflect static library" OFF)
OPTION(SPIRV_REFLECT_BUILD_TESTS "Build the SPIRV-Reflect test suite" OFF)
OPTION(SPIRV_REFLECT_ENABLE_ASSERTS "Enable asserts for debugging" OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
if (SPIRV_REFLECT_EXECUTABLE)
# ==========================================================================
# Compile spirv_reflect.c as C
# ==========================================================================
add_executable(spirv-reflect ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
target_compile_options(spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror>)
if (SPIRV_REFLECT_ENABLE_ASSERTS)
target_compile_definitions(spirv-reflect PRIVATE SPIRV_REFLECT_ENABLE_ASSERTS)
endif()
set_target_properties(spirv-reflect PROPERTIES CXX_STANDARD 11)
target_include_directories(spirv-reflect PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
target_compile_definitions(spirv-reflect PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
install(TARGETS spirv-reflect RUNTIME DESTINATION bin)
# ==========================================================================
# Compile spirv_reflect.c as C++
# ==========================================================================
add_executable(spirv-reflect-pp ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
target_compile_options(spirv-reflect-pp PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror>)
if (SPIRV_REFLECT_ENABLE_ASSERTS)
target_compile_definitions(spirv-reflect-pp PRIVATE SPIRV_REFLECT_ENABLE_ASSERTS)
endif()
set_target_properties(spirv-reflect-pp PROPERTIES CXX_STANDARD 11)
target_include_directories(spirv-reflect-pp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
target_compile_definitions(spirv-reflect-pp PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
install(TARGETS spirv-reflect-pp RUNTIME DESTINATION bin)
endif()
if (SPIRV_REFLECT_EXAMPLES)
add_subdirectory(examples)
endif()
if (SPIRV_REFLECT_STRIPPER)
add_subdirectory(util/stripper)
endif()
if (SPIRV_REFLECT_BUILD_TESTS)
message("Tests are enabled!")
SET(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject" FORCE)
SET(BUILD_GTEST ON CACHE BOOL "Builds the googletest subproject" FORCE)
SET(INSTALL_GTEST OFF CACHE BOOL "Enable installation of googletest. (Projects embedding googletest generally turn this OFF.)" FORCE)
SET(gtest_force_shared_crt ON CACHE BOOL "Enable DLL for C runtime libraries on Windows" FORCE)
add_subdirectory(third_party/googletest)
add_executable(test-spirv-reflect ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-spirv-reflect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
set_target_properties(test-spirv-reflect PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
CXX_STANDARD 11)
target_compile_definitions(test-spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>)
target_link_libraries(test-spirv-reflect gtest_main)
target_include_directories(test-spirv-reflect PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(TARGET test-spirv-reflect POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/tests)
endif()
if(SPIRV_REFLECT_STATIC_LIB)
add_library(spirv-reflect-static STATIC ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c)
target_include_directories(spirv-reflect-static
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(TARGETS spirv-reflect-static LIBRARY DESTINATION lib)
endif()