From 83c9769237ab184372be0d786b6007ec7e5ec63e Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Mon, 29 Jan 2024 15:10:15 -0800 Subject: [PATCH] CMake code review (#140) --- CMakeLists.txt | 59 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c629bb..b46bea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,14 @@ elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$") set(DIRECTX_ARCH arm) elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$") set(DIRECTX_ARCH arm64) +elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Ww][Ii][Nn]32$") + set(DIRECTX_ARCH x86) +elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Xx]64$") + set(DIRECTX_ARCH x64) +elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]$") + set(DIRECTX_ARCH arm) +elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64$") + set(DIRECTX_ARCH arm64) endif() if(WINDOWS_STORE OR (DEFINED XBOX_CONSOLE_TARGET)) @@ -290,14 +298,12 @@ if(BUILD_TOOLS AND WIN32) Microsoft::DirectXTex Microsoft::DirectXMesh::Utilities) source_group(uvatlastool REGULAR_EXPRESSION UVAtlasTool/*.*) +endif() - if(UVATLAS_USE_OPENMP) - target_link_libraries(uvatlastool PRIVATE OpenMP::OpenMP_CXX) - endif() - - if(directxmath_FOUND) - target_link_libraries(uvatlastool PRIVATE Microsoft::DirectXMath) - endif() +if(directxmath_FOUND) + foreach(t IN LISTS TOOL_EXES) + target_link_libraries(${t} PRIVATE Microsoft::DirectXMath) + endforeach() endif() if(MSVC) @@ -306,7 +312,7 @@ if(MSVC) target_link_options(${t} PRIVATE /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO) endforeach() - if((CMAKE_SIZEOF_VOID_P EQUAL 4) AND (NOT ${DIRECTX_ARCH} MATCHES "^arm")) + if((CMAKE_SIZEOF_VOID_P EQUAL 4) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm"))) foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) target_link_options(${t} PRIVATE /SAFESEH) endforeach() @@ -316,7 +322,7 @@ if(MSVC) AND (MSVC_VERSION GREATER_EQUAL 1913) AND (NOT WINDOWS_STORE) AND (NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))) - message(STATUS "Building Spectre-mitigated libraries.") + message(STATUS "Building Spectre-mitigated libraries") foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) target_compile_options(${t} PRIVATE "/Qspectre") endforeach() @@ -378,7 +384,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") endforeach() elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) - target_compile_options(${t} PRIVATE "-Wno-ignored-attributes") + target_compile_options(${t} PRIVATE "-Wno-ignored-attributes" "-Walloc-size-larger-than=4GB") endforeach() elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) @@ -416,19 +422,25 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") endforeach() endif() - if(UVATLAS_USE_OPENMP) + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.35) + foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) + target_compile_options(${t} PRIVATE /Zc:checkGwOdr) + endforeach() + + if(NOT (DEFINED XBOX_CONSOLE_TARGET)) + foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) + target_compile_options(${t} PRIVATE $<$:/Zc:templateScope>) + endforeach() + endif() + endif() + + if(OpenMP_CXX_FOUND) # OpenMP in MSVC is not compatible with /permissive- unless you disable two-phase lookup foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) target_compile_options(${t} PRIVATE /Zc:twoPhase-) endforeach() endif() - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.35) - foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) - target_compile_options(${t} PRIVATE /Zc:checkGwOdr $<$:/Zc:templateScope>) - endforeach() - endif() - set(WarningsEXE "/wd4365" "/wd4514" "/wd4625" "/wd4626" "/wd4627" "/wd4668" "/wd4710" "/wd4711" "/wd4751" "/wd4820" "/wd5026" "/wd5027" "/wd5039" "/wd5045" "/wd4061" "/wd4062" "/wd5219") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.34) list(APPEND WarningsEXE "/wd5262" "/wd5264") @@ -464,16 +476,17 @@ if(BUILD_TOOLS AND WIN32) set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT uvatlastool) endif() -if(BUILD_TOOLS AND WIN32 AND (NOT VCPKG_TOOLCHAIN)) +if(BUILD_TOOLS AND (NOT VCPKG_TOOLCHAIN)) foreach(t IN LISTS TOOL_EXES) install(TARGETS ${t} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endforeach() endif() #--- Test suite -include(CTest) -if(BUILD_TESTING AND WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOLE_TARGET)) - AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/CMakeLists.txt")) - enable_testing() - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests) +if(WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOLE_TARGET))) + include(CTest) + if(BUILD_TESTING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/CMakeLists.txt")) + enable_testing() + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests) + endif() endif()