From 42f17c2098a47e0bfa763341f033de2f896e43dd Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 5 May 2026 23:16:13 -0700 Subject: [PATCH 1/3] Minor CMake code review --- CMakeLists.txt | 9 ++++++--- SHMath/CMakeLists.txt | 15 ++++++++++----- build/JoinPaths.cmake | 23 ----------------------- 3 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 build/JoinPaths.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 42a32e27..a728b6de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,10 @@ cmake_minimum_required (VERSION 3.21) +if(POLICY CMP0162) + cmake_policy(SET CMP0162 NEW) +endif() + set(DIRECTXMATH_VERSION 3.20) if(WINDOWS_STORE OR (DEFINED XBOX_CONSOLE_TARGET)) @@ -77,10 +81,9 @@ install(FILES DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME}) # Create pkg-config file -include(build/JoinPaths.cmake) # from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files -join_paths(DIRECTXMATH_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") -join_paths(DIRECTXMATH_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") +cmake_path(APPEND DIRECTXMATH_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") +cmake_path(APPEND DIRECTXMATH_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/build/DirectXMath.pc.in" diff --git a/SHMath/CMakeLists.txt b/SHMath/CMakeLists.txt index 6c9e352f..a0c80e77 100644 --- a/SHMath/CMakeLists.txt +++ b/SHMath/CMakeLists.txt @@ -75,7 +75,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ $) -target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11) +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11) target_link_libraries(${PROJECT_NAME} PRIVATE DirectXMath) @@ -102,8 +102,7 @@ cmake_path(GET CMAKE_CURRENT_LIST_DIR PARENT_PATH DIRECTXMATH_PATH) write_basic_package_version_file( ${PACKAGE_NAME}-config-version.cmake VERSION ${SHMATH_VERSION} - COMPATIBILITY AnyNewerVersion - ARCH_INDEPENDENT) + COMPATIBILITY AnyNewerVersion) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets @@ -213,12 +212,18 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") endif() endif() -if(NOT WIN32) +if((NOT WIN32) AND (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/sal/sal.h")) file(DOWNLOAD https://raw.githubusercontent.com/dotnet/runtime/v9.0.2/src/coreclr/pal/inc/rt/sal.h "${CMAKE_CURRENT_BINARY_DIR}/sal/sal.h" EXPECTED_HASH SHA512=8085f67bfa4ce01ae89461cadf72454a9552fde3f08b2dcc3de36b9830e29ce7a6192800f8a5cb2a66af9637be0017e85719826a4cfdade508ae97f319e0ee8e + STATUS DOWNLOAD_STATUS ) + list(GET DOWNLOAD_STATUS 0 STATUS_CODE) + list(GET DOWNLOAD_STATUS 1 DOWNLOAD_ERROR) + if(NOT (STATUS_CODE EQUAL 0)) + message(FATAL_ERROR "Failed to download sal.h: ${DOWNLOAD_ERROR}") + endif() - target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/sal") + target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/sal") endif() diff --git a/build/JoinPaths.cmake b/build/JoinPaths.cmake deleted file mode 100644 index c68d91b8..00000000 --- a/build/JoinPaths.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# This module provides function for joining paths -# known from most languages -# -# SPDX-License-Identifier: (MIT OR CC0-1.0) -# Copyright 2020 Jan Tojnar -# https://github.com/jtojnar/cmake-snips -# -# Modelled after Python’s os.path.join -# https://docs.python.org/3.7/library/os.path.html#os.path.join -# Windows not supported -function(join_paths joined_path first_path_segment) - set(temp_path "${first_path_segment}") - foreach(current_segment IN LISTS ARGN) - if(NOT ("${current_segment}" STREQUAL "")) - if(IS_ABSOLUTE "${current_segment}") - set(temp_path "${current_segment}") - else() - set(temp_path "${temp_path}/${current_segment}") - endif() - endif() - endforeach() - set(${joined_path} "${temp_path}" PARENT_SCOPE) -endfunction() From c6bbd581d97da9880f9dd6cc6d7c82576e7e1135 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 5 May 2026 23:19:36 -0700 Subject: [PATCH 2/3] Minor update for change in CMake 4.1 --- SHMath/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHMath/CMakeLists.txt b/SHMath/CMakeLists.txt index a0c80e77..731f554b 100644 --- a/SHMath/CMakeLists.txt +++ b/SHMath/CMakeLists.txt @@ -164,7 +164,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel") target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus /Zc:inline /fp:fast /Qdiag-disable:161) elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${PROJECT_NAME} PRIVATE - /sdl /Zc:inline /fp:fast + /sdl /Zc:forScope /Zc:inline /Zc:wchar_t /fp:fast /wd4061 /wd4365 /wd4514 /wd4571 /wd4668 /wd4710 /wd4820 /wd5039 /wd5045) if(CMAKE_INTERPROCEDURAL_OPTIMIZATION) From d1cd29bddf8dbdc47cfddd5d7e34f12510747517 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 5 May 2026 23:22:16 -0700 Subject: [PATCH 3/3] Fix build break --- SHMath/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHMath/CMakeLists.txt b/SHMath/CMakeLists.txt index 731f554b..fbad6e57 100644 --- a/SHMath/CMakeLists.txt +++ b/SHMath/CMakeLists.txt @@ -225,5 +225,5 @@ if((NOT WIN32) AND (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/sal/sal.h")) message(FATAL_ERROR "Failed to download sal.h: ${DOWNLOAD_ERROR}") endif() - target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/sal") + target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/sal") endif()