Skip to content

Commit

Permalink
feat: add support for installing private header files
Browse files Browse the repository at this point in the history
  • Loading branch information
sanfengAndroid committed Dec 6, 2024
1 parent 41548b7 commit d1a5d94
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

option(FAKELINKER_INSTALL_PRIVATE_HEADERS "Install private header files for static linking" OFF)

if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(CMAKE_BUILD_TYPE "Release")
endif()
Expand Down Expand Up @@ -97,8 +99,15 @@ target_include_directories(fakelinker_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/fakelinker>
)
target_link_libraries(fakelinker_static ${log-lib})

if(FAKELINKER_INSTALL_PRIVATE_HEADERS)
target_include_directories(fakelinker_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/fakelinker>
)
endif()

target_link_libraries(fakelinker_static ${log-lib})

add_library(fakelinker SHARED
linker/linker_dynamic.cpp
Expand All @@ -117,7 +126,6 @@ set_target_properties(fakelinker PROPERTIES
"${LINK_FLAGS} -Wl,--gc-sections,-s,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/symbol.map.txt\""
)


install(TARGETS fakelinker fakelinker_static
EXPORT fakelinker
)
Expand All @@ -126,6 +134,13 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fakelinker/fakelinker
)

if(FAKELINKER_INSTALL_PRIVATE_HEADERS)
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/linker"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fakelinker/fakelinker
FILES_MATCHING PATTERN "*.h"
)
endif()

install(EXPORT fakelinker
FILE fakelinker-config.cmake
NAMESPACE fakelinker::
Expand Down

0 comments on commit d1a5d94

Please sign in to comment.