1# 2# Check if the file system is case sensitive or not 3# Inspired by Andreas Lauser's cmake at: 4# https://github.com/OPM/opm-parser/blob/master/cmake/Modules/CheckCaseSensitiveFileSystem.cmake 5# Included in libiio (LGPL2) with permission. 6# 7# Sets the following variable: 8# HAVE_CASE_SENSITIVE_FILESYSTEM True if the file system honors the case of files 9# 10# I dislike that we have to emit a file from CMake, but I can't think of a better way. 11 12message(STATUS "Check for case-sensitive file systems") 13string(RANDOM LENGTH 6 ALPHABET abcdefghijklmnopqrstuvwxyz TMP_FILE_L) 14set(TMP_FILE_L "${TMP_FILE_L}.tmp") 15string(TOUPPER ${TMP_FILE_L} TMP_FILE_U) 16string(TIMESTAMP TMP_TIME) 17set(TMP_FILE_CONTENTS "${TMP_FILE_L} ${TMP_TIME}") 18# create a uppercase file 19file(WRITE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}" "${TMP_FILE_CONTENTS}") 20 21# test if lowercase file can be opened 22set(FileContents "") 23if (EXISTS "${CMAKE_BINARY_DIR}/${TMP_FILE_L}") 24 file(READ "${CMAKE_BINARY_DIR}/${TMP_FILE_L}" FileContents) 25endif() 26 27# remove the file 28file(REMOVE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}") 29 30# check the contents 31# If it is empty, the file system is case sensitive. 32if ("${FileContents}" STREQUAL "${TMP_FILE_CONTENTS}") 33 message(STATUS "File system is not case-sensitive") 34 set(HAVE_CASE_SENSITIVE_FILESYSTEM 0) 35else() 36 message(STATUS "File system is case-sensitive") 37 set(HAVE_CASE_SENSITIVE_FILESYSTEM 1) 38endif() 39