Target Properties
Every target_* command you have used so far is a convenience wrapper around properties: named values stored on a target. target_include_directories(lib PUBLIC inc) appends inc to both INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES. Knowing the properties lets you read and set anything CMake knows about a target.
Reading and writing properties
cmake
set_target_properties(app PROPERTIES OUTPUT_NAME "tad-app" CXX_EXTENSIONS OFF)
set_property(TARGET app APPEND PROPERTY COMPILE_DEFINITIONS EXTRA=1)
get_target_property(var app OUTPUT_NAME) # var = tad-app (or var-NOTFOUND)Properties also exist on other scopes (GLOBAL, DIRECTORY, SOURCE, INSTALL, TEST, CACHE), set with set_property(<SCOPE> …) and read with get_property.
bash · try it yourself
mkdir -p props && cd props
cat > CMakeLists.txt <<'CM'
cmake_minimum_required(VERSION 3.25)
project(Props VERSION 2.1.0 LANGUAGES CXX)
add_library(core STATIC core.cpp)
target_include_directories(core PUBLIC include PRIVATE src)
target_compile_definitions(core PUBLIC CORE_API=1 PRIVATE CORE_BUILDING)
target_compile_features(core PUBLIC cxx_std_20)
set_target_properties(core PROPERTIES VERSION ${PROJECT_VERSION} OUTPUT_NAME tadcore)
include(CMakePrintHelpers)
cmake_print_properties(TARGETS core PROPERTIES
TYPE OUTPUT_NAME VERSION
INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES
COMPILE_DEFINITIONS INTERFACE_COMPILE_DEFINITIONS
INTERFACE_COMPILE_FEATURES)
get_target_property(missing core SOVERSION)
message("SOVERSION = ${missing}")
CM
mkdir -p include src && echo 'int core() { return 0; }' > core.cpp
# cmake_print_properties reports with message(STATUS), so keep the status lines this time
cmake -S . -B build -G Ninja 2>&1 | grep -v -e '^--' -e '^