Changes to CMake toolchain files
We still haven't successfully xcompiled, but we're working toward it.
This commit is contained in:
@@ -31,7 +31,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
# Search for libraries and headers in the target directories
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
# Set pkg-config to use the cross-compiled libraries
|
||||
set(ENV{PKG_CONFIG_PATH} "/usr/aarch64-linux-gnu/lib/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig")
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# ----------------------------------------------------------------------------------
|
||||
# MANDATORY USER VARIABLE
|
||||
# ----------------------------------------------------------------------------------
|
||||
# IMPORTANT: This variable MUST be set when running CMake to specify where the
|
||||
# laptop's sysroot (the root directory of the mounted laptop filesystem) is located.
|
||||
#
|
||||
# Usage example: cmake -DCMAKE_TOOLCHAIN_FILE=laptop_x86_sysroot.cmake
|
||||
# -DTARGET_SYSROOT=/mnt/laptop_sysroot/ <path_to_source>
|
||||
#
|
||||
# If the variable is not defined, we fall back to a common system root path for safety.
|
||||
if(NOT DEFINED TARGET_SYSROOT)
|
||||
set(TARGET_SYSROOT "/usr/lib/x86_64-linux-gnu")
|
||||
message(STATUS "TARGET_SYSROOT not explicitly defined. Defaulting to ${TARGET_SYSROOT}")
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# SYSROOT and COMPILER CONFIGURATION
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
# 1. Architecture and Platform Identification
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
set(TARGET_TRIPLE x86_64-linux-gnu) # Standard Debian/Ubuntu triple
|
||||
|
||||
# 2. Set the CMAKE_SYSROOT using the user-defined variable
|
||||
set(CMAKE_SYSROOT ${TARGET_SYSROOT})
|
||||
message(STATUS "Using CMAKE_SYSROOT: ${CMAKE_SYSROOT}")
|
||||
|
||||
# 3. Specify the Cross Compilers
|
||||
# These binaries must be installed on your RPi:
|
||||
# sudo apt install g++-x86-64-linux-gnu gcc-x86-64-linux-gnu
|
||||
set(CMAKE_C_COMPILER ${TARGET_TRIPLE}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TARGET_TRIPLE}-g++)
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# PKG-CONFIG CONFIGURATION (CRUCIAL FOR CROSS-COMPILING)
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
# 1. Define the search path for .pc files, relative to the sysroot.
|
||||
# This ensures we look in the target's standard pkgconfig locations.
|
||||
set(PKG_CONFIG_SEARCH_PATHS
|
||||
"${CMAKE_SYSROOT}/usr/lib/${TARGET_TRIPLE}/pkgconfig" # Primary location on Debian/Ubuntu
|
||||
"${CMAKE_SYSROOT}/usr/share/pkgconfig" # Secondary shared location
|
||||
"${CMAKE_SYSROOT}/usr/lib/pkgconfig" # Another common location
|
||||
)
|
||||
|
||||
# Join the paths using the system's path separator (colon on Linux)
|
||||
string(REPLACE ";" ":" PKG_CONFIG_LIBDIR_STRING "${PKG_CONFIG_SEARCH_PATHS}")
|
||||
|
||||
# Set the environment variable PKG_CONFIG_LIBDIR
|
||||
# This tells pkg-config exactly where to find the x86_64 .pc files.
|
||||
# 2. Set the sysroot directory for pkg-config
|
||||
# This tells pkg-config to prepend CMAKE_SYSROOT to any paths it finds in the .pc files.
|
||||
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
|
||||
set(ENV{PKG_CONFIG_LIBDIR} ${PKG_CONFIG_LIBDIR_STRING})
|
||||
set(ENV{PKG_CONFIG_PATH} "")
|
||||
|
||||
message(STATUS "PKG_CONFIG_SYSROOT_DIR set to: ${CMAKE_SYSROOT}")
|
||||
message(STATUS "PKG_CONFIG_LIBDIR set to: ${PKG_CONFIG_LIBDIR_STRING}")
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# CMAkE FIND BEHAVIOR
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
# The CMAKE_FIND_ROOT_PATH tells CMake where to look for programs, libraries, etc.
|
||||
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
|
||||
|
||||
# Restrict search to the sysroot, not in the RPi's native locations,
|
||||
# but allow programs (like pkg-config itself) to be found on the RPi.
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
Reference in New Issue
Block a user