Skip to content

Commit 2203ee0

Browse files
committed
Hopefully more robust and handy detection of the TFEL libraries
1 parent e8f437c commit 2203ee0

File tree

9 files changed

+83
-47
lines changed

9 files changed

+83
-47
lines changed

CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,16 @@ if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
148148
endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
149149

150150
#detecting TFEL and MFront
151-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
152-
find_package(TFEL)
153-
if(TFEL_FOUND)
154-
include(tfel)
155-
include(material-properties)
156-
include(behaviours)
157-
endif(TFEL_FOUND)
151+
option(disable-tfel "explicitly disable TFEL support. By default, MGIS tries to use TFEL for tests and MGIS/Function" OFF)
152+
if(NOT disable-tfel)
153+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
154+
find_package(TFEL)
155+
if(TFEL_FOUND)
156+
include(tfel)
157+
include(material-properties)
158+
include(behaviours)
159+
endif(TFEL_FOUND)
160+
endif(NOT disable-tfel)
158161

159162
#documentations
160163
option(enable-doxygen-doc "enable generation of the Doxygen documentation" OFF)
@@ -229,9 +232,7 @@ endif(CMAKE_CONFIGURATION_TYPES)
229232

230233
add_subdirectory(include)
231234
add_subdirectory(src)
232-
if(MGIS_HAVE_TFEL)
233-
add_subdirectory(tests)
234-
endif(MGIS_HAVE_TFEL)
235+
add_subdirectory(tests)
235236
add_subdirectory(bindings)
236237

237238
# Packaging

INSTALL-cmake.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Options
5555
- `enable-static`: compiles static libraries
5656
- `enable-doxygen-doc`: enable the generation of the API documentation
5757
using with `Doxygen`.
58+
- `disable-tfel`: by default, `MGIS` tries to add support for `TFEL`,
59+
notably if `tfel-config` is found in the `PATH`. This option disables
60+
this behaviour.
5861

5962
`cmake` usefull variables
6063
=======================
@@ -67,6 +70,7 @@ Options
6770
version of python shall be passed, not
6871
the revision version or the detection
6972
fails.
73+
- `TFEL_DIR` : specify the directory where to find TFEL
7074

7175
`cmake` typical usage
7276
=====================

bindings/c/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_subdirectory(include)
22
add_subdirectory(src)
3-
if(MGIS_HAVE_TFEL)
3+
if(MGIS_HAVE_MFRONT_SUPPORT)
44
add_subdirectory(tests)
5-
endif(MGIS_HAVE_TFEL)
5+
endif(MGIS_HAVE_MFRONT_SUPPORT)

bindings/fortran/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
add_subdirectory(src)
22
add_subdirectory(modules)
3-
if(MGIS_HAVE_TFEL)
3+
if(MGIS_HAVE_MFRONT_SUPPORT)
44
add_subdirectory(tests)
5-
endif(MGIS_HAVE_TFEL)
5+
endif(MGIS_HAVE_MFRONT_SUPPORT)
66

bindings/python/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ endif(MGIS_APPEND_SUFFIX)
1919

2020
add_subdirectory(src)
2121
add_subdirectory(mgis)
22-
if(MGIS_HAVE_TFEL)
22+
if(MGIS_HAVE_MFRONT_SUPPORT)
2323
add_subdirectory(tests)
24-
endif(MGIS_HAVE_TFEL)
24+
endif(MGIS_HAVE_MFRONT_SUPPORT)

cmake/modules/FindTFEL.cmake

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,39 @@
44
# set(TFELHOME ${CONAN_TFEL_ROOT})
55
# find_package(TFEL REQUIRED)
66
#
7-
# Once found, declares these variables:
8-
# - TFEL_FOUND
7+
# If a suitable environment is found to compile MFront behaviours,
8+
# the following variables are declared:
9+
# - MGIS_HAVE_MFRONT_SUPPORT
910
# - TFEL_INCLUDE_PATH
1011
# - TFEL_LIBRARIES
1112
# - TFEL_CXX_STANDARD
1213
# - TFEL_VERSION
14+
#
15+
# If TFEL libraries are found, the following variable is declared:
16+
# - MGIS_HAVE_TFEL
17+
18+
set(tfel_libs
19+
TFELTests
20+
TFELException
21+
TFELUtilities
22+
TFELMaterial
23+
TFELMath
24+
MTestFileGenerator
25+
)
1326

