Skip to content

Instantly share code, notes, and snippets.

@ngoduykhanh
Created February 16, 2017 08:04
Show Gist options
  • Save ngoduykhanh/9037a72bc510a0c063fb8a2f5e90f2a1 to your computer and use it in GitHub Desktop.
Save ngoduykhanh/9037a72bc510a0c063fb8a2f5e90f2a1 to your computer and use it in GitHub Desktop.
sysroot in cmakelist
# Check for sysroot override via TARGET_SYSROOT environment variable.
if (DEFINED ENV{TARGET_SYSROOT})
set(TARGET_SYSROOT "$ENV{TARGET_SYSROOT}")
message("Target sysroot overridden by TARGET_SYSROOT environment variable")
else()
# Ask the compiler for its sysroot.
if(NOT USE_CLANG EQUAL 1)
execute_process(
COMMAND ${TARGET_CC} --print-sysroot
OUTPUT_VARIABLE TARGET_SYSROOT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
message("Target sysroot: ${TARGET_SYSROOT}")
SET(CMAKE_REQUIRED_FLAGS "--sysroot=${TARGET_SYSROOT}")
add_definitions(--sysroot=${TARGET_SYSROOT})
SET(CMAKE_EXE_LINKER_FLAGS "--sysroot=${TARGET_SYSROOT}" CACHE STRING "" FORCE)
SET(CMAKE_SHARED_LINKER_FLAGS "--sysroot=${TARGET_SYSROOT}" CACHE STRING "" FORCE)
SET(CMAKE_MODULE_LINKER_FLAGS "--sysroot=${TARGET_SYSROOT}" CACHE STRING "" FORCE)
set(CMAKE_FIND_ROOT_PATH "${TARGET_SYSROOT}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment