Upgrade to upstream v1.3.240
[platform/upstream/Vulkan-Tools.git] / vulkaninfo / CMakeLists.txt
1 # ~~~
2 # Copyright (c) 2018-2023 Valve Corporation
3 # Copyright (c) 2018-2023 LunarG, Inc.
4 #
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
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 # ~~~
17
18 # CMakeLists.txt file for building Vulkaninfo
19
20 if(WIN32)
21     # ~~~
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 strings
25     # ~~~
26     string(TIMESTAMP CURRENT_YEAR "%Y")
27     set(VULKANINFO_CUR_COPYRIGHT_STR "${CURRENT_YEAR}")
28     if ("$CACHE{VULKANINFO_BUILD_DLL_VERSIONINFO}" STREQUAL "")
29         set(VULKANINFO_RC_VERSION "${VulkanHeaders_VERSION}")
30         set(VULKANINFO_VER_FILE_VERSION_STR "\"${VULKANINFO_RC_VERSION}.Dev Build\"")
31         set(VULKANINFO_VER_FILE_DESCRIPTION_STR "\"Vulkaninfo - Dev Build\"")
32     else()
33         set(VULKANINFO_RC_VERSION "$CACHE{VULKANINFO_BUILD_DLL_VERSIONINFO}")
34         set(VULKANINFO_VER_FILE_VERSION_STR "\"${VULKANINFO_RC_VERSION}\"")
35         set(VULKANINFO_VER_FILE_DESCRIPTION_STR "\"vulkaninfo\"")
36     endif()
37
38     # RC file wants the value of FILEVERSION to separated by commas
39     string(REPLACE "." ", " VULKANINFO_VER_FILE_VERSION "${VULKANINFO_RC_VERSION}")
40
41     # Configure the file to include the versioning info
42     configure_file(vulkaninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/vulkaninfo.rc)
43
44     add_executable(vulkaninfo vulkaninfo.cpp ${CMAKE_CURRENT_BINARY_DIR}/vulkaninfo.rc)
45     if (MINGW)
46       target_link_libraries(vulkaninfo ucrt)
47     endif ()
48 elseif(APPLE)
49     add_executable(vulkaninfo
50                    vulkaninfo.cpp
51                    ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo/metal_view.mm
52                    ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo/metal_view.h)
53 else()
54     add_executable(vulkaninfo vulkaninfo.cpp)
55 endif()
56
57 target_include_directories(vulkaninfo PRIVATE ${CMAKE_SOURCE_DIR}/vulkaninfo)
58 target_include_directories(vulkaninfo PRIVATE ${CMAKE_SOURCE_DIR}/vulkaninfo/generated)
59
60 if (NOT WIN32)
61     target_link_libraries(vulkaninfo ${CMAKE_DL_LIBS})
62 endif()
63
64 if(UNIX AND NOT APPLE) # i.e. Linux
65     option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
66     option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
67     option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
68     option(BUILD_WSI_DIRECTFB_SUPPORT "Build DirectFB WSI support" OFF)
69
70     find_package(PkgConfig REQUIRED QUIET) # Use PkgConfig to find Linux system libraries
71
72     if(BUILD_WSI_XCB_SUPPORT)
73         pkg_check_modules(XCB REQUIRED QUIET IMPORTED_TARGET xcb)
74         target_link_libraries(vulkaninfo PkgConfig::XCB)
75         target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_XCB_KHR -DVK_NO_PROTOTYPES)
76     endif()
77
78     if(BUILD_WSI_XLIB_SUPPORT)
79         pkg_check_modules(X11 REQUIRED QUIET IMPORTED_TARGET x11)
80         target_link_libraries(vulkaninfo PkgConfig::X11)
81         target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_XLIB_KHR -DVK_NO_PROTOTYPES)
82     endif()
83
84     if(BUILD_WSI_WAYLAND_SUPPORT)
85         find_package(Wayland REQUIRED)
86         target_include_directories(vulkaninfo PRIVATE ${WAYLAND_CLIENT_INCLUDE_DIR})
87         target_link_libraries(vulkaninfo ${WAYLAND_CLIENT_LIBRARIES})
88         target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_WAYLAND_KHR -DVK_NO_PROTOTYPES)
89     endif()
90
91     if(BUILD_WSI_DIRECTFB_SUPPORT)
92         pkg_check_modules(DirectFB REQUIRED QUIET IMPORTED_TARGET directfb)
93         target_link_libraries(vulkaninfo PkgConfig::DirectFB)
94         target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_DIRECTFB_EXT -DVK_NO_PROTOTYPES)
95     endif()
96 endif()
97
98 if(APPLE)
99     # We do this so vulkaninfo is linked to an individual library and NOT a framework.
100     target_link_libraries(vulkaninfo ${Vulkan_LIBRARY} "-framework AppKit -framework QuartzCore")
101     target_include_directories(vulkaninfo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo)
102 endif()
103
104 target_link_libraries(vulkaninfo Vulkan::Headers)
105
106 if(WIN32)
107     target_compile_definitions(vulkaninfo PUBLIC -DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -DVK_NO_PROTOTYPES)
108     if(MSVC AND NOT MSVC_VERSION LESS 1900)
109         # If MSVC, Enable control flow guard
110         message(STATUS "Building vulkaninfo with control flow guard")
111         add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/guard:cf>")
112         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf")
113         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
114     endif()
115
116     # Use static MSVCRT libraries
117     foreach(configuration
118             in
119             CMAKE_C_FLAGS_DEBUG
120             CMAKE_C_FLAGS_MINSIZEREL
121             CMAKE_C_FLAGS_RELEASE
122             CMAKE_C_FLAGS_RELWITHDEBINFO
123             CMAKE_CXX_FLAGS_DEBUG
124             CMAKE_CXX_FLAGS_MINSIZEREL
125             CMAKE_CXX_FLAGS_RELEASE
126             CMAKE_CXX_FLAGS_RELWITHDEBINFO)
127         if(${configuration} MATCHES "/MD")
128             string(REGEX
129                    REPLACE "/MD"
130                            "/MT"
131                            ${configuration}
132                            "${${configuration}}")
133         endif()
134     endforeach()
135 elseif(APPLE)
136     add_definitions(-DVK_USE_PLATFORM_MACOS_MVK -DVK_USE_PLATFORM_METAL_EXT)
137 endif()
138
139 if(APPLE)
140     install(TARGETS vulkaninfo RUNTIME DESTINATION "vulkaninfo")
141 else()
142     install(TARGETS vulkaninfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
143 endif()
144