Skip to content

Commit

Permalink
cmake: Add install export set (#164)
Browse files Browse the repository at this point in the history
* cmake: Add install export set

Set convert_utf as private as it is statically linked.
Specify libunshield include directory in install interface
Add unshield:: namespace export set
Set all targets to the unshieldConfig export set

* ci: Add install and upload steps

* Add convert_utf to export set when compiled STATIC

* Set proper SHARED versioning
  • Loading branch information
bwrsandman authored Dec 7, 2023
1 parent 0fbc94c commit d10852e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ jobs:

- name: Test
run: ctest --test-dir build --output-on-failure

- name: Install
run: cmake --install build --strip --prefix install

- name: Upload
uses: actions/upload-artifact@v3
with:
name: unshield-${{github.sha}} (${{matrix.platform.name}})
path: install
if-no-files-found: error
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ add_subdirectory(src)

install(FILES man/unshield.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libunshield.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(EXPORT unshieldConfig NAMESPACE unshield:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/unshield)

if (BUILD_TESTING)
add_subdirectory(test)
Expand Down
11 changes: 6 additions & 5 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ else()
add_library(libunshield SHARED ${LIBUNSHIELD_HEADERS} ${LIBUNSHIELD_SOURCES})
endif()

target_include_directories(libunshield PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(libunshield PUBLIC ZLIB::ZLIB convert_utf)
target_include_directories(libunshield PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(libunshield PUBLIC ZLIB::ZLIB PRIVATE convert_utf)
set_target_properties(libunshield PROPERTIES OUTPUT_NAME unshield)
set_target_properties(libunshield PROPERTIES VERSION 0.0.0 SOVERSION 0)
set_target_properties(libunshield PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

if(USE_OUR_OWN_MD5)
target_link_libraries(libunshield PUBLIC md5)
else()
target_link_libraries(libunshield PUBLIC OpenSSL::Crypto)
endif()

install(TARGETS libunshield RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES libunshield.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS libunshield EXPORT unshieldConfig RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ if(BUILD_STATIC AND MSVC)
set_msvc_runtime_static()
endif()

install(TARGETS unshield RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(TARGETS_TO_INSTALL unshield)

if(BUILD_STATIC)
list(APPEND TARGETS_TO_INSTALL convert_utf)
endif()

install(TARGETS ${TARGETS_TO_INSTALL} EXPORT unshieldConfig RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

0 comments on commit d10852e

Please sign in to comment.