From 63b95a52bc58f7dc287c843c694d41c8ee94e887 Mon Sep 17 00:00:00 2001 From: Arne Naegel Date: Mon, 13 Nov 2023 14:22:46 +0100 Subject: [PATCH] Adding option for externals/autodiff from https://github.com/autodiff/autodiff/ --- cmake/ug/autodiff.cmake | 79 +++++++++++++++++++++++++++++++++++++++++ cmake/ug_includes.cmake | 6 +++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 cmake/ug/autodiff.cmake diff --git a/cmake/ug/autodiff.cmake b/cmake/ug/autodiff.cmake new file mode 100644 index 000000000..579626471 --- /dev/null +++ b/cmake/ug/autodiff.cmake @@ -0,0 +1,79 @@ +# Copyright (c) 2020: G-CSC, Goethe University Frankfurt +# Author: Arne Naegel +# +# This file is part of UG4. +# +# UG4 is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License version 3 (as published by the +# Free Software Foundation) with the following additional attribution +# requirements (according to LGPL/GPL v3 §7): +# +# (1) The following notice must be displayed in the Appropriate Legal Notices +# of covered and combined works: "Based on UG4 (www.ug4.org/license)". +# +# (2) The following notice must be displayed at a prominent place in the +# terminal output of covered works: "Based on UG4 (www.ug4.org/license)". +# +# (3) The following bibliography is recommended for citation and must be +# preserved in all covered files: +# "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively +# parallel geometric multigrid solver on hierarchically distributed grids. +# Computing and visualization in science 16, 4 (2013), 151-164" +# "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel +# flexible software system for simulating pde based models on high performance +# computers. Computing and visualization in science 16, 4 (2013), 165-179" +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. + +# included from ug_includes.cmake + + + +# Set Autodiff include path +if(USE_AUTODIFF) + # This sections adds autodiff to the include path. + # Note: Autodiff requires C++17-compliant compilers + + IF (EXTERNAL_AUTODIFF) # Automatic + FIND_PACKAGE(autodiff CONFIG REQUIRED) + else (EXTERNAL_AUTODIFF)# Builtin + SET(autodiff_DIR ${UG_ROOT_CMAKE_PATH}/../../externals/AutoDiffForUG4/autodiff) + ENDIF(EXTERNAL_AUTODIFF) + + MESSAGE(STATUS "Info: Using Autodiff from ${autodiff_DIR}") + MESSAGE(STATUS "Info: ... compiling plugins will require at least C++17.") + + # These are the important lines... + include_directories(${autodiff_DIR}) + add_definitions(-DUG_USE_AUTODIFF) + + + # As a next step, update the submodule. + find_package(Git QUIET) + if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + # Update submodules as needed + option(GIT_SUBMODULE "Check submodules during build" ON) + if(GIT_SUBMODULE) + message(STATUS "Submodule update:${GIT_EXECUTABLE} ${autodiff_DIR}/..") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY "${autodiff_DIR}/.." + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() + endif() + + if(NOT EXISTS "${autodiff_DIR}/CMakeLists.txt") + message(ERROR "The submodules in ${autodiff_DIR} were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") + endif() + + +else(USE_AUTODIFF) + set(USE_AUTODIFF OFF) +endif(USE_AUTODIFF) + + diff --git a/cmake/ug_includes.cmake b/cmake/ug_includes.cmake index c4c4ba57f..f4e030fd5 100644 --- a/cmake/ug_includes.cmake +++ b/cmake/ug_includes.cmake @@ -190,6 +190,7 @@ else(APPLE) option(USE_LUA2C "Use LUA2C" OFF) endif(APPLE) option(USE_LUAJIT "Use LUA just in time compiler" OFF) +option(USE_AUTODIFF "Use Autodiff" OFF) option(USE_PYBIND11 "Use PYBIND11" OFF) option(USE_JSON "Use JSON" OFF) option(USE_XEUS "Use XEUS" OFF) @@ -280,6 +281,7 @@ message(STATUS "Info: HLIBPRO: ${HLIBPRO}") message(STATUS "Info: USE_JSON: ${USE_JSON} (options are: ON, OFF)") message(STATUS "Info: USE_XEUS: ${USE_XEUS} (options are: ON, OFF)") message(STATUS "Info: USE_PYBIND11: ${USE_PYBIND11} (options are: ON, OFF)") +message(STATUS "Info: USE_AUTODIFF: ${USE_AUTODIFF} (options are: ON, OFF)") message(STATUS "") message(STATUS "Info: C Compiler: ${CMAKE_C_COMPILER} (ID: ${CMAKE_C_COMPILER_ID})") message(STATUS "Info: C++ Compiler: ${CMAKE_CXX_COMPILER} (ID: ${CMAKE_CXX_COMPILER_ID})") @@ -436,8 +438,10 @@ include(${UG_ROOT_CMAKE_PATH}/ug/lua2c.cmake) include(${UG_ROOT_CMAKE_PATH}/ug/luajit.cmake) # JSON include(${UG_ROOT_CMAKE_PATH}/ug/json.cmake) -# XEUS +# Pybind11 include(${UG_ROOT_CMAKE_PATH}/ug/pybind11.cmake) +# Autodiff +include(${UG_ROOT_CMAKE_PATH}/ug/autodiff.cmake) # XEUS include(${UG_ROOT_CMAKE_PATH}/ug/xeus.cmake)