CMake 3.22 crashes when using cmake_path
When using cmake_path
in CMake 3.22.0, it crashes with:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::erase: __pos (which is 8457) > this->size() (which is 18)
Aborted (core dumped)
(Note: The value of the __pos
varies with repeated runs.)
Using --trace-expand
didn't reveal much:
...
CMakeTestCXXCompiler.cmake(86): foreach(f )
CMakeTestCXXCompiler.cmake(89): unset(CMAKE_CXX_ABI_FILES )
CMakeTestCXXCompiler.cmake(92): set(CMAKE_TRY_COMPILE_TARGET_TYPE )
CMakeTestCXXCompiler.cmake(93): unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE )
CMakeTestCXXCompiler.cmake(94): unset(__CMAKE_CXX_COMPILER_OUTPUT )
CMakeLists.txt(3): cmake_path(SET foo /path/to/something )
CMakeLists.txt(4): cmake_path(REMOVE_FILENAME foo )
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::erase: __pos (which is 8457) > this->size() (which is 18)
Aborted (core dumped)
It does succeed when building with CMake 3.21.2:
...
CMakeTestCXXCompiler.cmake(86): foreach(f )
CMakeTestCXXCompiler.cmake(89): unset(CMAKE_CXX_ABI_FILES )
CMakeTestCXXCompiler.cmake(92): set(CMAKE_TRY_COMPILE_TARGET_TYPE )
CMakeTestCXXCompiler.cmake(93): unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE
)
CMakeTestCXXCompiler.cmake(94): unset(__CMAKE_CXX_COMPILER_OUTPUT )
CMakeLists.txt(3): cmake_path(SET foo /path/to/something )
CMakeLists.txt(4): cmake_path(REMOVE_FILENAME foo )
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rhasib/tmp_cmake/cmake_test
Sample CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(test)
cmake_path(SET foo "/path/to/something")
cmake_path(REMOVE_FILENAME foo)
We are running on 64-bit Linux (RHEL7) with CMake 3.22.0 and GCC 9.3.1.