Skip to content

Commit

Permalink
COMP: Bump Validated CMake policies version to 3.29.0
Browse files Browse the repository at this point in the history
Fix CLANG_FORMAT_EXECUTABLE location with find_program to address:

CMake Error at CMake/ITKClangFormatSetup.cmake:62 (message):
  Missing suitable clang-format executable, set CLANG_FORMAT_EXECUTABLE
  variable to version 8.0
Call Stack (most recent call first):
  CMakeLists.txt:586 (include)

Improve host system detection for the clang-format binary download.
  • Loading branch information
thewtex committed Apr 9, 2024
1 parent ee160a9 commit 6e88ab6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 9 additions & 12 deletions CMake/ITKClangFormatSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
option(ITK_USE_CLANG_FORMAT "Enable the use of clang-format enforce ITK coding style." ${BUILD_TESTING})
mark_as_advanced(ITK_USE_CLANG_FORMAT)

if(ITK_USE_CLANG_FORMAT AND NOT EXISTS "${CLANG_FORMAT_EXECUTABLE}")
find_program(CLANG_FORMAT_EXECUTABLE NAMES clang-format-8.0 clang-format8 clang-format)
mark_as_advanced(CLANG_FORMAT_EXECUTABLE)
if(ITK_USE_CLANG_FORMAT AND NOT CLANG_FORMAT_EXECUTABLE)
# Download pre-built binaries (about 2M) of clang-format extracted from
# https://releases.llvm.org/download.html and cached on data.kitware.com
#
Expand All @@ -31,14 +33,14 @@ if(ITK_USE_CLANG_FORMAT AND NOT EXISTS "${CLANG_FORMAT_EXECUTABLE}")
# Android - Android NDK (GCC, Clang)
# CrayLinuxEnvironment - Cray supercomputers (Cray compiler)
# MSYS - Windows (MSYS2 shell native GCC)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(CLANG_FORMAT_DOWNLOAD_URL "https://data.kitware.com/api/v1/file/5d274e88877dfcc902effc47/download")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(CLANG_FORMAT_DOWNLOAD_URL "https://data.kitware.com/api/v1/file/5d2b8775877dfcc902fd8236/download")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
elseif (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CLANG_FORMAT_DOWNLOAD_URL "https://data.kitware.com/api/v1/file/5d2b8c87877dfcc902fda594/download")
else()
message(FATAL_ERROR "UNKNOWN SYSTEM: Set CLANG_FORMAT_EXECUTABLE manually to the clang-format version 8.0 binary")
message(FATAL_ERROR "System binaries not available: set CLANG_FORMAT_EXECUTABLE to clang-format 8 or disable ITK_USE_CLANG_FORMAT.")
endif()
file(MAKE_DIRECTORY "${ITK_BINARY_DIR}/temp")
if(WIN32)
Expand All @@ -54,11 +56,6 @@ if(ITK_USE_CLANG_FORMAT AND NOT EXISTS "${CLANG_FORMAT_EXECUTABLE}")
set(CLANG_FORMAT_EXECUTABLE
"${ITK_BINARY_DIR}/${CLANG_FORMAT_EXECUTABLE_NAME}"
CACHE FILEPATH "The binary for clang-format" FORCE)
endif()
if(CLANG_FORMAT_EXECUTABLE)
mark_as_advanced(CLANG_FORMAT_EXECUTABLE)
endif()
if(ITK_USE_CLANG_FORMAT AND NOT EXISTS "${CLANG_FORMAT_EXECUTABLE}")
message(FATAL_ERROR "Missing suitable clang-format executable, set CLANG_FORMAT_EXECUTABLE variable to version 8.0")
unset(CLANG_FORMAT_EXECUTABLE)
elseif(ITK_USE_CLANG_FORMAT AND NOT CLANG_FORMAT_EXECUTABLE)
message(FATAL_ERROR "Missing suitable clang-format executable, set CLANG_FORMAT_EXECUTABLE to clang-format 8 or disable ITK_USE_CLANG_FORMAT.")
endif()
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
# continue to generate policy warnings "CMake Warning (dev)...Policy CMP0XXX is not set:"
#
set(ITK_OLDEST_VALIDATED_POLICIES_VERSION "3.16.3")
set(ITK_NEWEST_VALIDATED_POLICIES_VERSION "3.19.7")
set(ITK_NEWEST_VALIDATED_POLICIES_VERSION "3.29.0")
cmake_minimum_required(VERSION ${ITK_OLDEST_VALIDATED_POLICIES_VERSION}...${ITK_NEWEST_VALIDATED_POLICIES_VERSION}
FATAL_ERROR)

#
# Now enumerate specific policies newer than ITK_NEWEST_VALIDATED_POLICIES_VERSION
# that may need to be individually set to NEW/OLD
#
foreach(pnew "CMP0120" "CMP0135")
foreach(pnew )
if(POLICY ${pnew})
cmake_policy(SET ${pnew} NEW)
endif()
Expand Down

0 comments on commit 6e88ab6

Please sign in to comment.