Last active
March 17, 2023 13:20
-
-
Save scivision/da26bc936182f623f595c8ce85706a53 to your computer and use it in GitHub Desktop.
Shows distinct "REAL_PATH" behavior of get_filename_component(REALPATH) and file(REAL_PATH)
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 3.26.0 Darwin | |
-- source directory: /tmp | |
uppercase: /tmp/cmake_9X4EF26O4A20GGJB | |
lowercase: /tmp/cmake_9x4ef26o4a20ggjb | |
-- touch file /tmp/cmake_9x4ef26o4a20ggjb | |
-- Case-insensitive filesystem detected: | |
get_filename_component(REALPATH): /private/tmp/cmake_9x4ef26o4a20ggjb | |
get_filename_component(ABSOLUTE): /tmp/cmake_9X4EF26O4A20GGJB | |
file(REAL_PATH): /private/tmp/cmake_9x4ef26o4a20ggjb | |
cmake_path(ABSOLUTE_PATH): /tmp/cmake_9X4EF26O4A20GGJB |
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 3.26.0 Windows | |
-- source directory: C:/tmp | |
uppercase: C:/tmp/cmake_EUQ6Z2K7UOODL9J8 | |
lowercase: c:/tmp/cmake_euq6z2k7uoodl9j8 | |
-- touch file c:/tmp/cmake_euq6z2k7uoodl9j8 | |
-- Case-insensitive filesystem detected: | |
get_filename_component(REALPATH): C:/tmp/cmake_euq6z2k7uoodl9j8 OFF | |
get_filename_component(ABSOLUTE): C:/tmp/cmake_euq6z2k7uoodl9j8 OFF | |
file(REAL_PATH): C:/tmp/cmake_EUQ6Z2K7UOODL9J8 OFF | |
cmake_path(ABSOLUTE_PATH): C:/tmp/cmake_EUQ6Z2K7UOODL9J8 OFF |
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.21) | |
# Shows distinct "REAL_PATH" behavior of get_filename_component and file() | |
# including effects with case-insensitive filesystem if present. | |
string(RANDOM LENGTH 16 ALPHABET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" Uname) | |
string(PREPEND Uname ${CMAKE_CURRENT_LIST_DIR}/cmake_) | |
string(TOLOWER ${Uname} Lname) | |
if(WIN32) | |
set(os "Windows") | |
else() | |
execute_process(COMMAND uname -s OUTPUT_VARIABLE os OUTPUT_STRIP_TRAILING_WHITESPACE) | |
endif() | |
message(STATUS "CMake ${CMAKE_VERSION} ${os}") | |
message(STATUS "source directory: ${CMAKE_CURRENT_LIST_DIR} | |
uppercase: ${Uname} | |
lowercase: ${Lname}") | |
message(STATUS "touch file ${Lname}") | |
file(TOUCH ${Lname}) | |
get_filename_component(real_gfc ${Uname} REALPATH) | |
cmake_path(COMPARE ${Lname} EQUAL ${real_gfc} same_rgfc) | |
get_filename_component(abs_gfc ${Uname} ABSOLUTE) | |
cmake_path(COMPARE ${Lname} EQUAL ${abs_gfc} same_agfc) | |
cmake_path(ABSOLUTE_PATH Uname OUTPUT_VARIABLE abs_cp) | |
cmake_path(COMPARE ${Lname} EQUAL ${abs_cp} same_cp) | |
file(REAL_PATH ${Uname} real_fr) | |
cmake_path(COMPARE ${Lname} EQUAL ${real_fr} same_fr) | |
if(EXISTS ${Uname}) | |
set(txt "in") | |
else() | |
set(txt "") | |
endif() | |
message(STATUS "Case-${txt}sensitive filesystem detected: | |
get_filename_component(REALPATH): ${real_gfc} ${same_rgfc} | |
get_filename_component(ABSOLUTE): ${abs_gfc} ${same_agfc} | |
file(REAL_PATH): ${real_fr} ${same_fr} | |
cmake_path(ABSOLUTE_PATH): ${abs_cp} ${same_cp}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment