cmake: CMake cleanup
authorJuan Ramos <juan@lunarg.com>
Thu, 10 Nov 2022 23:46:39 +0000 (16:46 -0700)
committerJuan Ramos <114601453+juan-lunarg@users.noreply.github.com>
Fri, 11 Nov 2022 00:16:53 +0000 (17:16 -0700)
- Use idiom for CMAKE_MODULE_PATH
- find_package(PkgConfig) instead of include(FindPkgConfig)
- Remove CMake 2.X code workaround
- Use CMAKE_CURRENT_BINARY_DIR instead of CMAKE_BINARY_DIR
- CMakeParseArguments is now part of the language

BUILD.md
CMakeLists.txt
loader/CMakeLists.txt
tests/framework/CMakeLists.txt

index 8c69cf6791c2800f5c7a29536a8869e1114462b8..9b5a8f64054a14c5077fa302c564ceefb16ed1d5 100644 (file)
--- a/BUILD.md
+++ b/BUILD.md
@@ -390,8 +390,8 @@ the primary build artifacts to a specific location using a "bin, include, lib"
 style directory structure. This may be useful for collecting the artifacts and
 providing them to another project that is dependent on them.
 
-The default location is `$CMAKE_BINARY_DIR\install`, but can be changed with
-the `CMAKE_INSTALL_PREFIX` variable when first generating the project build
+The default location is `$CMAKE_CURRENT_BINARY_DIR\install`, but can be changed
+with the `CMAKE_INSTALL_PREFIX` variable when first generating the project build
 files with CMake.
 
 You can build the install target from the command line with:
index cef78f06c263cc9feaeaa7144d1925113b6110bd..e71de78f35e1c2d26e35a0b39aa93c97e24652a3 100644 (file)
@@ -14,8 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # ~~~
-
 cmake_minimum_required(VERSION 3.10.2)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 
 # If we are building in Visual Studio 2015 and with a CMake version 3.19 or greater, we need to set this variable
 # so that CMake will choose a Windows SDK version higher than 10.0.14393.0, as dxgi1_6.h is only found in Windows SDK
@@ -49,7 +49,7 @@ if (UPDATE_DEPS)
     endif()
 
     message("********************************************************************************")
-    message("* NOTE: Adding target vl_update_deps to run as needed for updating            *")
+    message("* NOTE: Adding target vl_update_deps to run as needed for updating             *")
     message("*       dependencies.                                                          *")
     message("********************************************************************************")
 
@@ -83,7 +83,6 @@ if (VULKAN_HEADERS_INSTALL_DIR)
     list(APPEND CMAKE_PREFIX_PATH ${VULKAN_HEADERS_INSTALL_DIR})
 endif()
 
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 find_package(PythonInterp 3 QUIET)
 
 set(THREADS_PREFER_PTHREAD_FLAG ON)
@@ -115,12 +114,7 @@ find_package(VulkanHeaders REQUIRED CONFIG QUIET)
 include(GNUInstallDirs)
 
 if(UNIX AND NOT APPLE) # i.e.: Linux
-    include(FindPkgConfig)
-endif()
-
-if(APPLE)
-    # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined. This avoids the CMP0042 policy message.
-    set(CMAKE_MACOSX_RPATH 1)
+    find_package(PkgConfig)
 endif()
 
 set(GIT_BRANCH_NAME "--unknown--")
@@ -147,7 +141,7 @@ endif()
 
 if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
     # Windows: if install locations not set by user, set install prefix to "<build_dir>\install".
-    set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
+    set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
 endif()
 
 # Enable IDE GUI folders.  "Helper targets" that don't have interesting source code should set their FOLDER property to this
@@ -464,7 +458,7 @@ if(BUILD_TESTS)
     endif()
 
     if (BUILD_TESTS)
-        add_subdirectory(tests ${CMAKE_BINARY_DIR}/tests)
+        add_subdirectory(tests)
     endif()
 
 endif()
index 17c0d638698fac2082fead5c03a1ecd652e3e0d4..2eb704fdeec49100588c52c1a23d624f42ab2fe0 100644 (file)
@@ -381,7 +381,7 @@ if (TARGET asm_offset)
 endif()
 
 # Generate pkg-config file.
-include(FindPkgConfig QUIET)
+find_package(PkgConfig QUIET)
 if(PKG_CONFIG_FOUND)
     set(VK_API_VERSION "${LOADER_GENERATED_HEADER_VERSION}")
     set(PRIVATE_LIBS "")
index b3d46f5bc34cb348b1b43de250c829752eaa7cfd..c04ebae89b9ff11a86387afa5baa24b98bf93d76 100644 (file)
@@ -51,7 +51,6 @@ if (MSVC)
     target_compile_options(testing_framework_util PUBLIC /wd4458)
 endif()
 
-include(CMakeParseArguments)
 function(AddSharedLibrary LIBRARY_NAME)
     set(singleValueArgs DEF_FILE)
     set(multiValueArgs SOURCES DEFINITIONS)
@@ -96,7 +95,7 @@ add_dependencies (testing_framework_util generate_framework_config)
 add_library(testing_dependencies STATIC test_environment.cpp test_environment.h)
 target_link_libraries(testing_dependencies
     PUBLIC gtest Vulkan::Headers testing_framework_util shim-library)
-target_include_directories(testing_dependencies PUBLIC ${CMAKE_BINARY_DIR}/tests/framework)
+target_include_directories(testing_dependencies PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
 target_compile_definitions(testing_dependencies PUBLIC "GTEST_LINKED_AS_SHARED_LIBRARY=1")
 set_target_properties(testing_dependencies ${LOADER_STANDARD_CXX_PROPERTIES})
 if (APPLE AND BUILD_STATIC_LOADER)