Skip to content

Commit

Permalink
cmake: General cleanup
Browse files Browse the repository at this point in the history
- APPEND CMAKE_MODULE_PATH
- Remove overly specific CMake code
- Use CMAKE_SYSTEM_NAME to detect Linux/BSD
- Remove unused code
- Simplify install target code
- Use PRIVATE instead of PUBLIC
- Prefer target based commands
  • Loading branch information
juan-lunarg committed Sep 29, 2023
1 parent 576f328 commit 6587536
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 42 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.
# ~~~
cmake_minimum_required(VERSION 3.17.2)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

project(Vulkan-Tools)

Expand All @@ -25,19 +26,10 @@ set(API_TYPE "vulkan")

add_subdirectory(scripts)

# User-interface declarations ----------------------------------------------------------------------------------------------------
# This section contains variables that affect development GUIs (e.g. CMake GUI and IDEs), such as option(), folders, and variables
# with the CACHE property.

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(BUILD_CUBE "Build cube" ON)
option(BUILD_VULKANINFO "Build vulkaninfo" ON)
option(BUILD_ICD "Build icd" ON)

if (UNIX AND NOT APPLE) # i.e. Linux
option(ENABLE_ADDRESS_SANITIZER "Use addres sanitization" OFF)
endif()
option(ENABLE_ADDRESS_SANITIZER "Use address sanitization")

if(WIN32)
# Optional: Allow specify the exact version used in the vulkaninfo executable
Expand Down
24 changes: 6 additions & 18 deletions cube/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(CUBE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
set(SCRIPTS_DIR "${PROJECT_SOURCE_DIR}/scripts")


if(UNIX AND NOT APPLE) # i.e. Linux
if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
Expand Down Expand Up @@ -97,7 +97,7 @@ elseif(ANDROID)
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
elseif(APPLE)
add_definitions(-DVK_USE_PLATFORM_METAL_EXT)
elseif(UNIX AND NOT APPLE) # i.e. Linux
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
if(NOT CUBE_WSI_SELECTION)
set(CUBE_WSI_SELECTION "XCB")
endif()
Expand Down Expand Up @@ -199,12 +199,6 @@ elseif(NOT WIN32)
target_link_options(vkcube PUBLIC -fsanitize=address)
endif ()
else()
if(CMAKE_CL_64)
set(LIB_DIR "Win64")
else()
set(LIB_DIR "Win32")
endif()

add_executable(vkcube
WIN32
cube.c
Expand All @@ -225,7 +219,7 @@ if(APPLE)
fixup_bundle(\${CMAKE_INSTALL_PREFIX}/cube/vkcube.app \"\" \"${Vulkan_LIBRARY_DIR}\")
")
else()
install(TARGETS vkcube RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS vkcube)
endif()

# ----------------------------------------------------------------------------
Expand All @@ -249,12 +243,6 @@ elseif(NOT WIN32)
target_link_options(vkcubepp PUBLIC -fsanitize=address)
endif ()
else()
if(CMAKE_CL_64)
set(LIB_DIR "Win64")
else()
set(LIB_DIR "Win32")
endif()

add_executable(vkcubepp
WIN32
cube.cpp
Expand All @@ -275,13 +263,13 @@ if(APPLE)
fixup_bundle(\${CMAKE_INSTALL_PREFIX}/cube/vkcubepp.app \"\" \"${Vulkan_LIBRARY_DIR}\")
")
else()
install(TARGETS vkcubepp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS vkcubepp)
endif()

# ----------------------------------------------------------------------------
# vkcube-wayland

if(UNIX AND NOT APPLE) # i.e. Linux
if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
if(BUILD_WSI_WAYLAND_SUPPORT AND EXISTS ${WAYLAND_PROTOCOLS_PATH}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml)
set(CUBE_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR} ${CUBE_INCLUDE_DIRS})
link_libraries(${WAYLAND_CLIENT_LIBRARIES})
Expand All @@ -305,7 +293,7 @@ if(UNIX AND NOT APPLE) # i.e. Linux
if (NEED_RT)
target_link_libraries(vkcube-wayland rt)
endif()
install(TARGETS vkcube-wayland RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS vkcube-wayland)

if (ENABLE_ADDRESS_SANITIZER)
target_compile_options(vkcube-wayland PUBLIC -fsanitize=address)
Expand Down
2 changes: 1 addition & 1 deletion icd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(WIN32)
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DVK_USE_PLATFORM_WIN32_KHX -DWIN32_LEAN_AND_MEAN)
elseif(APPLE)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
elseif(UNIX AND NOT APPLE) # i.e. Linux
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
if(BUILD_WSI_XCB_SUPPORT)
add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DVK_USE_PLATFORM_XCB_KHX)
endif()
Expand Down
31 changes: 18 additions & 13 deletions vulkaninfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ endif()

target_compile_definitions(vulkaninfo PRIVATE -DVK_ENABLE_BETA_EXTENSIONS)

if(UNIX AND NOT APPLE) # i.e. Linux
if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
Expand Down Expand Up @@ -97,8 +97,8 @@ if(UNIX AND NOT APPLE) # i.e. Linux
endif()

if (ENABLE_ADDRESS_SANITIZER)
target_compile_options(vulkaninfo PUBLIC -fsanitize=address)
target_link_options(vulkaninfo PUBLIC -fsanitize=address)
target_compile_options(vulkaninfo PRIVATE -fsanitize=address)
target_link_options(vulkaninfo PRIVATE -fsanitize=address)
endif ()
endif()

Expand All @@ -111,22 +111,27 @@ endif()
target_link_libraries(vulkaninfo Vulkan::Headers)

if(WIN32)
target_compile_definitions(vulkaninfo PUBLIC -DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -DVK_NO_PROTOTYPES)
if(MSVC AND NOT MSVC_VERSION LESS 1900)
# If MSVC, Enable control flow guard
message(STATUS "Building vulkaninfo with control flow guard")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/guard:cf>")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
endif()
target_compile_definitions(vulkaninfo PRIVATE
VK_USE_PLATFORM_WIN32_KHR
WIN32_LEAN_AND_MEAN
_CRT_SECURE_NO_WARNINGS
VK_NO_PROTOTYPES
)

message(STATUS "Building vulkaninfo with control flow guard")
target_compile_options(vulkaninfo PRIVATE /guard:cf)
target_link_options(vulkaninfo PRIVATE /guard:cf)

elseif(APPLE)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK -DVK_USE_PLATFORM_METAL_EXT)
target_compile_definitions(vulkaninfo PRIVATE
VK_USE_PLATFORM_MACOS_MVK
VK_USE_PLATFORM_METAL_EXT
)
endif()

if(APPLE)
install(TARGETS vulkaninfo RUNTIME DESTINATION "vulkaninfo")
else()
install(TARGETS vulkaninfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS vulkaninfo)
endif()

0 comments on commit 6587536

Please sign in to comment.