1427
if(DEFINED TFEL_DIR)
1528
list(APPEND CMAKE_PREFIX_PATH "${TFEL_DIR}")
1629
endif()
1730

1831
if(DEFINED ENV{TFELHOME})
1932
set(TFELHOME "$ENV{TFELHOME}")
20-
list(APPEND CMAKE_PREFIX_PATH "$ENV{TFELHOME}/share/tfel/cmake")
33+
if(NOT DEFINED TFEL_DIR)
34+
set(TFEL_DIR "${TFELHOME}/share/tfel/cmake")
35+
list(APPEND CMAKE_PREFIX_PATH "${TFEL_DIR}")
36+
endif(NOT DEFINED TFEL_DIR)
37+
message(STATUS "tfelhome: ${TFELHOME}")
2138
endif()
2239

23-
message(STATUS "tfelhome: ${TFELHOME}")
24-
2540
foreach(tool mfront tfel-check tfel-config mfront-query)
2641
string(TOUPPER ${tool} toolVar)
2742
string(REPLACE "-" "_" toolVar ${toolVar})
@@ -30,15 +45,27 @@ endforeach()
3045

3146
IF(TFEL_CONFIG AND MFRONT AND MFRONT_QUERY)
3247

48+
if ((NOT DEFINED TFEL_DIR) AND (NOT DEFINED ENV{TFELHOME}))
49+
# Trying to figure out TFEL_DIR
50+
execute_process(COMMAND ${TFEL_CONFIG} "--include-path"
51+
OUTPUT_VARIABLE TFEL_INCLUDE_PATH
52+
OUTPUT_STRIP_TRAILING_WHITESPACE
53+
)
54+
file(TO_CMAKE_PATH "${TFEL_INCLUDE_PATH}" TFEL_INCLUDE_PATH)
55+
cmake_path(GET TFEL_INCLUDE_PATH PARENT_PATH TFELHOME)
56+
set(TFEL_DIR "${TFELHOME}/share/tfel/cmake")
57+
list(APPEND CMAKE_PREFIX_PATH "${TFEL_DIR}")
58+
endif ((NOT DEFINED TFEL_DIR) AND (NOT DEFINED ENV{TFELHOME}))
59+
3360
execute_process(COMMAND ${TFEL_CONFIG} "--cxx-standard"
3461
RESULT_VARIABLE TFEL_CXX_STANDARD_AVAILABLE
3562
OUTPUT_VARIABLE TFEL_CXX_STANDARD
3663
OUTPUT_STRIP_TRAILING_WHITESPACE
3764
)
3865
if(NOT TFEL_CXX_STANDARD_AVAILABLE EQUAL 0)
39-
set(TFEL_CXX_STANDARD 11)
66+
message(FATAL_ERROR "tfel-config does not support --cxx-standard")
4067
endif()
41-
68+
4269
execute_process(COMMAND ${TFEL_CONFIG} "--version"
4370
OUTPUT_VARIABLE TFEL_VERSION_FULL
4471
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -67,32 +94,19 @@ IF(TFEL_CONFIG AND MFRONT AND MFRONT_QUERY)
6794
if(NOT TFEL_INCLUDE_PATH_RESULT EQUAL 0)
6895
message(FATAL_ERROR "call to tfel-config failed")
6996
endif()
97+
98+
foreach(lib ${tfel_libs})
99+
find_library(${lib}_LIBRARY ${lib} HINTS ${TFELHOME} PATH_SUFFIXES lib)
100+
list(APPEND TFEL_LIBRARIES ${${lib}_LIBRARY})
101+
endforeach(lib)
70102

71103
# find_path(TFEL_CONFIG_INCLUDE_PATH TFELConfig.hxx
72104
# HINTS ${TFELHOME}/include/TFEL/Config
73105
# )
74106
# get_filename_component(TFEL_INCLUDE_PATH
75107
# ${TFEL_CONFIG_INCLUDE_PATH}/../.. ABSOLUTE CACHE
76108
# )
77-
78-
set(tfel_libs
79-
TFELTests
80-
TFELException
81-
TFELUtilities
82-
TFELMaterial
83-
TFELMath
84-
MTestFileGenerator
85-
)
86-
if(${TFEL_CXX_STANDARD} LESS 17)
87-
list(APPEND tfel_libs TFELPhysicalConstants)
88-
endif()
89-
90-
foreach(lib ${tfel_libs})
91-
find_package(${lib} REQUIRED)
92-
find_library(${lib}_LIBRARY ${lib} HINTS ${TFELHOME} PATH_SUFFIXES lib)
93-
list(APPEND TFEL_LIBRARIES ${${lib}_LIBRARY})
94-
endforeach(lib)
95-
109+
96110
include(FindPackageHandleStandardArgs)
97111
find_package_handle_standard_args(TFEL DEFAULT_MSG
98112
TFEL_VERSION
@@ -101,10 +115,17 @@ IF(TFEL_CONFIG AND MFRONT AND MFRONT_QUERY)
101115
TFEL_CXX_STANDARD
102116
)
103117

104-
set(TFEL_FOUND ON)
118+
set(MGIS_HAVE_MFRONT_SUPPORT ON)
105119

106120
else(TFEL_CONFIG AND MFRONT AND MFRONT_QUERY)
107121

108-
set(TFEL_FOUND OFF)
122+
set(MGIS_HAVE_MFRONT_SUPPORT OFF)
109123

110124
endif(TFEL_CONFIG AND MFRONT AND MFRONT_QUERY)
125+
126+
if(DEFINED TFEL_DIR)
127+
foreach(lib ${tfel_libs})
128+
find_package(${lib} REQUIRED)
129+
endforeach(lib)
130+
set(MGIS_HAVE_TFEL ON)
131+
endif(DEFINED TFEL_DIR)

cmake/modules/tfel.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ message(STATUS "MTestFileGenerator : ${MTestFileGenerator_LIBRARY}")
2626
set(TFEL_MFRONT_LIBRARIES
2727
${TFEL_LIBRARIES}
2828
CACHE INTERNAL "")
29-
set(MGIS_HAVE_TFEL ON)

src/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ if(enable-mgis-function)
2929
BasicLinearQuadratureSpace.cxx
3030
Function.cxx
3131
Evaluator.cxx
32-
TensorView.cxx
33-
TensorModifier.cxx
3432
MaterialFunctionManager.cxx)
33+
if(MGIS_HAVE_TFEL)
34+
list(APPEND MFrontGenericInterface_SOURCES
35+
TensorView.cxx
36+
TensorModifier.cxx)
37+
endif(MGIS_HAVE_TFEL)
3538
endif(enable-mgis-function)
3639

