CMAKE_SOURCE_DIR is not normalised in server mode
Hello,
I originally reported the bug here: https://github.com/vector-of-bool/vscode-cmake-tools/issues/642 But I suspect that the bug is in the cmake-server code where some normalisation does not take place.
Brief Issue Summary
I have the problem that the if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
expression does not return true for the root-level CMakeLists.txt file. That breaks some code that uses this expression to check if the project is the "root" level project or if it has been added via add_subdirectory
.
To reproduce put the following into a CMakeLists.txt
file and load it into vscode:
project(testcase NONE)
message(STATUS "CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}")
If you configure you'll see the following output (note the different c:
vs. C:
):
[cmake] CMAKE_SOURCE_DIR=c:/Users/gjasny/Git/testcase
[cmake] CMAKE_CURRENT_SOURCE_DIR=C:/Users/gjasny/Git/testcase
[cmake] CMAKE_BINARY_DIR=c:/Users/gjasny/Git/testcase/build
[cmake] CMAKE_CURRENT_BINARY_DIR=C:/Users/gjasny/Git/testcase/build
If I run cmake on the command line everything works as expected:
cmake.exe -S c:\Users\gjasny\Git\testcase -B C:\Users\gjasny\Git\testcase
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.14393.
-- CMAKE_SOURCE_DIR=C:/Users/gjasny/Git/testcase
-- CMAKE_CURRENT_SOURCE_DIR=C:/Users/gjasny/Git/testcase
-- CMAKE_BINARY_DIR=C:/Users/gjasny/Git/testcase
-- CMAKE_CURRENT_BINARY_DIR=C:/Users/gjasny/Git/testcase
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/gjasny/Git/testcase
Expected:
in the root-level of the project the CMAKE_CURRENT_xxx_DIR
and CMAKE_xxx_DIR
should be STREQUAL.
Platform and Versions
- Operating System: Windows
- CMake Version: 3.13.3
- VSCode Version: 1.30.2
- CMake Tools Extension Version: 1.1.3
- Compiler/Toolchain: Visual C++ 2017
Thanks, Gregor