2 # Copyright (c) 2018-2019 Valve Corporation
3 # Copyright (c) 2018-2019 LunarG, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # CMakeLists.txt file for building Vulkaninfo
22 # Setup the vulkaninfo.rc file to contain the correct info
23 # Optionally uses the VULKANINFO_BUILD_DLL_VERSIONINFO build option to allow setting the exact build version
24 # When VULKANINFO_BUILD_DLL_VERSIONINFO is not provided, "Dev Build" is added to the version string
26 if ("$CACHE{VULKANINFO_BUILD_DLL_VERSIONINFO}" STREQUAL "")
27 # Default version - for when no version is provided
28 set(VULKANINFO_RC_VERSION "1.0.1111.2222")
29 set(VULKANINFO_VER_FILE_VERSION_STR "\"${VULKANINFO_RC_VERSION}.Dev Build\"")
30 set(VULKANINFO_VER_FILE_DESCRIPTION_STR "\"Vulkan Loader - Dev Build\"")
32 set(VULKANINFO_RC_VERSION "$CACHE{VULKANINFO_BUILD_DLL_VERSIONINFO}")
33 set(VULKANINFO_VER_FILE_VERSION_STR "\"${VULKANINFO_RC_VERSION}\"")
34 set(VULKANINFO_VER_FILE_DESCRIPTION_STR "\"Vulkan Loader\"")
37 # RC file wants the value of FILEVERSION to separated by commas
38 string(REPLACE "." ", " VULKANINFO_VER_FILE_VERSION "${VULKANINFO_RC_VERSION}")
40 # Configure the file to include the versioning info
41 configure_file(vulkaninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/vulkaninfo.rc)
43 add_executable(vulkaninfo vulkaninfo.cpp ${CMAKE_CURRENT_BINARY_DIR}/vulkaninfo.rc)
45 add_executable(vulkaninfo
47 ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo/metal_view.mm
48 ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo/metal_view.h)
50 add_executable(vulkaninfo vulkaninfo.cpp)
53 target_include_directories(vulkaninfo PRIVATE ${CMAKE_SOURCE_DIR}/vulkaninfo)
54 target_include_directories(vulkaninfo PRIVATE ${CMAKE_SOURCE_DIR}/vulkaninfo/generated)
57 target_link_libraries(vulkaninfo ${CMAKE_DL_LIBS})
60 if(UNIX AND NOT APPLE) # i.e. Linux
61 include(FindPkgConfig)
62 option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
63 option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
64 option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
65 option(BUILD_WSI_DIRECTFB_SUPPORT "Build DirectFB WSI support" OFF)
67 if(BUILD_WSI_XCB_SUPPORT)
68 find_package(XCB REQUIRED)
69 target_include_directories(vulkaninfo PRIVATE ${XCB_INCLUDE_DIRS})
70 target_link_libraries(vulkaninfo ${XCB_LIBRARIES})
71 target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_XCB_KHR -DVK_NO_PROTOTYPES)
74 if(BUILD_WSI_XLIB_SUPPORT)
75 find_package(X11 REQUIRED)
76 target_include_directories(vulkaninfo PRIVATE ${X11_INCLUDE_DIR})
77 target_link_libraries(vulkaninfo ${X11_LIBRARIES})
78 target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_XLIB_KHR -DVK_NO_PROTOTYPES)
81 if(BUILD_WSI_WAYLAND_SUPPORT)
82 find_package(Wayland REQUIRED)
83 target_include_directories(vulkaninfo PRIVATE ${WAYLAND_CLIENT_INCLUDE_DIR})
84 target_link_libraries(vulkaninfo ${WAYLAND_CLIENT_LIBRARIES})
85 target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_WAYLAND_KHR -DVK_NO_PROTOTYPES)
88 if(BUILD_WSI_DIRECTFB_SUPPORT)
89 find_package(DirectFB REQUIRED)
90 target_include_directories(vulkaninfo PRIVATE ${DIRECTFB_INCLUDE_DIR})
91 target_link_libraries(vulkaninfo ${DIRECTFB_LIBRARIES})
92 target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_DIRECTFB_EXT -DVK_NO_PROTOTYPES)
97 # We do this so vulkaninfo is linked to an individual library and NOT a framework.
98 target_link_libraries(vulkaninfo ${Vulkan_LIBRARY} "-framework AppKit -framework QuartzCore")
99 target_include_directories(vulkaninfo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo ${VulkanHeaders_INCLUDE_DIR})
101 target_include_directories(vulkaninfo PRIVATE ${VulkanHeaders_INCLUDE_DIR})
104 # Create vulkaninfo application bundle for MacOS
106 include(${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo.cmake)
110 target_compile_definitions(vulkaninfo PUBLIC -DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -DVK_NO_PROTOTYPES)
111 if(MSVC AND NOT MSVC_VERSION LESS 1900)
112 # If MSVC, Enable control flow guard
113 message(STATUS "Building vulkaninfo with control flow guard")
114 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/guard:cf>")
115 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf")
116 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
119 # Use static MSVCRT libraries
120 foreach(configuration
123 CMAKE_C_FLAGS_MINSIZEREL
124 CMAKE_C_FLAGS_RELEASE
125 CMAKE_C_FLAGS_RELWITHDEBINFO
126 CMAKE_CXX_FLAGS_DEBUG
127 CMAKE_CXX_FLAGS_MINSIZEREL
128 CMAKE_CXX_FLAGS_RELEASE
129 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
130 if(${configuration} MATCHES "/MD")
135 "${${configuration}}")
139 add_definitions(-DVK_USE_PLATFORM_MACOS_MVK -DVK_USE_PLATFORM_METAL_EXT)
143 install(TARGETS vulkaninfo RUNTIME DESTINATION "vulkaninfo")
145 install(TARGETS vulkaninfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})