简体   繁体   English

cmake命令行选项

[英]cmake command line option

I am new to VS development and Cmake. 我是VS开发和Cmake的新手。 I have used CMake-GUI to generate a visual studio solution and am able to build it successfully. 我使用CMake-GUI生成可视化工作室解决方案,并能够成功构建它。

However, our code has now reached a stage where we can finally build & link into a binary. 但是,我们的代码现在已经达到了我们最终可以构建和链接到二进制文件的阶段。 With multiple people checking in code, we want to do a nightly build and so I was thinking of writing a batch file for this. 有多个人检查代码,我们想做一个夜间构建,所以我想为此编写一个批处理文件。

However, I am trying to invoke cmake from command line and am running into issues. 但是,我试图从命令行调用cmake并遇到问题。

In cmake-gui, in order to configure, I provide two values Path of my source code Path where binaries will be generated 在cmake-gui中,为了配置,我提供了两个值我的源代码路径Path,其中将生成二进制文件

However, when I try to run the same over command line (using the following command) 但是,当我尝试运行相同的over命令行时(使用以下命令)

cmake -G "NMake Makefiles" -D CMAKE_SOURCE_DIR="D:\source_code" -D CMAKE_BINARY_DIR="D:\source_code\build\gen\host"

CMake throws up an eror : The source directory "D:\\" is a file not a directory. CMake抛出一个错误:源目录“D:\\”是一个文件而不是一个目录。

I tried the following variations too without any luck 我没有任何运气也试过以下变化

cmake -G "NMake Makefiles" -D PROJECT_SOURCE_DIR="D:\source_code" -D PROJECT_BINARY_DIR="D:\source_code\build\gen

Can someone please guide me to the correct syntax. 有人可以指导我正确的语法。

Thanks in advance 提前致谢

You shouldn't try and set any of these variables on the command line. 您不应尝试在命令行上设置任何这些变量。 They're automatically set by CMake the first time it reads the CMakeLists.txt. 它们在第一次读取CMakeLists.txt时由CMake自动设置。

Instead, you should run the CMake command from within the binary dir, and pass the path to the directory containing the top-level CMakeLists.txt. 相反,您应该从二进制目录中运行 CMake命令,并将路径传递给包含顶级CMakeLists.txt的目录。 So something like: 所以类似于:

cd D:\source_code\build\gen\host
cmake -G"NMake Makefiles" D:\source_code

By the way, CMake's command line parsing isn't great (eg see this answer ). 顺便说一句,CMake的命令行解析不是很好(例如看到这个答案 )。 I'd recommend avoiding leaving spaces after -D arguments. 我建议避免在-D参数后留空格。

Try this 试试这个

Remove space between -D and parameter 删除-D和参数之间的空格

 cmake -G "NMake Makefiles" -DCMAKE_SOURCE_DIR="D:\source_code" -DCMAKE_BINARY_DIR="D:\source_code\build\gen\host"

In my project, We used a CMake-GUI. 在我的项目中,我们使用了CMake-GUI。 But I created a shell script file to avoid repeatedly fill up the entries. 但我创建了一个shell脚本文件,以避免重复填写条目。

Sample gist is as follows. 样本要点如下。

cd <DIRECTORY_TO_BUILD> && <CMAKE-INSTALLATION-PATH>/bin/cmake.exe --build= "<BUILDSOURCE-PATH> -DQt5Widgets_DIR:PATH=C:/Qt/5.12.0/msvc2017/lib/cmake/Qt5Widgets

I have started with cd else the script will create the build folder from where the script is run. 我已经开始使用cd了,脚本将创建运行脚本的构建文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM