File: CMakeLists.txt.in

package info (click to toggle)
med-fichier 4.0.0+repack-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 55,660 kB
  • sloc: cpp: 679,525; ansic: 72,977; python: 37,983; fortran: 12,925; sh: 6,821; f90: 5,531; makefile: 5,136; tcl: 216; xml: 173
file content (214 lines) | stat: -rw-r--r-- 7,770 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.10 FATAL_ERROR)
PROJECT(MEDFile C CXX)

## The following signature is still buggy as of CMake 2.8.11 - 
## the OPTIONAL is not considered.
## See http://www.cmake.org/Bug/view.php?id=10227
#ENABLE_LANGUAGE(Fortran OPTIONAL)

INCLUDE(CheckLanguage)
CHECK_LANGUAGE(Fortran)
IF(CMAKE_Fortran_COMPILER)
  ENABLE_LANGUAGE(Fortran)
ELSE()
  MESSAGE(STATUS "No Fortran support")
ENDIF()

## Version number 
SET(MED_NUM_MAJEUR  @MED_NUM_MAJEUR@)
SET(MED_NUM_MINEUR  @MED_NUM_MINEUR@)
SET(MED_NUM_RELEASE @MED_NUM_RELEASE@)

## Previous version
SET(MED_3_LATEST_MINOR @MED_3_LATEST_MINOR@)

SET(MED_STR_VERSION "${MED_NUM_MAJEUR}.${MED_NUM_MINEUR}.${MED_NUM_RELEASE}")

SET(LONG_OR_INT int)

## User options:
OPTION (MEDFILE_BUILD_TESTS "Build MED-file tests" ON)
IF (MEDFILE_BUILD_TESTS)
  ENABLE_TESTING()
ENDIF()
OPTION (MEDFILE_BUILD_SHARED_LIBS "Build MED-file shared libraries" ON)
OPTION (MEDFILE_BUILD_STATIC_LIBS "Build MED-file static libraries" OFF)
OPTION (MEDFILE_INSTALL_DOC "Install pre-built documentation" ON)
OPTION (MEDFILE_BUILD_PYTHON "Build Python bindings (needs SWIG)" OFF)

#-- Add an Option to toggle the generation of the API documentation
#-- Embedded documentation contains patched doxygen generated fortran documention
#-- If you rebuild it with your own doxygen Fortran documentation will differ
option(MEDFILE_BUILD_DOC "Use Doxygen to create the HTML based API documentation" OFF)
if(MEDFILE_BUILD_DOC)
  FIND_PACKAGE(Doxygen)
  if (NOT DOXYGEN_FOUND)
    message(FATAL_ERROR
      "Doxygen is needed to build the documentation. Please install it correctly")
  endif()

  ADD_SUBDIRECTORY(doc)
endif()

# Option checking.
IF(MEDFILE_BUILD_SHARED_LIBS AND MEDFILE_BUILD_STATIC_LIBS)
  MESSAGE(FATAL_ERROR "You can not build shared and static libraries at the same time! ")
  SET(MEDFILE_BUILD_STATIC_LIBS OFF)
ENDIF()
IF(NOT (MEDFILE_BUILD_SHARED_LIBS OR MEDFILE_BUILD_STATIC_LIBS))
  MESSAGE(FATAL_ERROR "You must select to build either STATIC or SHARED libs")
  SET(MEDFILE_BUILD_SHARED_LIBS ON)
ENDIF()

## Useful macros
LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/config/cmake_files")
INCLUDE(medMacros)

## Version number
#MED_EXTRACT_AUTOTOOLS_VERSION(${PROJECT_SOURCE_DIR}/configure.ac MED_NUM_MAJEUR MED_NUM_MINEUR MED_NUM_RELEASE)
#SET(MED_STR_VERSION "${MED_NUM_MAJEUR}.${MED_NUM_MINEUR}.${MED_NUM_RELEASE}")

## Platform specific flags (windows)
IF(WIN32)
  ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)  # To disable windows warnings for strcpy, fopen, ...
  ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)  # To disable windows warnings std::copy, std::transform, ...
  ADD_DEFINITIONS(-DWNT -DWIN32)
  ADD_DEFINITIONS(-D_WIN32_WINNT=0x0500) # Windows 2000 or later API is required
  ADD_DEFINITIONS(-DPPRO_NT_CALL) # For windows system functions call

  IF(NOT MINGW)
    # Needed to avoid a seg fault at runtime!
    # The variable is not very well documented but seems to exist
    SET(CMAKE_Fortran_FLAGS  "/iface:mixed_str_len_arg ${CMAKE_Fortran_FLAGS}")
    ADD_DEFINITIONS(-DPPRO_NT) # For windows medfile function nammes
  ENDIF()

ELSE()
  # Ensure intermediate OBJECT libraries and static libs are built with -fPIC:
  SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
ENDIF(WIN32)

## Directories
IF(WIN32 AND NOT CYGWIN)
   SET(INSTALL_CMAKE_CONFIG_DIR cmake)
ELSE()
   SET(INSTALL_CMAKE_CONFIG_DIR share/cmake/med-fichier-${MED_STR_VERSION})
