CMake

How to fix CMake ‘make: *** No targets specified and no makefile found. Stop.’

Problem:

You are trying to build a software that is using the CMake build system.

You are trying to run make to build, but you see this error message:

make: *** No targets specified and no makefile found.  Stop.

Solution:

Before running make, you need to configure your build using CMake.

The simplest way of doing that is to run

cmake .

Typically you only need to do that once for each project ; CMake will automatically detect changes to CMakeLists.txt when you run make.

After that, you can run make again. If the build is successful, you’ll see a message like this:

[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
[100%] Built target main
Posted by Uli Köhler in CMake

How to fix CMake Parse error: Expected a command name, got unquoted argument with text "//"

Problem:

You want to build an application using CMake but you see an error message like this:

CMake Error at CMakeLists.txt:1:
  Parse error.  Expected a command name, got unquoted argument with text
  "//".


-- Configuring incomplete, errors occurred!
See also "/ram/CMakeFiles/CMakeOutput.log".
Makefile:176: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1

Solution:

You CMakeLists.txt likely looks like this:

// Create main executable
add_executable(main main.cpp)

The issue is in the first line:

// Create main executable

CMake comments start with #, not with // !

Change any comment line starting with // to start with # instead. In our example:

# Create main executable
add_executable(main main.cpp)

Then try building again (e.g. using cmake . or make). Unless you have other issues in your CMake configuration, the output should now look like this (for simple builds):

-- Configuring done
-- Generating done
-- Build files have been written to: /ram
[100%] Built target main

 

Posted by Uli Köhler in CMake

Minimal CMakeLists.txt for executables

This is the minimal CMakeLists.txt for building an executable named myproject from main.cpp:

cmake_minimum_required (VERSION 2.8.11)
project (MyProject)
add_executable (myproject main.cpp)

 

Posted by Uli Köhler in CMake