Last active
April 2, 2020 17:47
-
-
Save nico/c942ac2542d0c369c3c2c0966c693cdd to your computer and use it in GitHub Desktop.
https://reviews.llvm.org/D77184 research
This file contains 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
# cmake -P foo.cmake | |
include(FindPythonInterp) | |
#set(FOO_DIR "/Users/thakis/blah") | |
set(FOO_DIR "/Users/thakis/blah" CACHE STRING "wsdf") | |
function(configure_lit_site_cfg site_in site_out) | |
cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING;PATHS" ${ARGN}) | |
#message(${FOO_DIR}) | |
# Walk ARG_PATHS and collect the current value of the variables in there. | |
foreach(path ${ARG_PATHS}) | |
#message("${path}") | |
list(APPEND ARG_PATH_VALUES "${${path}}") | |
endforeach() | |
#message("val ${ARG_PATH_VALUES}") | |
#message("py ${PYTHON_EXECUTABLE}") | |
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) | |
# This is len(ARG_PATH_VALUES) - 1, for use with foreach(RANGE) loops. | |
set(arg_path_limit 0) # XXX -1? | |
if (ARG_PATH_VALUES) | |
# Passing ARG_PATH_VALUES as-is to execute_process() makes cmake strip | |
# empty list entries. So escape the ;s in the list and do the splitting | |
# outselves. cmake has no relpath function, so use Python for that. | |
string(REPLACE ";" "\\;" ARG_PATH_VALUES_ESCAPED "${ARG_PATH_VALUES}") | |
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" | |
"import os, sys; sys.stdout.write(';'.join(os.path.relpath(p, sys.argv[1]) if p else '' for p in sys.argv[2].split(';')))" | |
"/Users/thakis" | |
${ARG_PATH_VALUES_ESCAPED} | |
OUTPUT_VARIABLE ARG_PATH_VALUES_RELATIVE) | |
#message("p ${ARG_PATHS}") | |
#message("v ${ARG_PATH_VALUES}") | |
#message("o ${ARG_PATH_VALUES_RELATIVE}") | |
list(LENGTH ARG_PATHS len_vars) | |
list(LENGTH ARG_PATH_VALUES len_values) | |
list(LENGTH ARG_PATH_VALUES_RELATIVE len_rels) | |
if ((NOT ${len_vars} EQUAL ${len_values}) OR | |
(NOT ${len_vars} EQUAL ${len_rels})) | |
message(SEND_ERROR "PATHS lengths got confused") | |
endif() | |
math(EXPR arg_path_limit "${len_rels} - 1") | |
# Transform variables mentioned in ARG_PATHS to relative paths for | |
# the configure_file() call. | |
foreach(i RANGE ${arg_path_limit}) | |
list(GET ARG_PATHS ${i} val1) | |
list(GET ARG_PATH_VALUES_RELATIVE ${i} val2) | |
set(${val1} ${val2}) | |
endforeach() | |
endif() | |
message(${FOO_DIR}) | |
#configure_file(${site_in} ${site_out} @ONLY) | |
# Restore ARG_PATHS variables to their original values. | |
#foreach(i RANGE ${arg_path_limit}) | |
#list(GET ARG_PATHS ${i} val1) | |
#list(GET ARG_PATH_VALUES ${i} val2) | |
#set(${val1} ${val2}) | |
#endforeach() | |
message(${FOO_DIR}) | |
endfunction() | |
message(${FOO_DIR}) | |
configure_lit_site_cfg( | |
"asdf" | |
"foo" | |
PATHS | |
"FOO_DIR" | |
) | |
message(${FOO_DIR}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment