我是一个“emacs / [c] make / ninja / clang / bash / linux / macOs”的C ++开发人员,他不习惯像Visual Studio这样的IDE。我并没有声称任何一种方法更好或更糟,只是因为我不知道如何使用IDE。
我现在需要为强烈依赖Visual Studio的基于Windows的客户端开发C ++项目。
我的理解是Visual Studio 2017内置了对CMake,Ninja和Google Test的支持。但是,我无法想出一个允许我像往常一样简单编码的工作流程,将我的代码提交给GitHub,让我的客户只需“刷新仓库并重建解决方案”。
这是我的问题:克隆C ++ / CMake GitHub存储库并在Visual Studio中构建它的绝对最简单的方法是什么?
作为参考,我创建了以下存储库:
https://github.com/arrieta/visual-studio-cmake-test
这是我使用我的常规方法构建它的方式:
$ git clone https://github.com/arrieta/visual-studio-cmake-test.git
$ cd visual-studio-cmake-test
$ mkdir build
$ cd build
$ cmake -G Ninja ../
$ ninja
$ ./app
Welcome to app v0.0.1
Hello, world!
对于我的生活,我无法在Visual Studio中提出这样简单的方法(并不是说工具很糟糕,只是我的无知)。我创建了一个“解决方案”,然后是“项目”,然后是“回购”,我有很多选择,我不知所措。
感谢任何帮助。
vre
的解决方案用户vre
提供了以下方法,该方法完全符合预期。这里,C:\>
表示我的Windows 开发人员命令提示符。
C:\> git clone https://github.com/arrieta/visual-studio-cmake-test.git
Cloning into 'visual-studio-cmake-test'...
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 20 (delta 3), reused 20 (delta 3), pack-reused 0Unpacking objects: 5% (1/20)
Unpacking objects: 100% (20/20), done.
C:> cd visual-studio-cmake-test
C:> mkdir build
C:> cd build
C:> cmake -G "Visual Studio 15 2017" ..\
-- The C compiler identification is MSVC 19.13.26129.0
-- The CXX compiler identification is MSVC 19.13.26129.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:[...]/visual-studio-cmake-test/build
C:> cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /maxcpucount
[uninteresting output]
C:> cd Debug
C:> app.exe
Welcome to app v0.0.1
Hello, world!
答案 0 :(得分:4)
您可以从CMake定位Visual Studio生成器,然后使用CMake的构建工具模式。 E.g
cmake -G "Visual Studio 15 2017" ..\
和
cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /maxcpucount
所有来自您的构建目录。这使用MSBuild作为本机构建工具,并从命令行构建整个解决方案。
有关安装或测试的CMake构建工具模式的更多参数,请参阅此文章。 CMake + MSVC build tools 2015 - what to do after invoking cmake?
请参阅CMake文档了解构建工具模式https://cmake.org/cmake/help/v3.10/manual/cmake.1.html
C:\> git clone https://github.com/arrieta/visual-studio-cmake-test.git
Cloning into 'visual-studio-cmake-test'...
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 20 (delta 3), reused 20 (delta 3), pack-reused 0Unpacking objects: 5% (1/20)
Unpacking objects: 100% (20/20), done.
C:> cd visual-studio-cmake-test
C:> mkdir build
C:> cd build
C:> cmake -G "Visual Studio 15 2017" ..\
-- The C compiler identification is MSVC 19.13.26129.0
-- The CXX compiler identification is MSVC 19.13.26129.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:[...]/visual-studio-cmake-test/build
C:> cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /maxcpucount
[uninteresting output]
C:> cd Debug
C:> app.exe
Welcome to app v0.0.1
Hello, world!