Through that, I link private libraries with BUILD_INTERFACE genexpr and they wouldn't be in the exported targets, but the libraries' linked libraries will be and unfortunately when we run the install rule they will be installed. And i don't have access to those libraries' code to change. How can I remove those targets from being installed?
For testing:
TestingExports.text
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(TestinExports CXX)
add_subdirectory(ThatThing)
file(WRITE main.cc "int main() { }")
add_executable(${PROJECT_NAME} main.cc)
target_link_libraries(${PROJECT_NAME} PRIVATE $<BUILD_INTERFACE:ThatThing>)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config)
install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake)
ThatThing/CMakeLists.txt
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(ThatThing CXX)
add_subdirectory(ThoseLibraries)
file(WRITE that_thing.cc "void Function() { }")
add_library(${PROJECT_NAME} STATIC that_thing.cc)
target_link_libraries(${PROJECT_NAME} PRIVATE ThoseLibraries)
ThatThing/ThoseLibraries/CMakeLists.txt
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(ThoseLibraries CXX)
file(WRITE those_libraries.cc "void AnotherFunction() { }")
add_library(${PROJECT_NAME} STATIC those_libraries.cc)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config)
install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake)
After we build and install we can see that ThoseLibraries
is also installed:
$ cmake -B build -DCMAKE_INSTALL_PREFIX=$PWD/install
$ cmake --build build
$ cmake --install build
-- Install configuration: ""
-- Installing: /tmp/export_set/install/lib/libThoseLibraries.a
-- Installing: /tmp/export_set/install/lib/cmake/ThoseLibrariesConfig.cmake
-- Installing: /tmp/export_set/install/lib/cmake/ThoseLibrariesConfig-noconfig.cmake
-- Installing: /tmp/export_set/install/bin/TestinExports
-- Installing: /tmp/export_set/install/lib/cmake/TestinExportsConfig.cmake
-- Installing: /tmp/export_set/install/lib/cmake/TestinExportsConfig-noconfig.cmake
EDIT:
Obviously using
EXCLUDE_FROM_ALL
is completely useless from what I wrote as an example above. I don't want completely that target to be removed fromALL
. Also, I needed enough information for my IDE. Mentioned here: https://stackoverflow.com/a/64900982/9248466And overwriting
install()
is a workaround that doesn't work for me because I also have some rules and options to install the private section of the project. Mentioned here: https://stackoverflow.com/a/43043052/9248466- The overwriting
install()
macro didn't work and cause CMake ignore all the installation rules:
- The overwriting
macro(install)
endmacro()
add_subdirectory(ThatThing)
macro(install)
_install(${ARGV})
endmacro(install)