-
Notifications
You must be signed in to change notification settings - Fork 35
Cmake support
Cmake is a cross-platform build system which is quite popular in the C++ world. The file structure of a Cmake project differs from a project created with Visual Studio. In contrast to Visual Studio Cmake uses by default an out-of-place build strategy. This means that the compiler artifacts are not stored in the same directory as the source. An advantage of this concept is that binaries can easily ignored by just excluding a single folder from version control.
Our extension stores the commandline arguments inside a json file which is stored right next to the corresponding msbuild project file. In a pure Visual Studio environment the project file is naturally under version control. By using Cmake the project file will be stored inside some sort of 'build' folder which is usally ignored by version control thus our json file too. A typical Cmake project structure looks like this:
project/
|-- build/ [Ignored by vcs]
| |-- project.sln
| |-- project.csproj
| +-- project.args.json
|-- src/
|-- CMakeLists.txt
+-- main.cpp
You can solve this problem by telling our extension a different path to the json file by setting a msbuild property inside the project file.
This can easily be done inside a CMakeLists.txt
script by setting VS_GLOBAL_SmartCmdArgJsonFile
with set_property
.
The path should be an absolute path to reduce the chances that something goes wrong.
project(SimpleCmake)
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
add_executable(SimpleCmake main.cpp)
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
get_filename_component(smartCmdArgJsonFile "project.args.json" ABSOLUTE)
MESSAGE(STATUS "Path to json file: " ${smartCmdArgJsonFile})
set_property(TARGET SimpleCmake PROPERTY VS_GLOBAL_SmartCmdArgJsonFile ${smartCmdArgJsonFile})
endif()
Now the json file can be stored outside of the build folder and is no longer ignored. The new project structure looks like this:
project/
|-- build/ [Ignored by vcs]
| |-- project.sln
| +-- project.csproj
|-- src/
|-- CMakeLists.txt
|-- main.cpp
+-- project.args.json