Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better targets for use as a submodule #63

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ if (BUILD_STATIC_DEPS)
include(StaticBuild)
endif()

# Add a "libsession::libsession" target that depends on everything; when building a general purpose
# program that links against libsession, this is generally what you want to depend on.
add_library(libsession INTERFACE)

if(STATIC_BUNDLE)

include(combine_archives)
Expand All @@ -133,8 +137,24 @@ if(STATIC_BUNDLE)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libsession-util.a
ARCHIVE DESTINATION ${lib_folder})

# Add a target for the bundled library output:
add_library(libsession::util ALIAS session-util)

target_link_libraries(libsession INTERFACE libsession::util)
else()
foreach(tgt ${libsession_export_targets})
target_link_libraries(libsession INTERFACE libsession::${tgt})
endforeach()
endif()

add_library(libsession::libsession ALIAS libsession)
export(
TARGETS libsession
NAMESPACE libsession::
APPEND FILE libsessionTargets.cmake
)


option(WITH_TESTS "Enable unit tests" ${libsession_IS_TOPLEVEL_PROJECT})
if(WITH_TESTS)
Expand Down
8 changes: 7 additions & 1 deletion cmake/combine_archives.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ function(combine_archives output_archive dep_target)
DEPENDS ${mri_file} ${ARGN}
COMMAND /usr/bin/libtool -static -o ${FULL_OUTPUT_PATH} ${merge_libs})
endif()
add_custom_target(${output_archive} DEPENDS ${FULL_OUTPUT_PATH})
add_custom_target(${output_archive}-lib DEPENDS ${FULL_OUTPUT_PATH})
add_library(${output_archive} STATIC IMPORTED GLOBAL)
set_target_properties(${output_archive} PROPERTIES
IMPORTED_LOCATION ${FULL_OUTPUT_PATH}
IMPORTED_LINK_INTERFACE_LANGUAGES "C;CXX"
)
add_dependencies(${output_archive} ${output_archive}-lib)
endfunction(combine_archives)
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ endforeach()
export(
TARGETS ${export_targets} common version
NAMESPACE libsession::
FILE libsessionTargets.cmake
FILE ../libsessionTargets.cmake
)

set(libsession_export_targets "${export_targets}" PARENT_SCOPE)