optimize cmake scripts for subproject use

(cherry picked from commit 19cacd3ecb9dab73c2dd7bc39d9193e06ba92bdd)
This commit is contained in:
Fabian Keßler 2021-10-24 21:00:11 +02:00 committed by Antonio Sanchez
parent 75ebef26b6
commit d0bfdc1658
3 changed files with 45 additions and 35 deletions

View File

@ -3,6 +3,16 @@ cmake_minimum_required(VERSION 3.5.0)
project(Eigen3) project(Eigen3)
# Remove this block after bumping CMake to v3.21.0
# PROJECT_IS_TOP_LEVEL is defined then by default
if(CMAKE_VERSION VERSION_LESS 3.21.0)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(PROJECT_IS_TOP_LEVEL TRUE)
else()
set(PROJECT_IS_TOP_LEVEL FALSE)
endif()
endif()
# guard against in-source builds # guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
@ -127,13 +137,11 @@ if(NOT STANDARD_MATH_LIBRARY_FOUND)
"Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.") "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
else() else()
if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}") set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
else() else()
set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}") set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
endif() endif()
endif() endif()
if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
@ -504,8 +512,9 @@ if(EIGEN_BUILD_DOC)
endif() endif()
option(BUILD_TESTING "Enable creation of Eigen tests." ON) cmake_dependent_option(BUILD_TESTING "Enable creation of tests." ON "PROJECT_IS_TOP_LEVEL" OFF)
if(BUILD_TESTING) option(EIGEN_BUILD_TESTING "Enable creation of Eigen tests." ${BUILD_TESTING})
if(EIGEN_BUILD_TESTING)
include(EigenConfigureTesting) include(EigenConfigureTesting)
if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
@ -576,7 +585,7 @@ endif()
configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY) configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
if(BUILD_TESTING) if(EIGEN_BUILD_TESTING)
ei_testing_print_summary() ei_testing_print_summary()
endif() endif()
@ -584,6 +593,7 @@ message(STATUS "")
message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}") message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
message(STATUS "") message(STATUS "")
if(PROJECT_IS_TOP_LEVEL)
string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower) string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
if(cmake_generator_tolower MATCHES "makefile") if(cmake_generator_tolower MATCHES "makefile")
message(STATUS "Available targets (use: make TARGET):") message(STATUS "Available targets (use: make TARGET):")
@ -603,7 +613,7 @@ message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourprefix")
message(STATUS " | Or:") message(STATUS " | Or:")
message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir") message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir")
message(STATUS "doc | Generate the API documentation, requires Doxygen & LaTeX") message(STATUS "doc | Generate the API documentation, requires Doxygen & LaTeX")
if(BUILD_TESTING) if(EIGEN_BUILD_TESTING)
message(STATUS "check | Build and run the unit-tests. Read this page:") message(STATUS "check | Build and run the unit-tests. Read this page:")
message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests") message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
endif() endif()
@ -611,7 +621,7 @@ message(STATUS "blas | Build BLAS library (not the same thing as Eigen)")
message(STATUS "uninstall| Remove files installed by the install target") message(STATUS "uninstall| Remove files installed by the install target")
message(STATUS "---------+--------------------------------------------------------------") message(STATUS "---------+--------------------------------------------------------------")
message(STATUS "") message(STATUS "")
endif()
set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} ) set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} )
set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} ) set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} )

View File

@ -51,7 +51,7 @@ endforeach()
if(EIGEN_Fortran_COMPILER_WORKS) if(EIGEN_Fortran_COMPILER_WORKS)
if(BUILD_TESTING) if(EIGEN_BUILD_TESTING)
if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
add_subdirectory(testing) # can't do EXCLUDE_FROM_ALL here, breaks CTest add_subdirectory(testing) # can't do EXCLUDE_FROM_ALL here, breaks CTest
else() else()

View File

@ -2,7 +2,7 @@ add_subdirectory(Eigen)
if(EIGEN_BUILD_DOC) if(EIGEN_BUILD_DOC)
add_subdirectory(doc EXCLUDE_FROM_ALL) add_subdirectory(doc EXCLUDE_FROM_ALL)
endif() endif()
if(BUILD_TESTING) if(EIGEN_BUILD_TESTING)
if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
else() else()