This is a C/C++ project. I want to exclude a particular compilation target (say “xyz”) from my setup. There are macros already in place for that (say, XYZ), which I have successfully set to OFF so that the sources are not included.
Now the CMake setup is not from me, and I am fairly new to CMake. But what I see now is :
get_target_property called on non-existent target “xyz”
get_target_property called on non-existent target “xyz”
Cannot specify compile options for target “xyz” which is not built by this
The main CMakeLists has this :
if(XYZ)
add_subdirectory(xyz)
target_link_libraries(main INTERFACE xyz)
endif()
This successfully does not get called. Then some CMakeList down the directory hierarchy (in the env
folder) has this :
find_package(CorePackage CONFIG REQUIRED)
include(${CMAKE_CURRENT_LIST_DIR}/targetCompileOptions.cmake)
targetCompileOptions()
The code for this last function is found elsewhere :
function(targetCompileOptions)
set(compileOptions -Werror=double-promotion
-Werror=incompatible-pointer-types
…
)
set(uniqueTargets "")
set(parsedTargets "")
macro(getAllNotInterfaceLibs targets)
foreach(target ${targets})
if(${target} IN_LIST uniqueTargets OR ${target} IN_LIST parsedTargets)
continue()
endif()
list(APPEND parsedTargets ${target})
if (NOT ${target} STREQUAL "tar-NOTFOUND")
get_target_property(type ${target} TYPE)
if (NOT ${type} STREQUAL "INTERFACE_LIBRARY")
list(APPEND uniqueTargets ${target})
get_target_property(tar ${target} LINK_LIBRARIES)
getAllNotInterfaceLibs("${tar}")
else()
get_target_property(tar ${target} INTERFACE_LINK_LIBRARIES)
getAllNotInterfaceLibs("${tar}")
endif()
endif()
endforeach()
endmacro()
getAllNotInterfaceLibs(main)
list(REMOVE_DUPLICATES uniqueTargets)
foreach(target ${uniqueTargets})
target_compile_options(${target} PRIVATE ${compileOptions})
endforeach()
endfunction()
So this function seems to take a target, get list of linked targets, remove duplicates, and on whatever targets remain, apply some compilation options that we like.
The error is given at the call to the targetCompileOptions
function in the env
CMakeLists.
Should I look in my code for a place where it still (and wrongly, now that I have it deactivated) references “xyz” and links it to the main target ? What are ways that “xyz” could still be referenced & linked, aside from target_link_libraries
? Is there something I don’t understand ?