Alexander K.
Alexander K.

Reputation: 1767

CMake targets setup questions

Imagine the following situation:

I have "project" folder, in this folder I have "src" folder and 2 files "1.cpp" and "2.cpp". Every single .cpp produce single executable. After cmake generate makefiles i want to be able to do the following :

so I want to be able to write the following:

What is the best way to achive this ? Thanks a lot!

Upvotes: 3

Views: 2010

Answers (1)

Morten Kristensen
Morten Kristensen

Reputation: 7613

You need a top-level CMakeLists.txt in the root which knows about your "src" directory (using add_subdirectory). Then in "src" you will need another CMakeLists.txt which specifies how to compile your executables. This in itself will make it possible to say, for instance:

make 1 2

As for the debug/release mode it can be specified in cmake via the variable CMAKE_BUILD_TYPE. But I usually, at top-level, instruct it for a debug or release mode if the variable is not specified:

IF( NOT CMAKE_BUILD_TYPE )
  SET( CMAKE_BUILD_TYPE Debug ) 
  SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG" )
ENDIF( NOT CMAKE_BUILD_TYPE )

Another way of editing the build type without modifying the CMakeLists.txt is to do

make edit_cache

Which will bring up an ncurses dialog with the variables, CMAKE_BUILD_TYPE among them.

Upvotes: 3

Related Questions