1cmake_minimum_required (VERSION 2.8.11)
2
3macro(run_vk_helper subcmd)
4	add_custom_command(OUTPUT ${ARGN}
5		COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk_helper.py --${subcmd} ${PROJECT_SOURCE_DIR}/include/vulkan/vulkan.h --abs_out_dir ${CMAKE_CURRENT_BINARY_DIR}
6		DEPENDS ${PROJECT_SOURCE_DIR}/vk_helper.py ${PROJECT_SOURCE_DIR}/include/vulkan/vulkan.h
7	)
8endmacro()
9
10macro(run_vk_layer_generate subcmd output)
11	add_custom_command(OUTPUT ${output}
12		COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk-layer-generate.py ${DisplayServer} ${subcmd} ${PROJECT_SOURCE_DIR}/include/vulkan/vulkan.h > ${output}
13		DEPENDS ${PROJECT_SOURCE_DIR}/vk-layer-generate.py ${PROJECT_SOURCE_DIR}/include/vulkan/vulkan.h ${PROJECT_SOURCE_DIR}/vulkan.py
14	)
15endmacro()
16
17macro(run_vk_layer_xml_generate subcmd output)
18	add_custom_command(OUTPUT ${output}
19		COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/genvk.py -registry ${PROJECT_SOURCE_DIR}/vk.xml ${output}
20		DEPENDS ${PROJECT_SOURCE_DIR}/vk.xml ${PROJECT_SOURCE_DIR}/generator.py ${PROJECT_SOURCE_DIR}/genvk.py ${PROJECT_SOURCE_DIR}/reg.py
21	)
22endmacro()
23set(LAYER_JSON_FILES
24    VkLayer_core_validation
25    VkLayer_image
26    VkLayer_object_tracker
27    VkLayer_unique_objects
28    VkLayer_parameter_validation
29    VkLayer_swapchain
30    VkLayer_threading
31    VkLayer_device_limits
32    )
33
34set(VK_LAYER_RPATH /usr/lib/x86_64-linux-gnu/vulkan/layer:/usr/lib/i386-linux-gnu/vulkan/layer)
35set(CMAKE_INSTALL_RPATH ${VK_LAYER_RPATH})
36
37if (NOT WIN32)
38    # extra setup for out-of-tree builds
39    if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
40        foreach (config_file ${LAYER_JSON_FILES})
41            add_custom_target(${config_file}-json ALL
42                COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json
43                VERBATIM
44                )
45        endforeach(config_file)
46    endif()
47else()
48    if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
49        foreach (config_file ${LAYER_JSON_FILES})
50            FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
51            FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/${config_file}.json dst_json)
52            add_custom_target(${config_file}-json ALL
53                COMMAND copy ${src_json} ${dst_json}
54                VERBATIM
55                )
56        endforeach(config_file)
57    endif()
58endif()
59
60if (WIN32)
61    macro(add_vk_layer target)
62	add_custom_command(OUTPUT VkLayer_${target}.def
63		COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk-generate.py ${DisplayServer} win-def-file VkLayer_${target} layer > VkLayer_${target}.def
64		DEPENDS ${PROJECT_SOURCE_DIR}/vk-generate.py ${PROJECT_SOURCE_DIR}/vk.py
65	)
66	add_library(VkLayer_${target} SHARED ${ARGN} VkLayer_${target}.def)
67    target_link_Libraries(VkLayer_${target} layer_utils)
68	add_dependencies(VkLayer_${target} layer_utils_static)
69	add_dependencies(VkLayer_${target} generate_vk_layer_helpers)
70	set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}/VkLayer_${target}.def")
71    endmacro()
72else()
73    macro(add_vk_layer target)
74	add_library(VkLayer_${target} SHARED ${ARGN})
75    target_link_Libraries(VkLayer_${target} layer_utils)
76	add_dependencies(VkLayer_${target} generate_vk_layer_helpers)
77	set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
78	install(TARGETS VkLayer_${target} DESTINATION ${PROJECT_BINARY_DIR}/install_staging)
79    endmacro()
80endif()
81
82include_directories(
83	${CMAKE_CURRENT_SOURCE_DIR}
84	${CMAKE_CURRENT_SOURCE_DIR}/../loader
85	${CMAKE_CURRENT_SOURCE_DIR}/../include/vulkan
86	${CMAKE_CURRENT_BINARY_DIR}
87	${GLSLANG_SPIRV_INCLUDE_DIR}
88)
89
90if (WIN32)
91    set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
92    set (CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
93    set (CMAKE_CXX_FLAGS_DEBUG   "${CMAKE_CXX_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
94    set (CMAKE_C_FLAGS_DEBUG     "${CMAKE_C_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
95endif()
96if (NOT WIN32)
97    set (CMAKE_CXX_FLAGS "-std=c++11")
98    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith")
99    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith")
100endif()
101
102add_custom_command(OUTPUT vk_dispatch_table_helper.h
103	COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk-generate.py ${DisplayServer} dispatch-table-ops layer > vk_dispatch_table_helper.h
104	DEPENDS ${PROJECT_SOURCE_DIR}/vk-generate.py ${PROJECT_SOURCE_DIR}/vulkan.py)
105
106run_vk_helper(gen_enum_string_helper vk_enum_string_helper.h)
107run_vk_helper(gen_struct_wrappers
108	vk_struct_string_helper.h
109    vk_struct_string_helper_cpp.h
110	vk_struct_string_helper_no_addr.h
111	vk_struct_string_helper_no_addr_cpp.h
112    vk_struct_size_helper.h
113    vk_struct_size_helper.c
114	vk_struct_wrappers.h
115	vk_struct_wrappers.cpp
116    vk_safe_struct.h
117    vk_safe_struct.cpp
118)
119
120add_custom_target(generate_vk_layer_helpers DEPENDS
121	vk_dispatch_table_helper.h
122	vk_enum_string_helper.h
123	vk_struct_string_helper.h
124	vk_struct_string_helper_no_addr.h
125    vk_struct_string_helper_cpp.h
126	vk_struct_string_helper_no_addr_cpp.h
127    vk_struct_size_helper.h
128    vk_struct_size_helper.c
129	vk_struct_wrappers.h
130	vk_struct_wrappers.cpp
131    vk_safe_struct.h
132    vk_safe_struct.cpp
133)
134
135run_vk_layer_generate(object_tracker object_tracker.cpp)
136run_vk_layer_xml_generate(Threading thread_check.h)
137run_vk_layer_generate(unique_objects unique_objects.cpp)
138run_vk_layer_xml_generate(ParamChecker parameter_validation.h)
139
140add_library(layer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp)
141if (WIN32)
142    add_library(layer_utils_static STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp)
143    set_target_properties(layer_utils_static PROPERTIES OUTPUT_NAME layer_utils)
144    target_link_libraries(layer_utils)
145else()
146    install(TARGETS layer_utils DESTINATION ${PROJECT_BINARY_DIR}/install_staging)
147endif()
148add_vk_layer(core_validation core_validation.cpp vk_layer_table.cpp)
149add_vk_layer(device_limits device_limits.cpp vk_layer_table.cpp vk_layer_utils.cpp)
150add_vk_layer(image image.cpp vk_layer_table.cpp)
151add_vk_layer(swapchain swapchain.cpp vk_layer_table.cpp)
152# generated
153add_vk_layer(object_tracker object_tracker.cpp vk_layer_table.cpp)
154add_vk_layer(threading threading.cpp thread_check.h vk_layer_table.cpp)
155add_vk_layer(unique_objects unique_objects.cpp vk_layer_table.cpp vk_safe_struct.cpp)
156add_vk_layer(parameter_validation parameter_validation.cpp parameter_validation.h vk_layer_table.cpp)
157