doctopus
doctopus

Reputation: 5657

Trouble understanding this CMakeLists.txt file

I'm absolutely new to C++/CMake and from all the tutorials I've read, there should be an add_executable() line in the top-level CMakeLists.txt file. However, in this project that I'm working on, there isn't one:

cmake_minimum_required (VERSION 2.8.11)
set(CMAKE_CXX_STANDARD 17)
set(VERSION dev)

find_package(PkgConfig REQUIRED)
include_directories(SYSTEM $ENV{HOME}/usr/local/include)

project(engine)
add_subdirectory(common)

add_subdirectory(matching)
add_subdirectory(matching_test)
add_subdirectory(matching_tcp_client)
add_subdirectory(matching_tcp_service)
add_subdirectory(md_tcp_service)

add_subdirectory(matching_zmq_service)

add_subdirectory(net)

add_subdirectory(proxy_ws)
add_subdirectory(proxy_md_ws)
add_subdirectory(zmq_proxy)

add_subdirectory(test_tcp_matching_client)
add_subdirectory(test_tcp_matching_server)
add_subdirectory(test_md_tcp_server)

add_subdirectory(test_zmq_matching_server)
add_subdirectory(xpubxsub)

add_subdirectory(md)

A few questions I have:

Upvotes: 0

Views: 60

Answers (1)

antoine
antoine

Reputation: 1883

there should be an add_executable() line in the top-level CMakeLists.txt file

This is a wrong assumption. add_executable is not mandatory at all. For example, a project that produces only library will have add_library and no add_executable. Moreover this function could be in a subdirectory, there is no need to put it in the top level CMakeLists.txt.

In your example, there are lost of add_subdirectory with a folder name as argument. Those folder should contain a CMakeLists.txt file. You should look at them for a add_executable command. There might be several: one project could produce several executable. A common use case is a project that produce one main executable and several test executables.

Only executable needs to have a main() function and only one. If your project doesn't produce any executable, then there is no need to define a main() function.

Upvotes: 1

Related Questions