1if(NOT WIN32)
2    if (BUILD_WSI_XCB_SUPPORT)
3        find_package(XCB REQUIRED)
4    endif()
5    if (BUILD_WSI_XLIB_SUPPORT)
6        find_package(X11 REQUIRED)
7    endif()
8    if (BUILD_WSI_WAYLAND_SUPPORT)
9        find_package(Wayland REQUIRED)
10    endif()
11endif()
12
13file(GLOB TEXTURES
14  "${PROJECT_SOURCE_DIR}/demos/*.ppm"
15  )
16file(COPY ${TEXTURES} DESTINATION ${CMAKE_BINARY_DIR}/demos)
17
18set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
19set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
20
21if(WIN32)
22  set (LIBRARIES "vulkan-${MAJOR}")
23elseif(UNIX)
24  set (LIBRARIES "vulkan")
25else()
26endif()
27
28if(WIN32)
29    # For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
30    # 32-bit target data goes in build32, and 64-bit target data goes into build.  So, include/link the
31    # appropriate data at build time.
32    if (CMAKE_CL_64)
33        set (BUILDTGT_DIR build)
34    else ()
35        set (BUILDTGT_DIR build32)
36    endif()
37
38    # Use static MSVCRT libraries
39    foreach(configuration in CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
40                             CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO)
41        if(${configuration} MATCHES "/MD")
42            string(REGEX REPLACE "/MD" "/MT" ${configuration} "${${configuration}}")
43        endif()
44    endforeach()
45
46    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-vert.spv
47       COMMAND ${GLSLANG_VALIDATOR} -s -V -o ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${PROJECT_SOURCE_DIR}/demos/cube.vert
48       DEPENDS cube.vert ${GLSLANG_VALIDATOR}
49       )
50    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-frag.spv
51       COMMAND ${GLSLANG_VALIDATOR} -s -V -o ${CMAKE_BINARY_DIR}/demos/cube-frag.spv ${PROJECT_SOURCE_DIR}/demos/cube.frag
52       DEPENDS cube.frag ${GLSLANG_VALIDATOR}
53       )
54   file(COPY cube.vcxproj.user DESTINATION ${CMAKE_BINARY_DIR}/demos)
55   file(COPY vulkaninfo.vcxproj.user DESTINATION ${CMAKE_BINARY_DIR}/demos)
56else()
57    if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
58        add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-vert.spv
59            COMMAND ${GLSLANG_VALIDATOR} -s -V -o cube-vert.spv ${PROJECT_SOURCE_DIR}/demos/cube.vert
60            DEPENDS cube.vert ${GLSLANG_VALIDATOR}
61            )
62        add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-frag.spv
63            COMMAND ${GLSLANG_VALIDATOR} -s -V -o cube-frag.spv ${PROJECT_SOURCE_DIR}/demos/cube.frag
64            DEPENDS cube.frag ${GLSLANG_VALIDATOR}
65            )
66    endif()
67endif()
68
69if(NOT WIN32)
70    if(BUILD_WSI_XCB_SUPPORT)
71        include_directories(${XCB_INCLUDE_DIRS})
72        link_libraries(${XCB_LIBRARIES})
73    endif()
74    if(BUILD_WSI_XLIB_SUPPORT)
75        include_directories(${X11_INCLUDE_DIR})
76        link_libraries(${X11_LIBRARIES})
77    endif()
78    if(BUILD_WSI_WAYLAND_SUPPORT)
79        include_directories(${WAYLAND_CLIENT_INCLUDE_DIR})
80        link_libraries(${WAYLAND_CLIENT_LIBRARIES})
81    endif()
82
83    include_directories ("${PROJECT_SOURCE_DIR}/icd/common")
84    link_libraries(vulkan m)
85endif()
86if(WIN32)
87    include_directories (
88       "${PROJECT_SOURCE_DIR}/icd/common"
89       )
90
91    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES")
92    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES")
93endif()
94
95add_executable(vulkaninfo vulkaninfo.c)
96target_link_libraries(vulkaninfo ${LIBRARIES})
97
98if(NOT WIN32)
99    if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
100        add_executable(cube cube.c ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
101        target_link_libraries(cube ${LIBRARIES})
102    endif()
103else()
104    if (CMAKE_CL_64)
105        set (LIB_DIR "Win64")
106    else()
107        set (LIB_DIR "Win32")
108    endif()
109
110    add_executable(cube WIN32 cube.c ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
111    target_link_libraries(cube ${LIBRARIES})
112endif()
113
114if(NOT WIN32)
115    if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
116        add_executable(cubepp cube.cpp ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
117        target_link_libraries(cubepp ${LIBRARIES})
118    endif()
119else()
120    if (CMAKE_CL_64)
121        set (LIB_DIR "Win64")
122    else()
123        set (LIB_DIR "Win32")
124    endif()
125
126    add_executable(cubepp WIN32 cube.cpp ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
127    target_link_libraries(cubepp ${LIBRARIES})
128endif()
129
130if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
131    add_subdirectory(smoke)
132endif()
133
134if(UNIX)
135    install(TARGETS vulkaninfo DESTINATION bin)
136endif()
137