forked from FieldML/FieldML-API
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
125 lines (113 loc) · 4.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is FieldML
#
# The Initial Developer of the Original Code is
# Auckland Uniservices Ltd, Auckland, New Zealand.
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK ***** */
# Set the minimum version of cmake required to 3.0
cmake_minimum_required( VERSION 3.0 )
# Set this namespace to keep these options seperate from other project options
set( FIELDML_NAMESPACE_NAME FIELDML )
project(fieldml VERSION 0.5.0 LANGUAGES CXX)
enable_language(Fortran OPTIONAL)
option(USE_HDF5 "Do you want to use netgen (HDF5)?" NO)
option(HDF5_WITH_MPI "Do you want to use MPI with HDF5?" NO)
option(BUILD_TESTS "Build tests" ON)
option(FORTRAN_BINDINGS "Do you want to build the Fortran bindings" YES)
if (FORTRAN_BINDINGS AND NOT CMAKE_Fortran_COMPILER)
set(FORTRAN_BINDINGS NO)
message(WARNING "No Fortran compiler found but FORTRAN_BINDINGS requested. Disabling.")
endif()
option(JAVA_BINDINGS "Do you want to build the Java bindings" NO)
set(PACKAGE_CONFIG_DIR "lib/cmake" CACHE STRING "Directory for package config files (relative to CMAKE_INSTALL_PREFIX)")
# Further options:
# CMAKE_POSITION_INDEPENDENT_CODE=YES for -fPIC constant (is also passed in from OpenCMISS-main build script)
find_package(LibXml2 REQUIRED)
if(USE_HDF5)
# See the FindHDF5 description
if (BUILD_SHARED_LIBS)
set(HDF5_USE_STATIC_LIBRARIES NO)
else()
set(HDF5_USE_STATIC_LIBRARIES YES)
endif()
find_package(HDF5 REQUIRED CXX)
if(HDF5_WITH_MPI)
find_package(MPI REQUIRED)
endif()
endif()
if (NOT CMAKE_DEBUG_POSTFIX)
SET(CMAKE_DEBUG_POSTFIX d)
endif()
# Add actual fieldml code and io
add_subdirectory(core)
add_subdirectory(io)
if (FORTRAN_BINDINGS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FortranBindings.cmake)
endif()
# Create interface library for easy inclusion
add_library(fieldml-api INTERFACE)
target_link_libraries(fieldml-api INTERFACE fieldml-core fieldml-io)
if (HAVE_Fortran_BINDINGS)
target_link_libraries(fieldml-api INTERFACE fieldml-fortran)
endif()
install(TARGETS fieldml-api
EXPORT fieldml-api-config
INCLUDES DESTINATION include)
# Tests
if (BUILD_TESTS)
add_subdirectory(test)
endif()
if(JAVA_BINDINGS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/JavaBindings.cmake)
endif()
include(CMakePackageConfigHelpers)
install(EXPORT fieldml-api-config
DESTINATION ${PACKAGE_CONFIG_DIR})
WRITE_BASIC_PACKAGE_VERSION_FILE(${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-version.cmake
COMPATIBILITY AnyNewerVersion)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-dependencies.cmake
"include(CMakeFindDependencyMacro)\r\n"
"set(${PROJECT_NAME}_IMPORT_PREFIX \${_IMPORT_PREFIX})\r\n"
)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-dependencies.cmake "find_dependency(LibXml2 ${LIBXML2_VERSION})\r\n")
if (USE_HDF5)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-dependencies.cmake "find_dependency(HDF5 ${HDF5_VERSION})\r\n")
endif()
if (JAVA_BINDINGS)
# TODO
#file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-dependencies.cmake "find_dependency(OpenMP)\r\n")
endif()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-dependencies.cmake "set(_IMPORT_PREFIX \${${PROJECT_NAME}_IMPORT_PREFIX})")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/fieldml-api-config-dependencies.cmake
DESTINATION ${PACKAGE_CONFIG_DIR})