From e31a32283aa35f482f80067ded5e15a305f2a9ed Mon Sep 17 00:00:00 2001 From: Mike Weiblen Date: Thu, 16 Aug 2018 14:09:08 -0600 Subject: build: CMakeLists.txt cleanup, part 1 This is a first pass reorganization of CMake files in this repo. It consists primarily of dead code/variable removal, simplification, and reformatting by latest cmake-format. bump to cmake_minimum_required(3.4), for ccache support. add USE_CCACHE change 'ln -sf' to '-E create_symlink' clarify why CMAKE_OSX_DEPLOYMENT_TARGET is pre-project(). sync FindVulkan.cmake from upstream CMake v3.8.0 Ensure our repos use identical copy of upstream FindVulkan.cmake Copied from Modules/FindVulkan.cmake https://gitlab.kitware.com/cmake/cmake.git tag: v3.8.0 (commit da7833c5bb1f331162d46a2c664a443c1c641089) change $ to $ The $ genexp is officially deprecated. change CMAKE_SYSTEM_NAME to UNIX/APPLE/WIN32 Note that UNIX evaluates true for OSX, so whenever the code intends "Linux only", we use (UNIX AND NOT APPLE). change TOOLS_TARGET_FOLDER to TOOLS_HELPER_FOLDER for consistency with VVL and VL repos. set Windows install prefix if needed remove unused DisplayServer variable remove deprecated GLSLANG_REPO_ROOT The *_REPO_ROOT mechanism for finding packages is deprecated. remove extra cmake_minimum_required change LIBVK to Vulkan::Vulkan change PYTHON_CMD to PYTHON_EXECUTABLE section rulers, other cosmetics .cmake-format.py 0.4.1 reformat using cmake-format 0.4.1 Change-Id: Id8e5b26fdcf5dc0b383de94cbec75a567704a55e --- cube/CMakeLists.txt | 100 +++++++++++++++++++++-------------------- cube/macOS/cube/cube.cmake | 7 ++- cube/macOS/cubepp/cubepp.cmake | 12 +++-- 3 files changed, 65 insertions(+), 54 deletions(-) (limited to 'cube') diff --git a/cube/CMakeLists.txt b/cube/CMakeLists.txt index 3204214f..59105462 100644 --- a/cube/CMakeLists.txt +++ b/cube/CMakeLists.txt @@ -17,38 +17,27 @@ set(CUBE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/.. ${VulkanHeaders_INCLUDE_DIR}) -find_package(PythonInterp 3 REQUIRED) -set(PYTHON_CMD ${PYTHON_EXECUTABLE}) - set(SCRIPTS_DIR "${PROJECT_SOURCE_DIR}/scripts") if(GLSLANG_INSTALL_DIR) message(STATUS "Using GLSLANG_INSTALL_DIR to look for glslangValidator") find_program(GLSLANG_VALIDATOR names glslangValidator HINTS "${GLSLANG_INSTALL_DIR}/bin") -elseif(GLSLANG_REPO_ROOT) - message(STATUS "Using glslang_repo_root to look for glslangValidator") - find_program(GLSLANG_VALIDATOR names glslangValidator - HINTS "${GLSLANG_REPO_ROOT}/build/standalone/release" - HINTS "${GLSLANG_REPO_ROOT}/build/standalone/debug" - HINTS "${GLSLANG_REPO_ROOT}/build/StandAlone" - HINTS "${GLSLANG_REPO_ROOT}/dbuild/StandAlone" - HINTS "${GLSLANG_REPO_ROOT}/build32/standalone/release" - HINTS "${GLSLANG_REPO_ROOT}/build32/standalone/debug") else() set(GLSLANG_VALIDATOR_NAME "glslangValidator") message(STATUS "Using cmake find_program to look for glslangValidator") - if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - execute_process(COMMAND ${PYTHON_CMD} ${SCRIPTS_DIR}/fetch_glslangvalidator.py glslang-master-windows-x64-Release.zip) + if(WIN32) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${SCRIPTS_DIR}/fetch_glslangvalidator.py glslang-master-windows-x64-Release.zip) set(GLSLANG_VALIDATOR_NAME "glslangValidator.exe") - elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - execute_process(COMMAND ${PYTHON_CMD} ${SCRIPTS_DIR}/fetch_glslangvalidator.py glslang-master-linux-Release.zip) - elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - execute_process(COMMAND ${PYTHON_CMD} ${SCRIPTS_DIR}/fetch_glslangvalidator.py glslang-master-osx-Release.zip) + elseif(APPLE) + execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SCRIPTS_DIR}/fetch_glslangvalidator.py glslang-master-osx-Release.zip) + elseif(UNIX AND NOT APPLE) # i.e. Linux + execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SCRIPTS_DIR}/fetch_glslangvalidator.py glslang-master-linux-Release.zip) endif() find_program(GLSLANG_VALIDATOR NAMES ${GLSLANG_VALIDATOR_NAME} HINTS "${PROJECT_SOURCE_DIR}/glslang/bin") endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(UNIX AND NOT APPLE) # i.e. Linux include(FindPkgConfig) option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON) option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON) @@ -75,9 +64,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") +if(WIN32) add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN) - set(DisplayServer Win32) if(NOT MSVC_VERSION LESS 1900) # Enable control flow guard message(STATUS "Building cube with control flow guard") @@ -85,9 +73,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf") endif() -elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") +elseif(ANDROID) add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR) -elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") +elseif(APPLE) + add_definitions(-DVK_USE_PLATFORM_MACOS_MVK) +elseif(UNIX AND NOT APPLE) # i.e. Linux if(NOT CUBE_WSI_SELECTION) set(CUBE_WSI_SELECTION "XCB") endif() @@ -126,8 +116,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") endif() link_libraries(${API_LOWERCASE} m) -elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - add_definitions(-DVK_USE_PLATFORM_MACOS_MVK) else() message(FATAL_ERROR "Unsupported Platform!") endif() @@ -148,7 +136,11 @@ if(WIN32) CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO) if(${configuration} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${configuration} "${${configuration}}") + string(REGEX + REPLACE "/MD" + "/MT" + ${configuration} + "${${configuration}}") endif() endforeach() @@ -183,9 +175,13 @@ if(APPLE) include(macOS/cube/cube.cmake) elseif(NOT WIN32) if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) - add_executable( - cube cube.c ${PROJECT_SOURCE_DIR}/cube/cube.vert ${PROJECT_SOURCE_DIR}/cube/cube.frag cube.vert.inc cube.frag.inc) - target_link_libraries(cube ${LIBVK}) + add_executable(cube + cube.c + ${PROJECT_SOURCE_DIR}/cube/cube.vert + ${PROJECT_SOURCE_DIR}/cube/cube.frag + cube.vert.inc + cube.frag.inc) + target_link_libraries(cube Vulkan::Vulkan) endif() else() if(CMAKE_CL_64) @@ -194,9 +190,14 @@ else() set(LIB_DIR "Win32") endif() - add_executable( - cube WIN32 cube.c ${PROJECT_SOURCE_DIR}/cube/cube.vert ${PROJECT_SOURCE_DIR}/cube/cube.frag cube.vert.inc cube.frag.inc) - target_link_libraries(cube ${LIBVK}) + add_executable(cube + WIN32 + cube.c + ${PROJECT_SOURCE_DIR}/cube/cube.vert + ${PROJECT_SOURCE_DIR}/cube/cube.frag + cube.vert.inc + cube.frag.inc) + target_link_libraries(cube Vulkan::Vulkan) endif() if(APPLE) @@ -204,13 +205,10 @@ if(APPLE) set_target_properties(cube PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) install(TARGETS cube BUNDLE DESTINATION "cube") # Fix up the library references to be self-contained within the bundle. - install( - CODE - " + install(CODE " include(BundleUtilities) fixup_bundle(\${CMAKE_INSTALL_PREFIX}/cube/cube.app \"\" \"\") - " - ) + ") else() install(TARGETS cube RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() @@ -222,9 +220,13 @@ if(APPLE) include(macOS/cubepp/cubepp.cmake) elseif(NOT WIN32) if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) - add_executable( - cubepp cube.cpp ${PROJECT_SOURCE_DIR}/cube/cube.vert ${PROJECT_SOURCE_DIR}/cube/cube.frag cube.vert.inc cube.frag.inc) - target_link_libraries(cubepp ${LIBVK}) + add_executable(cubepp + cube.cpp + ${PROJECT_SOURCE_DIR}/cube/cube.vert + ${PROJECT_SOURCE_DIR}/cube/cube.frag + cube.vert.inc + cube.frag.inc) + target_link_libraries(cubepp Vulkan::Vulkan) endif() else() if(CMAKE_CL_64) @@ -233,9 +235,14 @@ else() set(LIB_DIR "Win32") endif() - add_executable( - cubepp WIN32 cube.cpp ${PROJECT_SOURCE_DIR}/cube/cube.vert ${PROJECT_SOURCE_DIR}/cube/cube.frag cube.vert.inc cube.frag.inc) - target_link_libraries(cubepp ${LIBVK}) + add_executable(cubepp + WIN32 + cube.cpp + ${PROJECT_SOURCE_DIR}/cube/cube.vert + ${PROJECT_SOURCE_DIR}/cube/cube.frag + cube.vert.inc + cube.frag.inc) + target_link_libraries(cubepp Vulkan::Vulkan) endif() if(APPLE) @@ -243,13 +250,10 @@ if(APPLE) set_target_properties(cubepp PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) install(TARGETS cubepp BUNDLE DESTINATION "cube") # Fix up the library references to be self-contained within the bundle. - install( - CODE - " + install(CODE " include(BundleUtilities) fixup_bundle(\${CMAKE_INSTALL_PREFIX}/cube/cubepp.app \"\" \"\") - " - ) + ") else() install(TARGETS cubepp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/cube/macOS/cube/cube.cmake b/cube/macOS/cube/cube.cmake index 69952eeb..b2b6ba53 100644 --- a/cube/macOS/cube/cube.cmake +++ b/cube/macOS/cube/cube.cmake @@ -38,10 +38,13 @@ add_executable(cube MACOSX_BUNDLE ${cube_SRCS} ${cube_HDRS} ${cube_RESOURCES} cu if(NOT ${CMAKE_GENERATOR} MATCHES "^Xcode.*") # Compile the storyboard file with the ibtool. add_custom_command(TARGET cube POST_BUILD - COMMAND ${IBTOOL} --errors --warnings --notices + COMMAND ${IBTOOL} + --errors + --warnings + --notices --output-format human-readable-text --compile ${CMAKE_CURRENT_BINARY_DIR}/cube.app/Contents/Resources/Main.storyboardc - ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cube/Resources/Main.storyboard + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cube/Resources/Main.storyboard COMMENT "Compiling storyboard") endif() diff --git a/cube/macOS/cubepp/cubepp.cmake b/cube/macOS/cubepp/cubepp.cmake index 7e27e9c6..2b523a98 100644 --- a/cube/macOS/cubepp/cubepp.cmake +++ b/cube/macOS/cubepp/cubepp.cmake @@ -22,8 +22,9 @@ set(cubepp_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/AppDelegate.mm ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/DemoViewController.mm) -set(cubepp_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/AppDelegate.h - ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/DemoViewController.h) +set( + cubepp_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/AppDelegate.h ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/DemoViewController.h + ) set(cubepp_RESOURCES ${CMAKE_BINARY_DIR}/staging-json/MoltenVK_icd.json ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Resources/LunarGIcon.icns) @@ -39,10 +40,13 @@ add_executable(cubepp MACOSX_BUNDLE ${cubepp_SRCS} ${cubepp_HDRS} ${cubepp_RESOU if(NOT ${CMAKE_GENERATOR} MATCHES "^Xcode.*") # Compile the storyboard file with the ibtool. add_custom_command(TARGET cubepp POST_BUILD - COMMAND ${IBTOOL} --errors --warnings --notices + COMMAND ${IBTOOL} + --errors + --warnings + --notices --output-format human-readable-text --compile ${CMAKE_CURRENT_BINARY_DIR}/cubepp.app/Contents/Resources/Main.storyboardc - ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Resources/Main.storyboard + ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cubepp/Resources/Main.storyboard COMMENT "Compiling storyboard") endif() -- cgit v1.2.3