Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

visual studio - Building MSVC project with cmake and command-line

Good day!

Let us have a source file main.cpp and a CMakeLists.txt file containing the next text:

cmake_minimum_required(VERSION 2.6)
project(tmp)

set(CMAKE_CXX_FLAGS "-Wall")
add_executable(tmp.elf main.cpp)

Let's say the main.cpp file contains a simple "Hello, World!" program:

#include <stdio.h>

int main()
{
  printf("Hello, World!
");
  return 0;
}

We can build the project with cmake CMakeLists.txt && make. Then we'll just get the tmp.elf file which we can just run. Or we can get no tmp.elf file and assume that something is wrong with the main.cpp source file (assuming the compiler and cmake are installed properly on the building system).

So, the question is: how can we do the same on the Windows machine? E.g. we will get the tmp.vcproj file after running cmake CMakeLists.txt and then we need to build it somehow. How the build process can be performed using command-line? (Java's Process.start(), actually :-P )

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can start the build in a platform and CMake generator independent fashion by invoking cmake with the --build option:

cmake --build .

For multi-configuration generators, you can specify the configuration in the following way:

cmake --build . --config Release

Also see the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...