3740
mgis_library(MFrontGenericInterface

tests/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
STRING(REPLACE "\\;" ";" MGIS_PATH_STRING "$ENV{PATH}")
22
STRING(REPLACE ";" "\\;" MGIS_PATH_STRING "${MGIS_PATH_STRING}")
33

4+
if(MGIS_HAVE_MFRONT_SUPPORT)
5+
46
mfront_material_properties_check_library(MaterialPropertyTest
57
MaterialPropertyBoundCheck
68
MaterialPropertyBoundCheck2
@@ -370,6 +372,8 @@ else((CMAKE_HOST_WIN32) AND (NOT MSYS))
370372
PROPERTY DEPENDS BehaviourTest)
371373
endif((CMAKE_HOST_WIN32) AND (NOT MSYS))
372374

375+
endif(MGIS_HAVE_MFRONT_SUPPORT)
376+
373377
add_executable(InvalidResultTest
374378
EXCLUDE_FROM_ALL
375379
InvalidResultTest.cxx)
@@ -467,6 +471,8 @@ add_executable(MaterialFunctionManagerTest
467471
target_link_libraries(MaterialFunctionManagerTest
468472
PRIVATE MFrontGenericInterface tfel::TFELTests)
469473

474+
if(MGIS_HAVE_MFRONT_SUPPORT)
475+
470476
add_test(NAME MaterialFunctionManagerTest
471477
COMMAND MaterialFunctionManagerTest "$<TARGET_FILE:BehaviourTest>")
472478
add_dependencies(check MaterialFunctionManagerTest)
@@ -479,6 +485,8 @@ else((CMAKE_HOST_WIN32) AND (NOT MSYS))
479485
PROPERTY DEPENDS BehaviourTest)
480486
endif((CMAKE_HOST_WIN32) AND (NOT MSYS))
481487

488+
endif(MGIS_HAVE_MFRONT_SUPPORT)
489+
482490
endif(MGIS_HAVE_TFEL)
483491

484492
endif(enable-mgis-function)

0 commit comments

Comments
 (0)