Skip to content

cmake: populate CMAKE_FIND_ROOT_PATH when cross-compiling for a different architecture on Linux #1660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,30 @@ set(COMMONLIST ${COMMONLIST} ${TINYFORMATLIST})
# Libraries
################################################################################

# Find libraries when cross-compiling for a different architecture on Linux systems.
# We purposedly do not use the `LINUX` variable for two reasons:
# - We're not testing for the target but for the system running the compiler,
# - It should exclude Android.
# Conveniently it also finds the MinGW root path when cross-compiling for Windows on Linux.
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
# This code setting MACHINE_TRIPLE may be moved to DaemonCompiler.
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -dumpmachine
OUTPUT_VARIABLE MACHINE_TRIPLE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# If the target architecture has a cross-compiler subfolder, use it.
if (MACHINE_TRIPLE)
set(MACHINE_ROOT_PATH "/usr/${MACHINE_TRIPLE}")

if (NOT IS_DIRECTORY "${MACHINE_ROOT_PATH}")
unset(MACHINE_ROOT_PATH)
endif()
endif()
endif()

list(APPEND CMAKE_FIND_ROOT_PATH ${MACHINE_ROOT_PATH})

# Import external dependencies
if (DEPS_DIR)
# Warn on old version of deps
Expand Down Expand Up @@ -484,6 +508,7 @@ if (DEPS_DIR)
set(CMAKE_INCLUDE_PATH ${DEPS_DIR} ${DEPS_DIR}/include ${CMAKE_INCLUDE_PATH})
set(CMAKE_FRAMEWORK_PATH ${DEPS_DIR} ${CMAKE_FRAMEWORK_PATH})
set(CMAKE_PREFIX_PATH ${DEPS_DIR} ${CMAKE_PREFIX_PATH})

if (DAEMON_PARENT_SCOPE_DIR)
# Also set parent scope so the top level CMakeLists can find precompiled deps
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH} PARENT_SCOPE)
Expand Down