Skip to content

fix how --sysroot is taken into account in CMakeMake easyblock #2247

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

Closed
Closed
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
37 changes: 35 additions & 2 deletions easybuild/easyblocks/generic/cmakemake.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.build_log import print_warning
from easybuild.tools.config import build_option
from easybuild.tools.filetools import change_dir, mkdir, which, remove_dir
from easybuild.tools.filetools import change_dir, mkdir, remove_dir, which, write_file
from easybuild.tools.environment import setvar
from easybuild.tools.modules import get_software_root
from easybuild.tools.run import run_cmd
Expand Down Expand Up @@ -171,7 +171,40 @@ def configure_step(self, srcdir=None, builddir=None):
# that CMake picks up compiler from sysroot rather than toolchain compiler...
sysroot = build_option('sysroot')
if sysroot:
options.append('-DCMAKE_SYSROOT=%s' % sysroot)

# only use toolchain file if -DCMAKE_TOOLCHAIN_FILE is not set yet in configopts
if '-DCMAKE_TOOLCHAIN_FILE=' not in self.cfg['configopts']:

# create toolchain file, and tell CMake to use it via CMAKE_TOOLCHAIN_FILE;
# see https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html
# and https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-linux
cmake_toolchain_file = os.path.join(self.builddir, 'toolchain.cmake')

cmake_toolchain_lines = [
# path that CMake should pass to compiler via --sysroot,
# see https://cmake.org/cmake/help/latest/variable/CMAKE_SYSROOT.html
"set(CMAKE_SYSROOT %s)" % sysroot,
# root path that CMake should search, used for find_library & co;
# see https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_ROOT_PATH.html
"set(CMAKE_FIND_ROOT_PATH %s)" % sysroot,
]

# instruct CMake to only use paths listed in CMAKE_FIND_ROOT_PATH;
# when --sysroot is specifed in EasyBuild, nothing from the host sysroot (/) should be used;
# see https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_ROOT_PATH_MODE_LIBRARY.html
root_path_modes = ['INCLUDE', 'LIBRARY', 'PACKAGE', 'PROGRAM']
cmake_toolchain_lines.extend("set(CMAKE_FIND_ROOT_PATH_MODE_%s ONLY)" % x for x in root_path_modes)

write_file(cmake_toolchain_file, '\n'.join(cmake_toolchain_lines) + '\n')
options.append('-DCMAKE_TOOLCHAIN_FILE=%s' % cmake_toolchain_file)

if '-DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=' not in self.cfg['configopts']:
# add -DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=64 option to ensure libraries are searched
# in *both* <sysroot>/usr/lib64 and <sysroot>/usr/lib;
# see https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX.html
# and https://cmake.org/cmake/help/latest/command/find_library.html
options.append('-DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=64')

self.log.info("Using absolute path to compiler commands because of alterate sysroot %s", sysroot)
self.cfg['abs_path_compilers'] = True

Expand Down