Skip to content

Conversation

@willat343
Copy link
Contributor

Scenario this addresses:

  • enables specific versions of Eigen3 and manif to be used in a downstream package via CMake FetchContent (eigen already supports this)

How the code changes:

  • Before finding Eigen3, we check first if the target Eigen3::Eigen is already defined. Thus if the downstream target includes a specific version of eigen and the target is available, manif will use this target instead of finding Eigen itself (which may be the system install for example).
  • We add the MANIF::manif alias to the library, so that if manif is made available via FetchContent (but not installed), it can be linked to with MANIF::manif, consistent and not conflicting with the install/export NAMESPACE.

Example fo downstream usage (providing Eigen3::Eigen and with this PR MANIF::manif targets to link to):

option(USE_SYSTEM_Eigen3 "Use system install of Eigen3" OFF)
option(USE_SYSTEM_manif "Use system install of manif" OFF)

if (NOT TARGET Eigen3::Eigen)
    set(EIGEN3_VERSION "3.3.7")
    if (${USE_SYSTEM_Eigen3})
        find_package(Eigen3 ${EIGEN3_VERSION} REQUIRED)
        message(STATUS "Found Eigen3 at ${Eigen3_DIR} with version ${Eigen3_VERSION}")
    else()
        FetchContent_Declare(
            eigen
            GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
            GIT_TAG ${EIGEN3_VERSION}
        )
        FetchContent_MakeAvailable(eigen)
        message(STATUS "Fetched eigen to ${eigen_SOURCE_DIR} with version ${EIGEN3_VERSION}")
    endif()
endif()

if (NOT TARGET MANIF::manif)
    set(MANIF_VERSION "0.0.6") # Assuming this PR makes it into the next release
    if (${USE_SYSTEM_manif})
        find_package(manif ${MANIF_VERSION} REQUIRED)
        message(STATUS "Found manif at ${manif_DIR} with version ${manif_VERSION}")
    else()
        FetchContent_Declare(
            manif
            GIT_REPOSITORY https://github.com/artivis/manif.git
            GIT_TAG ${MANIF_VERSION}
        )
        FetchContent_MakeAvailable(manif)
        message(STATUS "Fetched manif to ${manif_SOURCE_DIR} with version ${MANIF_VERSION}")
    endif()
endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant