Skip to content

Commit e5ca00f

Browse files
committed
cmake: populate CMAKE_FIND_ROOT_PATH when cross-compiling for a different architecture on Linux
1 parent 0fa128f commit e5ca00f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,33 @@ if (DEPS_DIR)
479479
endif()
480480
endif()
481481

482+
# Find libraries when cross-compiling on Linux systems.
483+
# We purposedly do not use the `LINUX` variable for two reasons:
484+
# - We're not testing for the target but for the system running the compiler,
485+
# - It should exclude Android.
486+
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
487+
# This code setting MACHINE_TRIPLE may be moved to DaemonCompiler.
488+
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -dumpmachine
489+
OUTPUT_VARIABLE MACHINE_TRIPLE
490+
OUTPUT_STRIP_TRAILING_WHITESPACE
491+
)
492+
493+
# If the target architecture has a cross-compiler subfolder, use it.
494+
if (MACHINE_TRIPLE)
495+
set(MACHINE_ROOT_PATH "/usr/${MACHINE_TRIPLE}")
496+
497+
if (NOT IS_DIRECTORY "${MACHINE_ROOT_PATH}")
498+
unset(MACHINE_ROOT_PATH)
499+
endif()
500+
endif()
501+
endif()
502+
482503
# Add to paths
483-
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH})
504+
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH} ${MACHINE_ROOT_PATH})
484505
set(CMAKE_INCLUDE_PATH ${DEPS_DIR} ${DEPS_DIR}/include ${CMAKE_INCLUDE_PATH})
485506
set(CMAKE_FRAMEWORK_PATH ${DEPS_DIR} ${CMAKE_FRAMEWORK_PATH})
486507
set(CMAKE_PREFIX_PATH ${DEPS_DIR} ${CMAKE_PREFIX_PATH})
508+
487509
if (DAEMON_PARENT_SCOPE_DIR)
488510
# Also set parent scope so the top level CMakeLists can find precompiled deps
489511
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH} PARENT_SCOPE)

0 commit comments

Comments
 (0)