Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • v2.0.0 protected
  • v1.9.0 protected
  • v1.8.0 protected
  • v1.7.0 protected
  • v1.6.0 protected
  • v1.5.2 protected
  • v1.5.1 protected
  • v1.5.0 protected
  • v1.4.1 protected
  • v1.4 protected
  • v1.4.0 protected
  • v1.3 protected
  • v1.3.0 protected
  • v1.2 protected
  • v1.2.0 protected
  • v1.1 protected
  • v1.1.0 protected
  • v1.0 protected
  • v1.0.0 protected
20 results

loadstaticsharedtargets

  • Clone with SSH
  • Clone with HTTPS
  • user avatar
    Tim Haase authored
    30f9247a
    History

    LoadStaticSharedTargets.cmake

    This project contains a CMake macro for loading static or shared exported library targets in a CMake package config file. Static or shared targets can be explicitly (via COMPONENTS) or implicitly (via BUILD_SHARED_LIBS) imported with the find_package() command.

    Usage

    In your cmake project, do the following:

    include(FetchContent)
    
    FetchContent_Declare(
        LoadStaticSharedTargets
        GIT_REPOSITORY "https://github.com/lepus2589/LoadStaticSharedTargets.git"
        GIT_TAG v1.0
        GIT_SHALLOW True
    )
    FetchContent_MakeAvailable(LoadStaticSharedTargets)
    FetchContent_GetProperties(
      LoadStaticSharedTargets
      SOURCE_DIR LoadStaticSharedTargets_SOURCE_DIR
      POPULATED LoadStaticSharedTargets_POPULATED
    )
    
    install(
        FILES
        "${LoadStaticSharedTargets_SOURCE_DIR}/src/cmake/LoadStaticSharedTargets.cmake"
        DESTINATION "${YourProject_INSTALL_CMAKEDIR}"
    )

    In your projects package config CMake file, you can now use the macro like this:

    include("${CMAKE_CURRENT_LIST_DIR}/LoadStaticSharedTargets.cmake")
    
    load_static_shared_targets(
        STATIC_TARGETS
        "${CMAKE_CURRENT_LIST_DIR}/YourProject_Targets-static.cmake"
        SHARED_TARGETS
        "${CMAKE_CURRENT_LIST_DIR}/YourProject_Targets-shared.cmake"
    )

    Further Reading

    The idea for this code was taken from @alexreinking's blog post: Building a Dual Shared and Static Library with CMake and the associated example repository.

    Information on project structure and usage of CMake library packages using this approach in other projects can be found there.