ENDIF()
SET(INSTALL_INCLUDE_DIR include)

## Pre-requisites detection
# Detect HDF5 first to potentially retrieve MPI automatically:
MED_FIND_HDF5()
MED_FIND_MPI()

IF(MEDFILE_BUILD_PYTHON)
  FIND_PACKAGE(SWIG REQUIRED)
  INCLUDE(${SWIG_USE_FILE})
  FIND_PACKAGE(PythonLibs REQUIRED)
  FIND_PACKAGE(PythonInterp REQUIRED)  # to get version string ...
ENDIF()

## Creation of files med_config.h.cmake
MED_CREATE_CONFIG_FILES()

## Check for various functions
MED_CHECK_HEADERS()
MED_CHECK_FUNCTIONS()
MED_CHECK_SIZE()
MED_C_FORTRAN_INTERFACE()
MED_TIME_SYS_TIME()

## Configure the files created above
CONFIGURE_FILE("${PROJECT_BINARY_DIR}/include/med_config.h.cmake" "${PROJECT_BINARY_DIR}/include/med_config.h")
CONFIGURE_FILE("${PROJECT_BINARY_DIR}/include/2.3.6/med_config.h.cmake" "${PROJECT_BINARY_DIR}/include/2.3.6/med_config.h")

## Sources 
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tools)
IF(MEDFILE_BUILD_TESTS)
  ADD_SUBDIRECTORY(tests)
ENDIF()
IF(MEDFILE_BUILD_PYTHON)
  ADD_SUBDIRECTORY(python)
ENDIF()

## Installation of the doc
IF(MEDFILE_INSTALL_DOC  OR MEDFILE_BUILD_DOC)
  INSTALL(DIRECTORY doc/html.dox/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/med-fichier-${MED_STR_VERSION} REGEX "Makefile*" EXCLUDE PATTERN "*.am" EXCLUDE)
  INSTALL(DIRECTORY doc/gif doc/jpg doc/png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/med-fichier-${MED_STR_VERSION} FILES_MATCHING PATTERN "*.gif" PATTERN "*.jpg" PATTERN "*.svg" PATTERN "*.png")
ENDIF()

#######################
## Configuration export
#######################
INCLUDE(CMakePackageConfigHelpers)

# Project name, upper case
STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC)

# Detect if we are built as a sub-project in a bigger source tree:
IF("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
  SET(_BUILT_AS_SUB FALSE)
  MESSAGE(STATUS "Configuring ${PROJECT_NAME} standalone.")
ELSE()
  MESSAGE(STATUS "Configuring ${PROJECT_NAME} as a sub-project. No conf files will be installed.")
  SET(_BUILT_AS_SUB TRUE)
ENDIF()

# Add all targets to the build-tree export set if we are *not*  
# built as a sub-folder of a bigger project.
IF(NOT _BUILT_AS_SUB)
  IF(CMAKE_Fortran_COMPILER_WORKS)
    SET(_fortLib med medfwrap)
    SET(_fortLibS med_static medfwrap_static)
  ELSE()
    SET(_fortLib "")
    SET(_fortLibS "")
  ENDIF()
  
  IF(MEDFILE_BUILD_STATIC_LIBS)
    EXPORT(TARGETS medC_static ${_fortLibS}
      FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake)
  ENDIF()
  IF(MEDFILE_BUILD_SHARED_LIBS) 
    EXPORT(TARGETS medC ${_fortLib}
      APPEND FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake)
  ENDIF()
  
ENDIF()

# Create the configuration files:
#   - in the build tree:
SET(HDF5_ROOT_DIR "${HDF5_ROOT_DIR}")  # ensure the var exists, even if blank
SET(MPI_ROOT_DIR "${MPI_ROOT_DIR}")    # ensure the var exists, even if blank
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include")
CONFIGURE_PACKAGE_CONFIG_FILE(config/cmake_files/${PROJECT_NAME}Config.cmake.in 
    ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
    INSTALL_DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}"
    PATH_VARS CONF_INCLUDE_DIRS INSTALL_CMAKE_CONFIG_DIR CMAKE_INSTALL_PREFIX HDF5_ROOT_DIR MPI_ROOT_DIR)

#   - in the install tree:
#       Get the relative path of the include directory so 
#       we can register it in the generated configuration files:
SET(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}")
CONFIGURE_PACKAGE_CONFIG_FILE(config/cmake_files/${PROJECT_NAME}Config.cmake.in 
    ${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake
    INSTALL_DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}"
    PATH_VARS CONF_INCLUDE_DIRS INSTALL_CMAKE_CONFIG_DIR CMAKE_INSTALL_PREFIX HDF5_ROOT_DIR MPI_ROOT_DIR)

WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
    VERSION ${MED_STR_VERSION}
    COMPATIBILITY AnyNewerVersion)
  
# Install the CMake configuration files:
INSTALL(FILES
  "${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake"
  "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}")

# Install the export set for use within the install-tree
IF(NOT _BUILT_AS_SUB)
  INSTALL(EXPORT medfileTargets DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}" FILE ${PROJECT_NAME}Targets.cmake)
ENDIF()