Created
August 10, 2022 08:33
-
-
Save Novakov/43d3286ddcc414dd4083560469089fd9 to your computer and use it in GitHub Desktop.
Create relocatable Conan install folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run as `install(SCRIPT)` | |
execute_process( | |
COMMAND | |
conan install | |
-l @CMAKE_BINARY_DIR@/conan.${CMAKE_INSTALL_CONFIG_NAME}.lock | |
-g deploy | |
-g CMakeDeps | |
-if ${CMAKE_INSTALL_PREFIX}/packages | |
@CMAKE_SOURCE_DIR@/conanfile.txt | |
COMMAND_ERROR_IS_FATAL ANY | |
) | |
execute_process( | |
COMMAND @Python3_EXECUTABLE@ @CMAKE_SOURCE_DIR@/patch_conan_cmake_files.py ${CMAKE_INSTALL_PREFIX}/packages | |
COMMAND_ERROR_IS_FATAL ANY | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os.path | |
from glob import glob | |
import re | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('root', help='Path to directory containing Conan generated files') | |
return parser.parse_args() | |
def main(args): | |
match_pattern = re.compile(r'set\((?P<name>\S+)_PACKAGE_FOLDER_(?P<config>\S+) ".*"\)') | |
replacement = r'set(\g<name>_PACKAGE_FOLDER_\g<config> "${CMAKE_CURRENT_LIST_DIR}/\g<name>")' | |
for fname in glob(os.path.abspath(os.path.join(args.root, '*-data.cmake'))): | |
with open(fname, 'r') as f: | |
content = f.read() | |
content = match_pattern.sub(replacement, content) | |
with open(fname, 'w') as f: | |
f.write(content) | |
main(parse_args()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment