@@ -196,13 +196,25 @@ foreach(option_flag IN LISTS option_flags)
196196 convert_env_var_to_bool ("${option_flag} " )
197197endforeach ()
198198
199+ set (CMAKE_FIND_ROOT_PATH_BACKUP "${CMAKE_FIND_ROOT_PATH} " )
200+
201+ macro (clear_wasm_sysroot )
199202if (WASM_BUILD)
200203 # when using the nix/build-all.py build script we should not
201204 # look into the sysroot for most of the dependencies but rather
202205 # in the designated build/ folder created by the script.
203- set (CMAKE_FIND_ROOT_PATH_BACKUP "${CMAKE_FIND_ROOT_PATH} " )
204206 set (CMAKE_FIND_ROOT_PATH "" )
205207endif ()
208+ set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
209+ endmacro ()
210+
211+ macro (restore_wasm_sysroot )
212+ if (WASM_BUILD)
213+ # reset to use sysroot
214+ set (CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH_BACKUP} " )
215+ endif ()
216+ set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
217+ endmacro ()
206218
207219if (WITH_CGAL)
208220 add_definitions (-DIFOPSH_WITH_CGAL )
@@ -223,7 +235,9 @@ endif()
223235
224236if (GLTF_SUPPORT OR CITYJSON_SUPPORT)
225237 UNIFY_ENVVARS_AND_CACHE (JSON_INCLUDE_DIR )
238+ clear_wasm_sysroot ()
226239 find_path (json_header_path "nlohmann/json.hpp" HINTS ${JSON_INCLUDE_DIR} )
240+ restore_wasm_sysroot ()
227241 set (JSON_INCLUDE_DIR ${json_header_path} )
228242
229243 if (json_header_path)
@@ -330,13 +344,17 @@ if(USE_MMAP)
330344 add_definitions (-DUSE_MMAP )
331345endif ()
332346
347+ clear_wasm_sysroot ()
333348find_package (Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS} )
349+ restore_wasm_sysroot ()
334350message (STATUS "Boost include files found in ${Boost_INCLUDE_DIRS} " )
335351message (STATUS "Boost libraries found in ${Boost_LIBRARY_DIRS} " )
336352
337353if (NOT MINIMAL_BUILD)
338354 # libxml2 is required for IFCXML (optional) and SVGFILL (mandatory)
355+ clear_wasm_sysroot ()
339356 find_package (LibXml2 REQUIRED )
357+ restore_wasm_sysroot ()
340358endif ()
341359
342360if (IFCXML_SUPPORT)
@@ -352,13 +370,15 @@ if(BUILD_IFCGEOM)
352370 # Open CASCADE
353371 if (WITH_OPENCASCADE)
354372 if ("${OCC_INCLUDE_DIR} " STREQUAL "" )
373+ clear_wasm_sysroot ()
355374 find_path (OCC_INCLUDE_DIR Standard_Version.hxx
356375 PATHS
357376 /usr/include/occt
358377 /usr/include/oce
359378 /usr/include/opencascade
360379 REQUIRED
361380 )
381+ restore_wasm_sysroot ()
362382
363383 if (OCC_INCLUDE_DIR)
364384 message (STATUS "Found Open CASCADE include files in: ${OCC_INCLUDE_DIR} " )
@@ -418,7 +438,9 @@ if(BUILD_IFCGEOM)
418438 message (STATUS "Looking for Open CASCADE library files in: ${OCC_LIBRARY_DIR} " )
419439 endif ()
420440
441+ clear_wasm_sysroot ()
421442 find_library (libTKernel NAMES TKernel TKerneld PATHS ${OCC_LIBRARY_DIR} NO_DEFAULT_PATH )
443+ restore_wasm_sysroot ()
422444
423445 if (libTKernel)
424446 message (STATUS "Required Open Cascade Library files found" )
@@ -641,11 +663,6 @@ if(HDF5_SUPPORT)
641663 set (SWIG_DEFINES ${SWIG_DEFINES} -DWITH_HDF5)
642664endif (HDF5_SUPPORT )
643665
644- if (WASM_BUILD)
645- # reset to use sysroot
646- set (CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH_BACKUP} " )
647- endif ()
648-
649666if (ENABLE_BUILD_OPTIMIZATIONS)
650667 if (MSVC )
651668 # NOTE: RelWithDebInfo and Release use O2 (= /Ox /Gl /Gy/ = Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy) by default,
@@ -925,8 +942,10 @@ endif()
925942
926943if (BUILD_IFCGEOM)
927944 if (WITH_CGAL)
945+ clear_wasm_sysroot ()
928946 find_library (libGMP NAMES gmp mpir PATHS ${GMP_LIBRARY_DIR} NO_DEFAULT_PATH )
929947 find_library (libMPFR NAMES mpfr PATHS ${MPFR_LIBRARY_DIR} NO_DEFAULT_PATH )
948+ restore_wasm_sysroot ()
930949 if (NOT libGMP)
931950 message (FATAL_ERROR "Unable to find GMP library files, aborting" )
932951 endif ()
0 commit comments