@@ -416,6 +416,30 @@ set(COMMONLIST ${COMMONLIST} ${TINYFORMATLIST})
416416# Libraries
417417################################################################################
418418
419+ # Find libraries when cross-compiling for a different architecture on Linux systems.
420+ # We purposedly do not use the `LINUX` variable for two reasons:
421+ # - We're not testing for the target but for the system running the compiler,
422+ # - It should exclude Android.
423+ # Conveniently it also finds the MinGW root path when cross-compiling for Windows on Linux.
424+ if (CMAKE_SYSTEM_NAME MATCHES "Linux" )
425+ # This code setting MACHINE_TRIPLE may be moved to DaemonCompiler.
426+ execute_process (COMMAND "${CMAKE_CXX_COMPILER} " -dumpmachine
427+ OUTPUT_VARIABLE MACHINE_TRIPLE
428+ OUTPUT_STRIP_TRAILING_WHITESPACE
429+ )
430+
431+ # If the target architecture has a cross-compiler subfolder, use it.
432+ if (MACHINE_TRIPLE)
433+ set (MACHINE_ROOT_PATH "/usr/${MACHINE_TRIPLE} " )
434+
435+ if (NOT IS_DIRECTORY "${MACHINE_ROOT_PATH} " )
436+ unset (MACHINE_ROOT_PATH)
437+ endif ()
438+ endif ()
439+ endif ()
440+
441+ list (APPEND CMAKE_FIND_ROOT_PATH ${MACHINE_ROOT_PATH} )
442+
419443# Import external dependencies
420444if (DEPS_DIR)
421445 # Warn on old version of deps
@@ -484,6 +508,7 @@ if (DEPS_DIR)
484508 set (CMAKE_INCLUDE_PATH ${DEPS_DIR} ${DEPS_DIR} /include ${CMAKE_INCLUDE_PATH} )
485509 set (CMAKE_FRAMEWORK_PATH ${DEPS_DIR} ${CMAKE_FRAMEWORK_PATH} )
486510 set (CMAKE_PREFIX_PATH ${DEPS_DIR} ${CMAKE_PREFIX_PATH} )
511+
487512 if (DAEMON_PARENT_SCOPE_DIR)
488513 # Also set parent scope so the top level CMakeLists can find precompiled deps
489514 set (CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH} PARENT_SCOPE)
0 commit comments