diff --git a/.gitignore b/.gitignore index b665018b4..a3fea6cfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,16 @@ build* .dir-locals.el TAGS third-party/blackdynamite/ +third-party/pybind11 +third-party/google-test third-party/cpp-array/ *~ release .*.swp *.tar.gz *.tgz *.tbz *.tar.bz2 .idea __pycache__ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ce25d7b56..383ae3ecd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,187 +1,187 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # @author Nicolas Richart # # @date creation: Mon Jun 14 2010 # @date last modification: Fri Jan 22 2016 # # @brief main configuration file # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu 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. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # # @section DESCRIPTION #------------------------------------------------------------------------------- # _ _ # | | | | # __ _| | ____ _ _ __ | |_ _ _ # / _` | |/ / _` | '_ \| __| | | | # | (_| | < (_| | | | | |_| |_| | # \__,_|_|\_\__,_|_| |_|\__|\__,_| # #=============================================================================== #=============================================================================== # CMake Project #=============================================================================== cmake_minimum_required(VERSION 3.1.3) # add this options before PROJECT keyword set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) project(Akantu) enable_language(CXX) #=============================================================================== # Misc. config for cmake #=============================================================================== set(AKANTU_CMAKE_DIR "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries.") mark_as_advanced(BUILD_SHARED_LIBS) if(NOT AKANTU_TARGETS_EXPORT) set(AKANTU_TARGETS_EXPORT AkantuLibraryDepends) endif() include(CMakeVersionGenerator) include(CMakePackagesSystem) include(CMakeFlagsHandling) include(AkantuPackagesSystem) include(AkantuMacros) include(AkantuCleaning) #cmake_activate_debug_message() #=============================================================================== # Version Number #=============================================================================== # AKANTU version number. An even minor number corresponds to releases. set(AKANTU_MAJOR_VERSION 3) set(AKANTU_MINOR_VERSION 0) set(AKANTU_PATCH_VERSION 0) define_project_version() #=============================================================================== # Options #=============================================================================== # Debug set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -DAKANTU_NDEBUG" CACHE STRING "Flags used by the compiler during release builds" FORCE) #add_flags(cxx "-Wall -Wextra -pedantic -Werror") if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_flags(cxx "-Wall -Wextra -pedantic") # -Weffc++ else() add_flags(cxx "-Wall") endif() option(AKANTU_EXAMPLES "Activate examples" OFF) option(AKANTU_TESTS "Activate tests" OFF) include(AkantuExtraCompilationProfiles) #=============================================================================== # Dependencies #=============================================================================== declare_akantu_types() package_list_packages(${PROJECT_SOURCE_DIR}/packages EXTRA_PACKAGES_FOLDER ${PROJECT_SOURCE_DIR}/extra_packages NO_AUTO_COMPILE_FLAGS) ## meta option \todo better way to do it when multiple package give enable the ## same feature if(AKANTU_SCOTCH) set(AKANTU_PARTITIONER ON) else() set(AKANTU_PARTITIONER OFF) endif() if(AKANTU_MUMPS) set(AKANTU_SOLVER ON) else() set(AKANTU_SOLVER OFF) endif() #=============================================================================== # Akantu library #=============================================================================== add_subdirectory(src) #=============================================================================== # Documentation #=============================================================================== if(AKANTU_DOCUMENTATION_DOXYGEN OR AKANTU_DOCUMENTATION_MANUAL) add_subdirectory(doc) else() set(AKANTU_DOC_EXCLUDE_FILES "${PROJECT_SOURCE_DIR}/doc/manual" CACHE INTERNAL "") endif() #=============================================================================== # Examples and tests #=============================================================================== include(AkantuTestsMacros) include(AkantuExampleMacros) if(AKANTU_TESTS) option(AKANTU_BUILD_ALL_TESTS "Build all tests" ON) find_package(GMSH REQUIRED) - package_is_activated(pybind11 _pybind11_act) - if(_pybind11_act) - find_package(pybind11 CONFIG REQUIRED QUIET) # to get the pybind11_add_module macro - endif() + # package_is_activated(pybind11 _pybind11_act) + # if(_pybind11_act) + # find_package(pybind11 CONFIG REQUIRED QUIET) # to get the pybind11_add_module macro + # endif() endif() if(AKANTU_EXAMPLES) find_package(GMSH REQUIRED) add_subdirectory(examples) endif() # tests add_test_tree(test) #=============================================================================== # Python interface #=============================================================================== package_is_activated(python_interface _python_act) if(_python_act) if(IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}") set(AKANTU_PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) else() set(AKANTU_PYTHON_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PREFIX}") endif() add_subdirectory(python) endif() #=============================================================================== # Install and Packaging #=============================================================================== include(AkantuInstall) option(AKANTU_DISABLE_CPACK "This option commands the generation of extra info for the \"make package\" target" ON) mark_as_advanced(AKANTU_DISABLE_CPACK) if(NOT AKANTU_DISABLE_CPACK) include(AkantuCPack) endif() diff --git a/cmake/AkantuMacros.cmake b/cmake/AkantuMacros.cmake index 30b99e524..bcb92d031 100644 --- a/cmake/AkantuMacros.cmake +++ b/cmake/AkantuMacros.cmake @@ -1,293 +1,240 @@ #=============================================================================== # @file AkantuMacros.cmake # # @author Guillaume Anciaux # @author Nicolas Richart # # @date creation: Fri Oct 22 2010 # @date last modification: Tue Jan 19 2016 # # @brief Set of macros used by akantu cmake files # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu 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. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== #=============================================================================== function(set_third_party_shared_libirary_name _var _lib) set(${_var} ${PROJECT_BINARY_DIR}/third-party/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${_lib}${CMAKE_SHARED_LIBRARY_SUFFIX} CACHE FILEPATH "" FORCE) endfunction() # ============================================================================== function(get_target_list_of_associated_files tgt files) if(TARGET ${tgt}) get_target_property(_type ${tgt} TYPE) else() set(_type ${tgt}-NOTFOUND) endif() if(_type STREQUAL "SHARED_LIBRARY" OR _type STREQUAL "STATIC_LIBRARY" OR _type STREQUAL "MODULE_LIBRARY" OR _type STREQUAL "EXECUTABLE") get_target_property(_srcs ${tgt} SOURCES) set(_dep_ressources) foreach(_file ${_srcs}) list(APPEND _dep_ressources ${CMAKE_CURRENT_SOURCE_DIR}/${_file}) endforeach() elseif(_type) get_target_property(_dep_ressources ${tgt} RESSOURCES) endif() set(${files} ${_dep_ressources} PARENT_SCOPE) endfunction() #=============================================================================== # Generate the list of currently loaded materials function(generate_material_list) message(STATUS "Determining the list of recognized materials...") package_get_all_include_directories( AKANTU_LIBRARY_INCLUDE_DIRS ) package_get_all_external_informations( AKANTU_EXTERNAL_INCLUDE_DIR AKANTU_EXTERNAL_LIBRARIES ) set(_include_dirs ${AKANTU_INCLUDE_DIRS} ${AKANTU_EXTERNAL_INCLUDE_DIR}) try_run(_material_list_run _material_list_compile ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/material_lister.cc CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${_include_dirs}" "-DCMAKE_CXX_STANDARD=14" COMPILE_DEFINITIONS "-DAKANTU_CMAKE_LIST_MATERIALS" COMPILE_OUTPUT_VARIABLE _compile_results RUN_OUTPUT_VARIABLE _result_material_list) if(_material_list_compile AND "${_material_list_run}" EQUAL 0) message(STATUS "Materials included in Akantu:") string(REPLACE "\n" ";" _material_list "${_result_material_list}") foreach(_mat ${_material_list}) string(REPLACE ":" ";" _mat_key "${_mat}") list(GET _mat_key 0 _key) list(GET _mat_key 1 _class) list(LENGTH _mat_key _l) if("${_l}" GREATER 2) list(REMOVE_AT _mat_key 0 1) set(_opt " -- options: [") foreach(_o ${_mat_key}) set(_opt "${_opt} ${_o}") endforeach() set(_opt "${_opt} ]") else() set(_opt "") endif() message(STATUS " ${_class} -- key: ${_key}${_opt}") endforeach() else() message(STATUS "Could not determine the list of materials.") message("${_compile_results}") endif() endfunction() #=============================================================================== # Declare the options for the types and defines the approriate typedefs function(declare_akantu_types) set(AKANTU_TYPE_FLOAT "double (64bit)" CACHE STRING "Precision force floating point types") mark_as_advanced(AKANTU_TYPE_FLOAT) set_property(CACHE AKANTU_TYPE_FLOAT PROPERTY STRINGS "quadruple (128bit)" "double (64bit)" "float (32bit)" ) set(AKANTU_TYPE_INTEGER "int (32bit)" CACHE STRING "Size of the integer types") mark_as_advanced(AKANTU_TYPE_INTEGER) set_property(CACHE AKANTU_TYPE_INTEGER PROPERTY STRINGS "int (32bit)" "long int (64bit)" ) include(CheckTypeSize) # ---------------------------------------------------------------------------- # Floating point types # ---------------------------------------------------------------------------- if(AKANTU_TYPE_FLOAT STREQUAL "float (32bit)") set(AKANTU_FLOAT_TYPE "float" CACHE INTERNAL "") set(AKANTU_FLOAT_SIZE 4 CACHE INTERNAL "") elseif(AKANTU_TYPE_FLOAT STREQUAL "double (64bit)") set(AKANTU_FLOAT_TYPE "double" CACHE INTERNAL "") set(AKANTU_FLOAT_SIZE 8 CACHE INTERNAL "") elseif(AKANTU_TYPE_FLOAT STREQUAL "quadruple (128bit)") check_type_size("long double" LONG_DOUBLE) if(HAVE_LONG_DOUBLE) set(AKANTU_FLOAT_TYPE "long double" CACHE INTERNAL "") set(AKANTU_FLOAT_SIZE 16 CACHE INTERNAL "") message("This feature is not tested and will most probably not compile") else() message(FATAL_ERROR "The type long double is not defined on your system") endif() else() message(FATAL_ERROR "The float type is not defined") endif() include(CheckIncludeFileCXX) include(CheckCXXSourceCompiles) # ---------------------------------------------------------------------------- # Integer types # ---------------------------------------------------------------------------- check_include_file_cxx(cstdint HAVE_CSTDINT) if(NOT HAVE_CSTDINT) check_include_file_cxx(stdint.h HAVE_STDINT_H) if(HAVE_STDINT_H) list(APPEND _int_include stdint.h) endif() else() list(APPEND _int_include cstdint) endif() check_include_file_cxx(cstddef HAVE_CSTDDEF) if(NOT HAVE_CSTDINT) check_include_file_cxx(stddef.h HAVE_STDDEF_H) if(HAVE_STDINT_H) list(APPEND _int_include stddef.h) endif() else() list(APPEND _int_include cstddef) endif() if(AKANTU_TYPE_INTEGER STREQUAL "int (32bit)") set(AKANTU_INTEGER_SIZE 4 CACHE INTERNAL "") check_type_size("int" INT) if(INT EQUAL 4) set(AKANTU_SIGNED_INTEGER_TYPE "int" CACHE INTERNAL "") set(AKANTU_UNSIGNED_INTEGER_TYPE "unsigned int" CACHE INTERNAL "") else() check_type_size("int32_t" INT32_T LANGUAGE CXX) if(HAVE_INT32_T) set(AKANTU_SIGNED_INTEGER_TYPE "int32_t" CACHE INTERNAL "") set(AKANTU_UNSIGNED_INTEGER_TYPE "uint32_t" CACHE INTERNAL "") list(APPEND _extra_includes ${_int_include}) endif() endif() elseif(AKANTU_TYPE_INTEGER STREQUAL "long int (64bit)") set(AKANTU_INTEGER_SIZE 8 CACHE INTERNAL "") check_type_size("long int" LONG_INT) if(LONG_INT EQUAL 8) set(AKANTU_SIGNED_INTEGER_TYPE "long int" CACHE INTERNAL "") set(AKANTU_UNSIGNED_INTEGER_TYPE "unsigned long int" CACHE INTERNAL "") else() check_type_size("long long int" LONG_LONG_INT) if(HAVE_LONG_LONG_INT AND LONG_LONG_INT EQUAL 8) set(AKANTU_SIGNED_INTEGER_TYPE "long long int" CACHE INTERNAL "") set(AKANTU_UNSIGNED_INTEGER_TYPE "unsigned long long int" CACHE INTERNAL "") else() check_type_size("int64_t" INT64_T) if(HAVE_INT64_T) set(AKANTU_SIGNED_INTEGER_TYPE "int64_t" CACHE INTERNAL "") set(AKANTU_UNSIGNED_INTEGER_TYPE "uint64_t" CACHE INTERNAL "") list(APPEND _extra_includes ${_int_include}) endif() endif() endif() else() message(FATAL_ERROR "The integer type is not defined") endif() # ---------------------------------------------------------------------------- # includes # ---------------------------------------------------------------------------- foreach(_inc ${_extra_includes}) set(_incs "#include <${_inc}>\n${_incs}") endforeach() set(AKANTU_TYPES_EXTRA_INCLUDES ${_incs} CACHE INTERNAL "") endfunction() -#=============================================================================== -if(__CMAKE_PARSE_ARGUMENTS_INCLUDED) - return() -endif() -set(__CMAKE_PARSE_ARGUMENTS_INCLUDED TRUE) - -function(CMAKE_PARSE_ARGUMENTS prefix _optionNames _singleArgNames _multiArgNames) - # first set all result variables to empty/FALSE - foreach(arg_name ${_singleArgNames} ${_multiArgNames}) - set(${prefix}_${arg_name}) - endforeach(arg_name) - - foreach(option ${_optionNames}) - set(${prefix}_${option} FALSE) - endforeach(option) - - set(${prefix}_UNPARSED_ARGUMENTS) - - set(insideValues FALSE) - set(currentArgName) - - # now iterate over all arguments and fill the result variables - foreach(currentArg ${ARGN}) - list(FIND _optionNames "${currentArg}" optionIndex) # ... then this marks the end of the arguments belonging to this keyword - list(FIND _singleArgNames "${currentArg}" singleArgIndex) # ... then this marks the end of the arguments belonging to this keyword - list(FIND _multiArgNames "${currentArg}" multiArgIndex) # ... then this marks the end of the arguments belonging to this keyword - - if(${optionIndex} EQUAL -1 AND ${singleArgIndex} EQUAL -1 AND ${multiArgIndex} EQUAL -1) - if(insideValues) - if("${insideValues}" STREQUAL "SINGLE") - set(${prefix}_${currentArgName} ${currentArg}) - set(insideValues FALSE) - elseif("${insideValues}" STREQUAL "MULTI") - list(APPEND ${prefix}_${currentArgName} ${currentArg}) - endif() - else(insideValues) - list(APPEND ${prefix}_UNPARSED_ARGUMENTS ${currentArg}) - endif(insideValues) - else() - if(NOT ${optionIndex} EQUAL -1) - set(${prefix}_${currentArg} TRUE) - set(insideValues FALSE) - elseif(NOT ${singleArgIndex} EQUAL -1) - set(currentArgName ${currentArg}) - set(${prefix}_${currentArgName}) - set(insideValues "SINGLE") - elseif(NOT ${multiArgIndex} EQUAL -1) - set(currentArgName ${currentArg}) - set(${prefix}_${currentArgName}) - set(insideValues "MULTI") - endif() +function(mask_package_options prefix) + get_property(_list DIRECTORY PROPERTY VARIABLES) + foreach(_var ${_list}) + if("${_var}" MATCHES "^${prefix}.*") + mark_as_advanced(${_var}) endif() - - endforeach(currentArg) - - # propagate the result variables to the caller: - foreach(arg_name ${_singleArgNames} ${_multiArgNames} ${_optionNames}) - set(${prefix}_${arg_name} ${${prefix}_${arg_name}} PARENT_SCOPE) - endforeach(arg_name) - set(${prefix}_UNPARSED_ARGUMENTS ${${prefix}_UNPARSED_ARGUMENTS} PARENT_SCOPE) -endfunction(CMAKE_PARSE_ARGUMENTS _options _singleArgs _multiArgs) + endforeach() +endfunction() diff --git a/cmake/AkantuPackagesSystem.cmake b/cmake/AkantuPackagesSystem.cmake index e660ca720..f7d13d99f 100644 --- a/cmake/AkantuPackagesSystem.cmake +++ b/cmake/AkantuPackagesSystem.cmake @@ -1,354 +1,353 @@ #=============================================================================== # @file AkantuPackagesSystem.cmake # # @author Nicolas Richart # # @date creation: Sat Jul 18 2015 # @date last modification: Mon Jan 18 2016 # # @brief Addition to the PackageSystem specific for Akantu # # @section LICENSE # # Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory # (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu 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. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== #=============================================================================== # Element Types #=============================================================================== #------------------------------------------------------------------------------- function(package_declare_elements pkg) set(_options KIND ELEMENT_TYPES GEOMETRICAL_TYPES INTERPOLATION_TYPES GEOMETRICAL_SHAPES GAUSS_INTEGRATION_TYPES - INTERPOLATION_TYPES INTERPOLATION_KIND FE_ENGINE_LISTS ) cmake_parse_arguments(_opt_pkg "" "" "${_options}" ${ARGN}) foreach(_opt ${_options}) if(_opt_pkg_${_opt}) package_set_variable(ET_${_opt} ${pkg} ${_opt_pkg_${_opt}}) endif() endforeach() endfunction() #------------------------------------------------------------------------------- function(_transfer_list_to_enum types enum) if(${enum}) set(_enum_tmp ${${enum}}) else() unset(_enum_tmp) endif() foreach(_type ${${types}}) # defining the types for the enum if(DEFINED _enum_tmp) set(_enum_tmp "${_enum_tmp} ${_type},") else() set(_enum_tmp "${_type},") endif() endforeach() set(${enum} ${_enum_tmp} PARENT_SCOPE) endfunction() #------------------------------------------------------------------------------- function(_transfer_list_to_boost_seq types boost_seq) if(${boost_seq}) set(_boost_seq_tmp ${${boost_seq}}) endif() foreach(_type ${${types}}) if(DEFINED _boost_seq_tmp) set(_boost_seq_tmp "${_boost_seq_tmp}${_tabs}\\ (${_type})") else() set(_boost_seq_tmp " (${_type})") endif() string(LENGTH "${_type}" _length) if(_length LESS 13) set(_tabs "\t\t\t\t") elseif(_length LESS 28) set(_tabs "\t\t\t") else() set(_tabs "\t\t") endif() endforeach() set(${boost_seq} ${_boost_seq_tmp} PARENT_SCOPE) endfunction() #------------------------------------------------------------------------------- function(package_get_element_lists) package_get_all_activated_packages(_activated_list) set(_lists KIND ELEMENT_TYPES GEOMETRICAL_TYPES INTERPOLATION_TYPES GEOMETRICAL_SHAPES GAUSS_INTEGRATION_TYPES INTERPOLATION_TYPES INTERPOLATION_KIND FE_ENGINE_LISTS ) set(_element_kind "#define AKANTU_ELEMENT_KIND") set(_all_element_types "#define AKANTU_ALL_ELEMENT_TYPE\t") set(_inter_types_boost_seq "#define AKANTU_INTERPOLATION_TYPES\t\t") foreach(_pkg_name ${_activated_list}) foreach(_list ${_lists}) string(TOLOWER "${_list}" _l_list) _package_get_variable(ET_${_list} ${_pkg_name} _${_l_list}) _transfer_list_to_enum(_${_l_list} _${_l_list}_enum) endforeach() if(_interpolation_types) _transfer_list_to_boost_seq(_interpolation_types _inter_types_boost_seq) endif() if(_kind) string(TOUPPER "${_kind}" _u_kind) if(_element_types) set(_boosted_element_types "${_boosted_element_types} #define AKANTU_ek_${_kind}_ELEMENT_TYPE\t") _transfer_list_to_boost_seq(_element_types _boosted_element_types) set(_boosted_element_types "${_boosted_element_types}\n") # defininf the kinds variables set(_element_kinds "${_element_kinds} #define AKANTU_${_u_kind}_KIND\t(_ek_${_kind})") # defining the full list of element set(_all_element_types "${_all_element_types}\t\\ AKANTU_ek_${_kind}_ELEMENT_TYPE") endif() # defining the full list of kinds set(_element_kind "${_element_kind}${_kind_tabs}\t\t\\ AKANTU_${_u_kind}_KIND") set(_kind_tabs "\t") # defining the macros set(_boost_macros "${_boost_macros} #define AKANTU_BOOST_${_u_kind}_ELEMENT_SWITCH(macro) \\ AKANTU_BOOST_ELEMENT_SWITCH(macro, \\ AKANTU_ek_${_kind}_ELEMENT_TYPE) #define AKANTU_BOOST_${_u_kind}_ELEMENT_LIST(macro) \\ AKANTU_BOOST_APPLY_ON_LIST(macro, \\ AKANTU_ek_${_kind}_ELEMENT_TYPE) ") list(APPEND _aka_fe_lists ${_fe_engine_lists}) foreach(_fe_engine_list ${_fe_engine_lists}) if(NOT DEFINED _fe_engine_list_${_fe_engine_list}) string(TOUPPER "${_fe_engine_list}" _u_list) string(LENGTH "#define AKANTU_FE_ENGINE_LIST_${_u_list}" _length) math(EXPR _length "72 - ${_length}") set(_space "") while(_length GREATER 0) if(CMAKE_VERSION VERSION_GREATER 3.0) string(CONCAT _space "${_space}" " ") else() set(_space "${_space} ") endif() math(EXPR _length "${_length} - 1") endwhile() set(_fe_engine_list_${_fe_engine_list} "#define AKANTU_FE_ENGINE_LIST_${_u_list}${_space}\\ AKANTU_GENERATE_KIND_LIST((_ek_${_kind})") else() set(_fe_engine_list_${_fe_engine_list} "${_fe_engine_list_${_fe_engine_list}}\t\t\t\t\\ (_ek_${_kind})") endif() endforeach() endif() endforeach() if(_aka_fe_lists) list(REMOVE_DUPLICATES _aka_fe_lists) foreach(_fe_list ${_aka_fe_lists}) set(_aka_fe_defines "${_fe_engine_list_${_fe_list}})\n${_aka_fe_defines}") endforeach() endif() foreach(_list ${_lists}) string(TOLOWER "${_list}" _l_list) set(AKANTU_${_list}_ENUM ${_${_l_list}_enum} PARENT_SCOPE) endforeach() set(AKANTU_INTERPOLATION_TYPES_BOOST_SEQ ${_inter_types_boost_seq} PARENT_SCOPE) set(AKANTU_ELEMENT_TYPES_BOOST_SEQ ${_boosted_element_types} PARENT_SCOPE) set(AKANTU_ELEMENT_KINDS_BOOST_SEQ ${_element_kinds} PARENT_SCOPE) set(AKANTU_ELEMENT_KIND_BOOST_SEQ ${_element_kind} PARENT_SCOPE) set(AKANTU_ALL_ELEMENT_BOOST_SEQ ${_all_element_types} PARENT_SCOPE) set(AKANTU_ELEMENT_KINDS_BOOST_MACROS ${_boost_macros} PARENT_SCOPE) set(AKANTU_FE_ENGINE_LISTS ${_aka_fe_defines} PARENT_SCOPE) endfunction() #------------------------------------------------------------------------------- function(package_get_element_types pkg list) package_get_name(${pkg} _pkg_name) _package_get_variable(ET_ELEMENT_TYPES ${_pkg_name} _tmp_list) set(${list} ${_tmp_list} PARENT_SCOPE) endfunction() #=============================================================================== # Material specific #=============================================================================== #------------------------------------------------------------------------------- function(package_declare_material_infos pkg) cmake_parse_arguments(_opt_pkg "" "" "LIST;INCLUDE" ${ARGN}) package_set_variable(MATERIAL_LIST ${pkg} ${_opt_pkg_LIST}) package_set_variable(MATERIAL_INCLUDE ${pkg} ${_opt_pkg_INCLUDE}) endfunction() #------------------------------------------------------------------------------- function(package_get_all_material_includes includes) _package_get_variable_for_activated(MATERIAL_INCLUDE _includes) foreach(_mat_inc ${_includes}) if(DEFINED _mat_includes) set(_mat_includes "${_mat_includes}\n#include \"${_mat_inc}\"") else() set(_mat_includes "#include \"${_mat_inc}\"") endif() endforeach() set(${includes} ${_mat_includes} PARENT_SCOPE) endfunction() #------------------------------------------------------------------------------- function(package_get_all_material_lists lists) _package_get_variable_for_activated(MATERIAL_LIST _lists) foreach(_mat_list ${_lists}) if(DEFINED _mat_lists) set(_mat_lists "${_mat_lists}\n ${_mat_list}\t\t\t\\") else() set(_mat_lists " ${_mat_list}\t\t\t\\") endif() endforeach() set(${lists} ${_mat_lists} PARENT_SCOPE) endfunction() # ------------------------------------------------------------------------------ # Extra files to consider in source package generated by CPack # ------------------------------------------------------------------------------ function(package_declare_extra_files_to_package pkg) set(_types SOURCES MANUAL TESTS PROJECT) cmake_parse_arguments(_extra_files "" "" "${_types}" ${ARGN}) set(_files ${_extra_files_UNPARSED_ARGUMENTS}) package_get_sources_folder(${pkg} _folder_SOURCES) package_get_manual_folder(${pkg} _folder_MANUAL) package_get_tests_folder(${pkg} _folder_TESTS) set(_folder_PROJECT ${PROJECT_SOURCE_DIR}) foreach(_type ${_types}) if(_extra_files_${_type}) foreach(_file ${_extra_files_${_type}}) list(APPEND _files ${_folder_${_type}}/${_file}) if(NOT EXISTS ${_folder_${_type}}/${_file}) message(SEND_ERROR "The package ${pkg} tries to register the file ${_file} (as a ${_type} file). This file cannot be found.") endif() endforeach() endif() endforeach() package_set_variable(EXTRA_FILES ${pkg} ${_files}) endfunction() # ------------------------------------------------------------------------------ function(package_add_files_to_package) set(_files) foreach(_file ${ARGN}) list(APPEND _files ${PROJECT_SOURCE_DIR}/${_file}) endforeach() package_add_to_project_variable(EXTRA_FILES ${_files}) endfunction() function(package_get_files_for_package files) package_get_project_variable(EXTRA_FILES _tmp) set(${files} ${_tmp} PARENT_SCOPE) endfunction() package_add_files_to_package( .clang-format AUTHORS README VERSION COPYING COPYING.lesser CTestConfig.cmake cmake/akantu_environement.sh.in cmake/akantu_environement.csh.in cmake/akantu_install_environement.sh.in cmake/akantu_install_environement.csh.in cmake/Modules/CMakeFlagsHandling.cmake cmake/Modules/CMakePackagesSystem.cmake cmake/Modules/CMakePackagesSystemGlobalFunctions.cmake cmake/Modules/CMakePackagesSystemPrivateFunctions.cmake cmake/Modules/CMakeVersionGenerator.cmake cmake/Modules/PCHgcc.cmake cmake/AkantuBuildTreeSettings.cmake.in cmake/AkantuConfig.cmake.in cmake/AkantuConfigVersion.cmake.in cmake/AkantuCPack.cmake cmake/AkantuCPackMacros.cmake cmake/AkantuInstall.cmake cmake/AkantuMacros.cmake cmake/AkantuPackagesSystem.cmake cmake/AkantuUse.cmake cmake/AkantuSimulationMacros.cmake cmake/material_lister.cc cmake/Modules/FindGMSH.cmake ) diff --git a/packages/pybind11.cmake b/packages/pybind11.cmake index 3015c77eb..c1868b8ff 100644 --- a/packages/pybind11.cmake +++ b/packages/pybind11.cmake @@ -1,4 +1,12 @@ set(PYBIND11_PYTHON_VERSION 3) + package_declare(pybind11 EXTERNAL - EXTRA_PACKAGE_OPTIONS ARGS CONFIG LINK_LIBRARIES pybind11::embed PREFIX pybind11 - DESCRIPTION "Akantu's pybind11 interface") + EXTRA_PACKAGE_OPTIONS ARGS "2.2;CONFIG" LINK_LIBRARIES pybind11::embed PREFIX pybind11 + DESCRIPTION "Akantu's pybind11 interface" + SYSTEM OFF third-party/cmake/pybind11.cmake + ) + +package_add_third_party_script_variable(pybind11 + PYBIND11_VERSION "v2.2") +package_add_third_party_script_variable(pybind11 + PYBIND11_GIT "https://github.com/pybind/pybind11.git") diff --git a/test/test_fe_engine/CMakeLists.txt b/test/test_fe_engine/CMakeLists.txt index 90475bf34..1d81db580 100644 --- a/test/test_fe_engine/CMakeLists.txt +++ b/test/test_fe_engine/CMakeLists.txt @@ -1,121 +1,123 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # # @date creation: Fri Sep 03 2010 # @date last modification: Mon Dec 07 2015 # # @brief configuration for FEM tests # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu 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. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # # @section DESCRIPTION # #=============================================================================== #=============================================================================== function(register_fem_test operation type) set(_target test_${operation}${type}) register_test(${_target} SOURCES test_${operation}.cc FILES_TO_COPY ${type}.msh COMPILE_OPTIONS TYPE=${type} PACKAGE core ) endfunction() #=============================================================================== package_get_element_types(core _types) foreach(_type ${_types}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_type}.msh) list(APPEND _meshes ${_type}.msh) #register_fem_test(fe_engine_precomputation ${_type}) else() if(NOT ${_type} STREQUAL _point_1) message("The mesh ${_type}.msh is missing, the fe_engine test cannot be activated without it") endif() endif() endforeach() -register_test(test_fe_engine_precomupation_bernoulli_beam_2 PACKAGE core SOURCES test_fe_engine_precomputation_bernoulli_2.cc) +register_test(test_fe_engine_precomupation_bernoulli_beam_2 + PACKAGE structural_mechanics + SOURCES test_fe_engine_precomputation_bernoulli_2.cc) #add_mesh(test_fem_circle_1_mesh circle.geo 2 1 OUTPUT circle1.msh) #add_mesh(test_fem_circle_2_mesh circle.geo 2 2 OUTPUT circle2.msh) # Tests for class MeshData macro(register_typed_test test_name type value1 value2) set(target test_${test_name}_${type}) register_test(${target} SOURCES test_${test_name}.cc COMPILE_OPTIONS "TYPE=${type};VALUE1=${value1};VALUE2=${value2}" PACKAGE core ) endmacro() register_typed_test(mesh_data string \"5\" \"10\") register_typed_test(mesh_data UInt 5 10) add_mesh(test_boundary_msh cube.geo 3 1) add_mesh(test_boundary_msh_physical_names cube_physical_names.geo 3 1) register_test(test_mesh_boundary SOURCES test_mesh_boundary.cc DEPENDS test_boundary_msh test_boundary_msh_physical_names PACKAGE core) register_test(test_facet_element_mapping SOURCES test_facet_element_mapping.cc DEPENDS test_boundary_msh_physical_names PACKAGE core) pybind11_add_module(aka_test MODULE pybind11_akantu.cc) register_gtest_sources( SOURCES test_fe_engine_precomputation.cc PACKAGE core pybind11 DEPENDS aka_test ) register_gtest_sources( SOURCES test_fe_engine_gauss_integration.cc PACKAGE core ) register_gtest_sources( SOURCES test_gradient.cc PACKAGE core ) register_gtest_sources( SOURCES test_integrate.cc PACKAGE core ) register_gtest_sources( SOURCES test_inverse_map.cc PACKAGE core ) register_gtest_test(test_fe_engine FILES_TO_COPY ${_meshes}) diff --git a/test/test_fe_engine/test_fe_engine_fixture.hh b/test/test_fe_engine/test_fe_engine_fixture.hh index a637f8bbf..1e2d4bc59 100644 --- a/test/test_fe_engine/test_fe_engine_fixture.hh +++ b/test/test_fe_engine/test_fe_engine_fixture.hh @@ -1,69 +1,68 @@ /* -------------------------------------------------------------------------- */ #include "element_class.hh" #include "fe_engine.hh" #include "integrator_gauss.hh" #include "shape_lagrange.hh" #include "test_gtest_utils.hh" /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_TEST_FE_ENGINE_FIXTURE_HH__ #define __AKANTU_TEST_FE_ENGINE_FIXTURE_HH__ using namespace akantu; template class TestFEMFixture : public ::testing::Test { public: static constexpr const ElementType type = type_::value; static constexpr const size_t dim = ElementClass::getSpatialDimension(); using FEM = FEEngineTemplate; void SetUp() override { const auto dim = this->dim; const auto type = this->type; mesh = std::make_unique(dim); std::stringstream meshfilename; meshfilename << type << ".msh"; mesh->read(meshfilename.str()); lower = mesh->getLowerBounds(); upper = mesh->getUpperBounds(); nb_element = this->mesh->getNbElement(type); fem = std::make_unique(*mesh, dim, "my_fem"); fem->initShapeFunctions(); nb_quadrature_points_total = fem->getNbIntegrationPoints(type) * nb_element; SCOPED_TRACE(aka::to_string(type)); } void TearDown() override { fem.reset(nullptr); mesh.reset(nullptr); } protected: std::unique_ptr fem; std::unique_ptr mesh; UInt nb_element; UInt nb_quadrature_points_total; Vector lower; Vector upper; }; template constexpr const ElementType TestFEMFixture::type; template constexpr const size_t TestFEMFixture::dim; - using types = gtest_list_t; TYPED_TEST_CASE(TestFEMFixture, types); #endif /* __AKANTU_TEST_FE_ENGINE_FIXTURE_HH__ */ diff --git a/third-party/cmake/gtest.cmake b/third-party/cmake/gtest.cmake index c21f8638f..5cc0e86bc 100644 --- a/third-party/cmake/gtest.cmake +++ b/third-party/cmake/gtest.cmake @@ -1,34 +1,43 @@ set(_working_dir ${PROJECT_BINARY_DIR}/third-party/src/gtest-download) configure_file(${PROJECT_SOURCE_DIR}/third-party/gtest.cmake.in ${_working_dir}/CMakeLists.txt) set(GTEST_ROOT ${PROJECT_BINARY_DIR}/third-party) find_package(GTest QUIET) - if(NOT GTEST_FOUND) - message(STATUS "Downloading googletest") - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result WORKING_DIRECTORY ${_working_dir} - OUTPUT_FILE ${_working_dir}/configure-out.log - ERROR_FILE ${_working_dir}/configure-error.log) - - if(result) - message(SEND_ERROR "CMake step for googletest failed: ${result}") - return() + if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third-party/google-test) + message(STATUS "Downloading googletest") + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result WORKING_DIRECTORY ${_working_dir} + OUTPUT_FILE ${_working_dir}/configure-out.log + ERROR_FILE ${_working_dir}/configure-error.log) + + if(result) + message(SEND_ERROR "CMake step for googletest failed: ${result}") + return() + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result WORKING_DIRECTORY ${_working_dir} + OUTPUT_FILE ${_working_dir}/build-out.log + ERROR_FILE ${_working_dir}/build-error.log) + + if(result) + message(SEND_ERROR "Downloading googletest failed: ${result}") + return() + endif() endif() - message(STATUS "Building googletest") - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result WORKING_DIRECTORY ${_working_dir} - OUTPUT_FILE ${_working_dir}/build-out.log - ERROR_FILE ${_working_dir}/build-error.log) + set(BUILD_GTEST ON CACHE INTERNAL "" FORCE) + set(BUILD_GMOCK OFF CACHE INTERNAL "" FORCE) - if(result) - message(SEND_ERROR "Build step for googletest failed: ${result}") - return() - endif() -endif() + add_subdirectory(third-party/google-test) -set(GTEST_ROOT ${PROJECT_BINARY_DIR}/third-party) -find_package(GTest REQUIRED) + add_library(GTest::Main ALIAS gtest_main) + add_library(GTest::GTest ALIAS gtest) + set(gtest_FOUND TRUE CACHE INTERNAL "" FORCE) + set(GTEST_INCLUDE_DIRS third-party/google-test/googletest/include CACHE INTERNAL "" FORCE) + set(GTEST_LIBRARIES GTest::Main CACHE INTERNAL "" FORCE) + mask_package_options(gtest) +endif() diff --git a/third-party/cmake/pybind11.cmake b/third-party/cmake/pybind11.cmake new file mode 100644 index 000000000..e2a28e30e --- /dev/null +++ b/third-party/cmake/pybind11.cmake @@ -0,0 +1,26 @@ +set(_working_dir ${PROJECT_BINARY_DIR}/third-party/src/pybind11-download) +configure_file(${PROJECT_SOURCE_DIR}/third-party/pybind11.cmake.in ${_working_dir}/CMakeLists.txt) + +if(NOT EXISTS ${PROJECT_SOURCE_DIR}/third-party/pybind11) + message(STATUS "Downloading pybind11") + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result WORKING_DIRECTORY ${_working_dir} + OUTPUT_FILE ${_working_dir}/configure-out.log + ERROR_FILE ${_working_dir}/configure-error.log) + + execute_process(COMMAND "${CMAKE_COMMAND}" --build . + WORKING_DIRECTORY ${_working_dir} + OUTPUT_FILE ${_working_dir}/build-out.log + ERROR_FILE ${_working_dir}/build-error.log) +endif() + +list(APPEND AKANTU_EXPORT_LIST pybind11 module embed) + +add_subdirectory(${PROJECT_SOURCE_DIR}/third-party/pybind11) + +set(pybind11_FOUND TRUE CACHE INTERNAL "" FORCE) +set(PYBIND11_INCLUDE_DIR "${PYBIND11_INCLUDE_DIR};${PYTHON_INCLUDE_DIRS}" CACHE INTERNAL "") +set(PYBIND11_LIBRARIES "${PYTHON_LIBRARIES}" CACHE INTERNAL "") + +mask_package_options(PYBIND11) +mark_as_advanced(USE_PYTHON_INCLUDE_DIR) diff --git a/third-party/gtest.cmake.in b/third-party/gtest.cmake.in index 7da91d110..55490ca89 100644 --- a/third-party/gtest.cmake.in +++ b/third-party/gtest.cmake.in @@ -1,16 +1,16 @@ cmake_minimum_required(VERSION 3.1) project(gtest-download NONE) include(ExternalProject) ExternalProject_Add(gtest - PREFIX ${PROJECT_BINARY_DIR}/third-party GIT_REPOSITORY ${GTEST_GIT} GIT_TAG ${GTEST_VERSION} - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= -DGTEST_CREATE_SHARED_LIBRARY:BOOL=ON - DOWNLOAD_NO_PROGRESS 1 - UPDATE_DISCONNECTED 1 - USES_TERMINAL_INSTALL 0 - USES_TERMINAL_UPDATE 0 + SOURCE_DIR ${PROJECT_SOURCE_DIR}/third-party/google-test + BINARY_DIR ${PROJECT_BINARY_DIR}/third-party/google-test + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" ) diff --git a/third-party/pybind11.cmake.in b/third-party/pybind11.cmake.in new file mode 100644 index 000000000..1757513d7 --- /dev/null +++ b/third-party/pybind11.cmake.in @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.1) + +project(pybind11-download NONE) + +include(ExternalProject) + +ExternalProject_Add(pybind11 + SOURCE_DIR ${PROJECT_SOURCE_DIR}/third-party/pybind11 + BINARY_DIR ${PROJECT_BINARY_DIR}/third-party/pybind11 + GIT_REPOSITORY ${PYBIND11_GIT} + GIT_TAG ${PYBIND11_VERSION} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" + )