I am trying a simple test to see if CMake is working on my windows system correctly. I keep getting a error. Here is the command with the error.
cmake .
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- Configuring done
CMake Error at CMakeLists.txt:5 (add_executable):
No SOURCES given to target: main.cpp
CMake Generate step failed. Build files cannot be regenerated correctly.
code for file named main.cpp
#include <iostream>
int main()
{
std::cout << "hello world\n" << "this is a test" <<std::endl;
}
and my CMake file
cmake_minimum_required(VERSION 3.10)
project(test)
add_executable(main.cpp)
I have used CMake in Linux before so not sure why this is failed. I used Microsoft package manager to install it. I am using the command line for this, i tried the GUI it also failed. I have also deleted the CMake files and cache multiple times. I have not been able to find anything online.
CodePudding user response:
Can't add a comment since my reputation is too low, so I will write an answer instead. In the last line of your CMakeLists.txt file
add_executable(main.cpp)
you are missing the name of the executable
add_executable(name_exe main.cpp)
CMake is telling you that in the error message. CMake tries to create a target main.cpp without source files, since CMake suggests the name of the executable at the first place in the command add_executable().