Last active
January 18, 2020 01:10
-
-
Save pmolodo/0b36ee7167237b76556a0e1975bbc6b9 to your computer and use it in GitHub Desktop.
Test of separate_arguments
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_minimum_required(VERSION 3.12.0) | |
enable_testing() | |
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") | |
set(IS_WINDOWS TRUE) | |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") | |
set(IS_LINUX TRUE) | |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
set(IS_MACOSX TRUE) | |
endif() | |
function(cmake_list_to_envpath_old varname) | |
message("(orig) : ${${varname}}") | |
if(IS_WINDOWS) | |
string(REPLACE ";" "\;" ${varname} "${${varname}}") | |
message("(replaced) : ${${varname}}") | |
else() | |
separate_arguments(${varname} NATIVE_COMMAND "${${varname}}") | |
message("(separated): ${${varname}}") | |
string(REPLACE "\;" ":" ${varname} "${${varname}}") | |
message("(replaced) : ${${varname}}") | |
endif() | |
set(${varname} "${${varname}}" PARENT_SCOPE) | |
endfunction() | |
function(cmake_list_to_envpath_new varname) | |
message("(orig) : ${${varname}}") | |
if(IS_WINDOWS) | |
string(REPLACE ";" "\;" ${varname} "${${varname}}") | |
message("(replaced) : ${${varname}}") | |
else() | |
string(REPLACE ";" ":" ${varname} "${${varname}}") | |
message("(replaced) : ${${varname}}") | |
endif() | |
set(${varname} "${${varname}}" PARENT_SCOPE) | |
endfunction() | |
# testOldSimple | |
message("########################################") | |
message("testOldSimple") | |
set(mypath | |
"/first/path" | |
"/second/path") | |
cmake_list_to_envpath_old(mypath) | |
add_test( | |
NAME testOldSimple | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMAND python -c "import os; expected = os.pathsep.join(['/first/path', '/second/path']); actual = os.environ['mypath']; print(actual); assert(expected == actual)" | |
) | |
set_property(TEST testOldSimple APPEND PROPERTY ENVIRONMENT | |
"mypath=${mypath}") | |
# testOldSpaces | |
message("########################################") | |
message("testOldSpaces") | |
set(mypath | |
"/first path/subdir" | |
"/second/path") | |
cmake_list_to_envpath_old(mypath) | |
add_test( | |
NAME testOldSpaces | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMAND python -c "import os; expected = os.pathsep.join(['/first path/subdir', '/second/path']); actual = os.environ['mypath']; print(actual); assert(expected == actual)" | |
) | |
set_property(TEST testOldSpaces APPEND PROPERTY ENVIRONMENT | |
"mypath=${mypath}") | |
# testNewSimple | |
message("########################################") | |
message("testNewSimple") | |
set(mypath | |
"/first/path" | |
"/second/path") | |
cmake_list_to_envpath_new(mypath) | |
add_test( | |
NAME testNewSimple | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMAND python -c "import os; expected = os.pathsep.join(['/first/path', '/second/path']); actual = os.environ['mypath']; print(actual); assert(expected == actual)" | |
) | |
set_property(TEST testNewSimple APPEND PROPERTY ENVIRONMENT | |
"mypath=${mypath}") | |
# testNewSpaces | |
message("########################################") | |
message("testNewSpaces") | |
set(mypath | |
"/first path/subdir" | |
"/second/path") | |
cmake_list_to_envpath_new(mypath) | |
add_test( | |
NAME testNewSpaces | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMAND python -c "import os; expected = os.pathsep.join(['/first path/subdir', '/second/path']); actual = os.environ['mypath']; print(actual); assert(expected == actual)" | |
) | |
set_property(TEST testNewSpaces APPEND PROPERTY ENVIRONMENT | |
"mypath=${mypath}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment