简体   繁体   中英

cmake command line option

I am new to VS development and Cmake. I have used CMake-GUI to generate a visual studio solution and am able to build it successfully.

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.

In cmake-gui, in order to configure, I provide two values Path of my source code Path where binaries will be generated

However, when I try to run the same over command line (using the following command)

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.

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.

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. 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 ). I'd recommend avoiding leaving spaces after -D arguments.

Try this

Remove space between -D and parameter

 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. But I created a shell script file to avoid repeatedly fill up the entries.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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