Skip to content

Commit

Permalink
Merge pull request #110 from Florent2305/PatchITK4NewGcc
Browse files Browse the repository at this point in the history
Fix COMP: ITK build error with GCC 13
  • Loading branch information
ecaruyer authored Apr 18, 2024
2 parents 7923db4 + 4859138 commit de6136d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include(CheckEnvironment)

include(ExternalProject)
include(ConfigureExternalProjectVariables)
include(EP_GeneratePatchCommand)

#Variables for dependencies and update custom, updated in external projects
set(Anima_DEPS "")
Expand Down
2 changes: 2 additions & 0 deletions superbuild/ConfigureExternalProjectVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ set(common_cache_args
${MACOSX_RPATH_OPTION}
)

set(EP_PATH_SOURCE ${PROJECT_SOURCE_DIR}/External-Projects)

if (CMAKE_EXTRA_GENERATOR)
set(cmake_gen "${CMAKE_EXTRA_GENERATOR} -G ${CMAKE_GENERATOR}")
else()
Expand Down
14 changes: 14 additions & 0 deletions superbuild/EP_GeneratePatchCommand.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## #############################################################################
## Generate patch command for an external project. To use with ExternalProject_Add
## #############################################################################
function(ep_GeneratePatchCommand ep OutVar patch)
set(PATCH_COMMAND ${CMAKE_COMMAND}
-Dep:STRING=${ep}
-DANIMA_SOURCE_DIR:STRING=${CMAKE_SOURCE_DIR}
-DEP_PATH_SOURCE:STRING=${EP_PATH_SOURCE}
-Dpatch:STRING=${patch}
-P
${CMAKE_SOURCE_DIR}/superbuild/EP_PatcherScript.cmake)

set(${OutVar} ${PATCH_COMMAND} PARENT_SCOPE)
endfunction()
66 changes: 66 additions & 0 deletions superbuild/EP_PatcherScript.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## #############################################################################
## Check if a patch should be applied and apply it if needed
## #############################################################################
macro(directory_count_elements ep_path elements_count_res)
file(GLOB RESULT ${ep_path}/*)
list(LENGTH RESULT ${elements_count_res})
endmacro()

function(ep_GenerateValidPatcherScript ep OutVar patch)
find_program(GIT_BIN NAMES git)

set(PATCHES_TO_APPLY_CUR ${ANIMA_SOURCE_DIR}/superbuild/patches/${patch})
directory_count_elements(${EP_PATH_SOURCE}/${ep} count)

if(NOT ${count} EQUAL 0) #Check if external_project is already cloned
execute_process(COMMAND ${GIT_BIN} apply --reverse --ignore-whitespace --check ${ANIMA_SOURCE_DIR}/superbuild/patches/${patch}
WORKING_DIRECTORY ${EP_PATH_SOURCE}/${ep}
RESULT_VARIABLE PATCH_ALREADY_APPLIED
OUTPUT_QUIET
ERROR_QUIET)

if (PATCH_ALREADY_APPLIED EQUAL 0) #As all OS system commands: 0 is Ok, not 0 is bad.
# The patch is already applied
message("The patch ${patch} for the external project ${ep} is already applied")
set (PATCHES_TO_APPLY_CUR "") #Then erase PATCHES_TO_APPLY_CUR
else()
execute_process(COMMAND ${GIT_BIN} apply --ignore-whitespace --check ${ANIMA_SOURCE_DIR}/superbuild/patches/${patch}
WORKING_DIRECTORY ${EP_PATH_SOURCE}/${ep}
RESULT_VARIABLE PATCH_APPLICABLE)
#OUTPUT_QUIET
#ERROR_QUIET)
if(PATCH_APPLICABLE EQUAL 0) #As all OS system commands: 0 is Ok, not 0 is bad.
#Do nothing, the value is already set
message("The patch ${patch} will be applied on pre-existing ${EP_PATH_SOURCE}/${ep}")
else()
message("*****************************************************************************************************\n")
message("***** The patch ${patch} for the external project ${ep} is NOT APPLICABLE")
message("***** EP PATH = ${EP_PATH_SOURCE}/${ep}")
message("***** PATCH file = ${ANIMA_SOURCE_DIR}/superbuild/patches/${patch}")
message("*****************************************************************************************************\n")
message(FATAL_ERROR "")

endif()
endif()
else()
message("The patch ${patch} will be applied after ${ep} cloning into ${EP_PATH_SOURCE}/${ep}")
endif()
set(PATCHES_TO_APPLY ${PATCHES_TO_APPLY} ${PATCHES_TO_APPLY_CUR})


set(PATCH_COMMAND "")
if (NOT "${PATCHES_TO_APPLY}" STREQUAL "")
set(PATCH_COMMAND ${GIT_BIN} apply --ignore-whitespace ${PATCHES_TO_APPLY})
endif()

set(${OutVar} ${PATCH_COMMAND} PARENT_SCOPE)
endfunction()


ep_GenerateValidPatcherScript(${ep} patchCommand ${patch})

if(patchCommand)
execute_process(COMMAND ${patchCommand} WORKING_DIRECTORY ${EP_PATH_SOURCE}/${ep})
else()
message(DEBUG "No patch treatment for ${ep}")
endif()
11 changes: 11 additions & 0 deletions superbuild/ITK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ if (NOT DEFINED ${proj}_SRC_DIR)
set(location GIT_REPOSITORY ${GITHUB_PREFIX}InsightSoftwareConsortium/ITK.git GIT_TAG ${tag})
endif()

## #############################################################################
## Check if patch has to be applied
## #############################################################################

ep_GeneratePatchCommand(ITK ITK_PATCH_COMMAND ITK.patch)

## #############################################################################
## Add external-project
## #############################################################################

ExternalProject_Add(${proj}
${location}
DEPENDS ${VTK_PROJ_DEP}
Expand All @@ -40,6 +50,7 @@ ExternalProject_Add(${proj}
CMAKE_GENERATOR ${cmake_gen}
CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
CMAKE_ARGS ${cmake_args}
PATCH_COMMAND ${ITK_PATCH_COMMAND}
BUILD_ALWAYS 1
BINARY_DIR ${CMAKE_BINARY_DIR}/${proj}
INSTALL_COMMAND ""
Expand Down
12 changes: 12 additions & 0 deletions superbuild/patches/ITK.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unchanged:
--- a/Modules/Filtering/MathematicalMorphology/include/itkMathematicalMorphologyEnums.h
+++ b/Modules/Filtering/MathematicalMorphology/include/itkMathematicalMorphologyEnums.h
@@ -19,6 +19,7 @@
#define itkMathematicalMorphologyEnums_h

#include <iostream>
+#include <cstdint>
#include "ITKMathematicalMorphologyExport.h"



0 comments on commit de6136d

Please sign in to comment.