Reputation: 51
I am creating a static library lets call it X. This library uses rapidjson library in .cpp files. When I export this as static library, I want to hide rapidjson dependency. Another project should be able to link with
target_link_librares(another_project PUBLIC X)
My CMake configuration:
add_library(X STATIC
hub.cpp
)
target_include_directories(X PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:include>
)
get_target_property(X_INCLUDE_DIRS X INTERFACE_INCLUDE_DIRECTORIES)
target_link_libraries(X
PUBLIC
Y // this can be visible
PRIVATE
rapidjson // this should not required when another project links to X
)
install(TARGETS X
EXPORT X-targets
ARCHIVE DESTINATION lib
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION include/X
FILES_MATCHING PATTERN "*.h"
)
install(EXPORT X-targets
FILE X-config.cmake
NAMESPACE X::
DESTINATION lib/X
)
When I install this and link to X, it requires for the line. However, this rapidjson is only used in the C++ files. And I want to hide this from end user.
find_package(RapidJson REQUIRED)
Is it possible to statically bundle these RapidJSON functions inside the X static library?
Upvotes: 0
Views: 45