Skip to content

Commit

Permalink
Added CMake Target Export to the Installation Step for easy Integrati…
Browse files Browse the repository at this point in the history
…on of BGSLibrary in user projects. (#171)

usage:
cmake_minimum_required(VERSION 3.5)
find_package(BGSLibrary 3.0.0 REQUIRED)
add_executable(BackgroundSubtractionTester main.cpp)
target_link_libraries(BackgroundSubtractionTester BGSLibrary::BGSLibrary)

Co-authored-by: IVI\ihrke <stephan.ihrke@ivi.fraunhofer.de>
  • Loading branch information
SIhrke and IVI\ihrke authored Jul 20, 2022
1 parent b477da6 commit 6eaeff8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
40 changes: 39 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.1)

project(bgslibrary)
project(bgslibrary VERSION 3.0.0)

include(CheckCXXCompilerFlag)

Expand Down Expand Up @@ -296,14 +296,52 @@ if(UNIX AND BGS_PYTHON_SUPPORT)
endif()

if(NOT BGS_PYTHON_ONLY)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/BGSLibrary)
target_include_directories(bgslibrary_core
PUBLIC
$<INSTALL_INTERFACE:include>)


install(TARGETS bgslibrary_core
bgslibrary
EXPORT bgslibrary_core-targets
RUNTIME DESTINATION bin COMPONENT app
LIBRARY DESTINATION lib COMPONENT runtime
ARCHIVE DESTINATION lib COMPONENT runtime
#PUBLIC_HEADER DESTINATION include/bgslibrary COMPONENT dev
FRAMEWORK DESTINATION "/Library/Frameworks"
)
set_target_properties(bgslibrary_core PROPERTIES EXPORT_NAME BGSLibrary)

install(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT bgslibrary_core-targets
FILE
BGSLibraryTargets.cmake
NAMESPACE
BGSLibrary::
DESTINATION
${INSTALL_CONFIGDIR}
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/BGSLibraryConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake-modules/BGSLibraryConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/BGSLibraryConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

install(FILES
${CMAKE_CURRENT_LIST_DIR}/cmake-modules/FindOpenCV.cmake
${CMAKE_CURRENT_BINARY_DIR}/BGSLibraryConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/BGSLibraryConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)

if(UNIX)
# to avoid: error while loading shared libraries: libbgslibrary_core.so
Expand Down
13 changes: 13 additions & 0 deletions cmake-modules/BGSLibraryConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
get_filename_component(BGSLibrary_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(CMakeFindDependencyMacro)

list(APPEND CMAKE_MODULE_PATH ${BGSLibrary_CMAKE_DIR})

find_package(OpenCV 2.3.1 REQUIRED )
list(REMOVE_AT CMAKE_MODULE_PATH -1)

if(NOT TARGET BGSLibrary::BGSLibrary)
include("${BGSLibrary_CMAKE_DIR}/BGSLibraryTargets.cmake")
endif()

set(BGSLibrary_LIBRARIES BGSLibrary::BGSLibrary)

0 comments on commit 6eaeff8

Please sign in to comment.