Skip to content

Commit

Permalink
Merge pull request #16 from rlei-weta/fileseq_cpp_cmake_install
Browse files Browse the repository at this point in the history
Install and export library targets.
  • Loading branch information
justinfx authored May 10, 2021
2 parents 97d877d + 8452eb4 commit a7e9ae5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,40 @@ SET_TARGET_PROPERTIES(fileseq_static PROPERTIES
if("${PCRECPP_FOUND}")
target_link_libraries(fileseq_shared ${PCRECPP_LIBRARIES})
target_link_libraries(fileseq_static ${PCRECPP_LIBRARIES})
endif()
endif()

# For providing standard install location vars.
include(GNUInstallDirs)

# Install public headers.
file(GLOB PUBLIC_HEADERS *.h)
install(
FILES ${PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fileseq
)

# Install libraries.
install(
TARGETS fileseq_shared fileseq_static
DESTINATION
EXPORT ${CMAKE_PROJECT_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# Produce a target import script for ease of importing into other CMake projects.
install(
EXPORT ${CMAKE_PROJECT_NAME}-targets
FILE ${CMAKE_PROJECT_NAME}Targets.cmake
NAMESPACE ${CMAKE_PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake
)

# Configure & install <Project>Config.cmake (which includes fileseqTargets.cmake)
set(OUTPUT_CONFIG ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake)
configure_file(cmake/Config.cmake.in ${OUTPUT_CONFIG} @ONLY)
install(
FILES ${OUTPUT_CONFIG}
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
6 changes: 6 additions & 0 deletions cpp/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
get_filename_component(@CMAKE_PROJECT_NAME@_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

# Include the targets if the shared library target is not defined.
if(NOT TARGET @CMAKE_PROJECT_NAME@::@CMAKE_PROJECT_NAME@_shared)
include("${@CMAKE_PROJECT_NAME@_CMAKE_DIR}/cmake/@[email protected]")
endif()

0 comments on commit a7e9ae5

Please sign in to comment.