Skip to content

Commit

Permalink
Fix OCCT and OpenCV patching during build (SoftFever#8465)
Browse files Browse the repository at this point in the history
* Fix OCCT and OpenCV patching during build

The inclusion of the `--directory` flag here isn't necessary because of
how `PATCH_COMMAND` applies patches. In fact this causes issues when
trying to build from an archive, `--directory` seems to imply `--index`
and thus this patch only succeeds if you're inside an initialized git
repo. If you simply use the archive without a git repo the build fails
at the patch step.

* Alter patch command based on git repo status

`git apply` has different behavior when inside a git repo vs not. If
we're in a git repo we need to fully quality the path for these patches,
otherwise we can omit the directory flag.

---------

Co-authored-by: Joe Palazzolo <[email protected]>
  • Loading branch information
jpalazz2 and Joe Palazzolo authored Feb 21, 2025
1 parent a49460d commit b82d13a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 14 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ if(NOT FREETYPE_FOUND)
set(FREETYPE_PKG "dep_FREETYPE")
endif()

execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --is-inside-work-tree
RESULT_VARIABLE REV_PARSE_RESULT
OUTPUT_VARIABLE REV_PARSE_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Will output "true" and have a 0 return code if within a git repo
if((REV_PARSE_RESULT EQUAL 0) AND (REV_PARSE_OUTPUT STREQUAL "true"))
set(IN_GIT_REPO TRUE)
# Find relative path from root to source used for adjusting patch command
file(RELATIVE_PATH BINARY_DIR_REL ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR})
endif ()

include(OCCT/OCCT.cmake)
include(OpenCV/OpenCV.cmake)

Expand Down
8 changes: 4 additions & 4 deletions deps/OCCT/OCCT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ else()
set(library_build_type "Static")
endif()


# get relative path of CMAKE_BINARY_DIR against root source directory
file(RELATIVE_PATH BINARY_DIR_REL ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR})
if (IN_GIT_REPO)
set(OCCT_DIRECTORY_FLAG --directory ${BINARY_DIR_REL}/dep_OCCT-prefix/src/dep_OCCT)
endif ()

orcaslicer_add_cmake_project(OCCT
URL https://github.com/Open-Cascade-SAS/OCCT/archive/refs/tags/V7_6_0.zip
URL_HASH SHA256=28334f0e98f1b1629799783e9b4d21e05349d89e695809d7e6dfa45ea43e1dbc
#PATCH_COMMAND ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/0001-OCCT-fix.patch
PATCH_COMMAND git apply --directory ${BINARY_DIR_REL}/dep_OCCT-prefix/src/dep_OCCT --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-OCCT-fix.patch
PATCH_COMMAND git apply ${OCCT_DIRECTORY_FLAG} --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-OCCT-fix.patch
#DEPENDS dep_Boost
DEPENDS ${FREETYPE_PKG}
CMAKE_ARGS
Expand Down
6 changes: 5 additions & 1 deletion deps/OpenCV/OpenCV.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ else ()
set(_use_IPP "-DWITH_IPP=OFF")
endif ()

if (IN_GIT_REPO)
set(OpenCV_DIRECTORY_FLAG --directory ${BINARY_DIR_REL}/dep_OpenCV-prefix/src/dep_OpenCV)
endif ()

orcaslicer_add_cmake_project(OpenCV
URL https://github.com/opencv/opencv/archive/refs/tags/4.6.0.tar.gz
URL_HASH SHA256=1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277
PATCH_COMMAND git apply --directory ${BINARY_DIR_REL}/dep_OpenCV-prefix/src/dep_OpenCV --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-vs2022.patch
PATCH_COMMAND git apply ${OpenCV_DIRECTORY_FLAG} --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-vs2022.patch
CMAKE_ARGS
-DBUILD_SHARED_LIBS=0
-DBUILD_PERE_TESTS=OFF
Expand Down

0 comments on commit b82d13a

Please sign in to comment.