I would like to first declare an target, say, an static library, then feeding its source files according to some options. Is it possible to achieve that?
Say, what I want is a command target_specify_sources()
, and the full script is like:
cmake_minimum_required(VERSION 3.17)
project(hello)
option(USE_PLUGIN "use plugin?" ON)
add_library(my_target STATIC)
if (USE_PLUGIN)
target_specify_sources(my_target
src/base.cpp
src/plugin.cpp
)
else()
target_specify_sources(my_target
src/base.cpp
)
endif()
update:
I shoud make clear that "to declare a target, means not specifying any source files". The comment mentioned another question link:
Can one add further source files to an executable once defined?
there is target_sources()
command since cmake 3.1, but it is not "declare target".