'Check Eigen version in cmake with header only

I want to use Eigen in one of my projects.

The user directly decides to turn Eigen ON/OFF and configures the path to the includes. So far, CMakeLists.txt looks like:

set(EIGEN_MODULE "OFF" CACHE BOOL "Enabled EIGEN MODULE ?")
if (EIGEN_MODULE)
        include_directories(${EIGEN_INCLUDE_DIR})
        set(EIGEN_INCLUDE_DIR /usr/local CACHE PATH "eigen include dir")
        if(NOT EXISTS ${EIGEN_INCLUDE_DIR})
            message(FATAL_ERROR "Bad eigen include dir")
        endif()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_MODULE")  
        include_directories(${EIGEN_INCLUDE_DIR})
endif(EIGEN_MODULE)

However, I don't know how to check the version of Eigen (I need to ensure 3.4.0 at least), knowing that I want to avoid find_package (Eigen3 3.4 REQUIRED NO_MODULE) which would require the user to compile Eigen.

Is there any way to do that ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source