Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure cmake to get an executable not by default

Tags:

cmake

I have a small project with cmake. I build a lib and an executable. on the development machine I want also an executable that cannot be build on other machines/environments.

e.g.:

<my-lib>
 | -- CMakeLists.txt
 |
 + -- src/             -> build the lib/archive
 |     |-- lib.c
 |     |-- lib.h
 |     |-- CMakeLists.txt
 |
 + -- tool             -> build the tool
 |     |-- tool.c
 |     |-- CMakeLists.txt
 |
 + -- tests            -> build the unit tests
 |     |-- tests.c
 |     |-- CMakeLists.txt

I added CMakeLists.txt to all directories. Also an add_executable to the tests. Now the unit-test executable is build by default. But I want to exclude it from default target.

CMakeLists.txt in tests:

find_library (CUNIT_LIB cunit)
include_directories (${Cunit_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/src")

set (CMAKE_C_FLAGS "-O2 -Wall -Werror")

add_executable (unit-test tests.c)

target_link_libraries (unit-test my-lib cunit)

Has anyone a hint how to handle this? I don't want to build unit-test always!

like image 898
user3087662 Avatar asked Sep 02 '25 01:09

user3087662


1 Answers

There is a property EXCLUDE_FROM_ALL for such task.

You can write:

set_target_properties(unit-test PROPERTIES EXCLUDE_FROM_ALL TRUE)
like image 181
Draks Avatar answered Sep 05 '25 03:09

Draks