Skip to content
Snippets Groups Projects
Commit 6993dd94 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Allow nanoflann and alglib to be external packages

parent feda220f
No related branches found
No related tags found
1 merge request!2Allow nanoflann and alglib to be external packages
...@@ -23,9 +23,11 @@ include(FeatureSummary) ...@@ -23,9 +23,11 @@ include(FeatureSummary)
dune_project() dune_project()
option(ENABLE_NANOFLANN "Use KDTree search tree from nanoflann." ON) option(ENABLE_NANOFLANN "Use KDTree search tree from nanoflann." ON)
option(DOWNLOAD_NANOFLANN "Download and build nanoflann library." OFF)
add_feature_info(ENABLE_NANOFLANN ENABLE_NANOFLANN "Use KDTree search tree from nanoflann.") add_feature_info(ENABLE_NANOFLANN ENABLE_NANOFLANN "Use KDTree search tree from nanoflann.")
option(ENABLE_ALGLIB "Use ALGLIB to implement the LM constrained least-squares solver." ON) option(ENABLE_ALGLIB "Use ALGLIB to implement the LM constrained least-squares solver." ON)
option(DOWNLOAD_ALGLIB "Download and build ALGLIB library." OFF)
add_feature_info(ENABLE_ALGLIB ENABLE_ALGLIB "Use ALGLIB to implement the LM constrained least-squares solver.") add_feature_info(ENABLE_ALGLIB ENABLE_ALGLIB "Use ALGLIB to implement the LM constrained least-squares solver.")
# provide external packages # provide external packages
...@@ -59,5 +61,8 @@ add_subdirectory(src) ...@@ -59,5 +61,8 @@ add_subdirectory(src)
add_subdirectory(dune) add_subdirectory(dune)
add_subdirectory(doc) add_subdirectory(doc)
# write contents into DUNE_CUSTOM_PKG_CONFIG_SECTION
string(JOIN "\n" DUNE_CUSTOM_PKG_CONFIG_SECTION ${DUNE_MESHDIST_PACKAGE_DEPENDENCIES})
# finalize the dune project, e.g. generating config.h etc. # finalize the dune project, e.g. generating config.h etc.
finalize_dune_project() finalize_dune_project()
include(FetchContent) include(FetchContent)
set(_find_dependencies)
if(ENABLE_NANOFLANN) if(ENABLE_NANOFLANN)
if(NOT nanoflann_SOURCE_DIR) if(DOWNLOAD_NANOFLANN)
set(NANOFLANN_BUILD_EXAMPLES OFF CACHE BOOL "Do not build examples for nanoflann" FORCE) set(NANOFLANN_BUILD_EXAMPLES OFF CACHE BOOL "Do not build examples for nanoflann" FORCE)
set(NANOFLANN_BUILD_TESTS OFF CACHE BOOL "Do not build tests for nanoflann" FORCE) set(NANOFLANN_BUILD_TESTS OFF CACHE BOOL "Do not build tests for nanoflann" FORCE)
FetchContent_Declare(nanoflann # name of the content FetchContent_Declare(nanoflann # name of the content
...@@ -12,22 +13,25 @@ if(ENABLE_NANOFLANN) ...@@ -12,22 +13,25 @@ if(ENABLE_NANOFLANN)
if(NOT nanoflann_POPULATED) if(NOT nanoflann_POPULATED)
FetchContent_Populate(nanoflann) FetchContent_Populate(nanoflann)
endif() endif()
endif()
file(GLOB NANOFLANN_HEADERS CONFIGURE_DEPENDS "${nanoflann_SOURCE_DIR}/include/*.hpp") file(GLOB NANOFLANN_HEADERS CONFIGURE_DEPENDS "${nanoflann_SOURCE_DIR}/include/*.hpp")
# Create a library from the source files # Create a library from the source files
dune_add_library(nanoflann INTERFACE dune_add_library(nanoflann INTERFACE
EXPORT_NAME nanoflann NAMESPACE nanoflann::) EXPORT_NAME nanoflann NAMESPACE nanoflann::)
target_include_directories(nanoflann INTERFACE target_include_directories(nanoflann INTERFACE
$<BUILD_INTERFACE:${nanoflann_SOURCE_DIR}/include> $<BUILD_INTERFACE:${nanoflann_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/nanoflann>) $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/nanoflann>)
install(FILES ${NANOFLANN_HEADERS} install(FILES ${NANOFLANN_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nanoflann" ) DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nanoflann" )
else()
find_package(nanoflann 1.6 REQUIRED)
list(APPEND _find_dependencies "find_dependency(nanoflann 1.6)")
endif()
endif() endif()
if(ENABLE_ALGLIB) if(ENABLE_ALGLIB)
if(NOT alglib_SOURCE_DIR) if(DOWNLOAD_ALGLIB)
FetchContent_Declare(alglib FetchContent_Declare(alglib
URL https://www.alglib.net/translator/re/alglib-4.03.0.cpp.gpl.tgz URL https://www.alglib.net/translator/re/alglib-4.03.0.cpp.gpl.tgz
DOWNLOAD_EXTRACT_TIMESTAMP TRUE DOWNLOAD_EXTRACT_TIMESTAMP TRUE
...@@ -35,17 +39,23 @@ if(ENABLE_ALGLIB) ...@@ -35,17 +39,23 @@ if(ENABLE_ALGLIB)
${CMAKE_COMMAND} -E create_symlink <SOURCE_DIR>/src <SOURCE_DIR>/alglib ${CMAKE_COMMAND} -E create_symlink <SOURCE_DIR>/src <SOURCE_DIR>/alglib
) )
FetchContent_MakeAvailable(alglib) FetchContent_MakeAvailable(alglib)
file(GLOB ALGLIB_HEADERS CONFIGURE_DEPENDS "${alglib_SOURCE_DIR}/src/*.hpp")
file(GLOB ALGLIB_SOURCES CONFIGURE_DEPENDS "${alglib_SOURCE_DIR}/src/*.cpp")
# Create a library from the source files
dune_add_library(alglib SOURCES ${ALGLIB_SOURCES}
EXPORT_NAME alglib NAMESPACE alglib::)
target_include_directories(alglib PUBLIC
$<BUILD_INTERFACE:${alglib_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(FILES ${ALGLIB_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/alglib" )
else()
find_package(alglib 4.0 REQUIRED)
list(APPEND _find_dependencies "find_dependency(alglib 4.0)")
endif() endif()
endif()
file(GLOB ALGLIB_HEADERS CONFIGURE_DEPENDS "${alglib_SOURCE_DIR}/src/*.hpp") set(DUNE_MESHDIST_PACKAGE_DEPENDENCIES "${_find_dependencies}" PARENT_SCOPE)
file(GLOB ALGLIB_SOURCES CONFIGURE_DEPENDS "${alglib_SOURCE_DIR}/src/*.cpp") \ No newline at end of file
# Create a library from the source files
dune_add_library(alglib SOURCES ${ALGLIB_SOURCES}
EXPORT_NAME alglib NAMESPACE alglib::)
target_include_directories(alglib PUBLIC
$<BUILD_INTERFACE:${alglib_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(FILES ${ALGLIB_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/alglib" )
endif()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment