summaryrefslogtreecommitdiffstats
path: root/c++/src/CMakeLists.txt
blob: eae86a3eb608ae31a01207ef822dd05ce3421c22 (plain)
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
cmake_minimum_required (VERSION 3.10)
project (HDF5_CPP_SRC CXX)

#-----------------------------------------------------------------------------
# Parallel/MPI, prevent spurious cpp/cxx warnings
#-----------------------------------------------------------------------------
if (H5_HAVE_PARALLEL)
  add_definitions ("-DMPICH_SKIP_MPICXX")
  add_definitions ("-DMPICH_IGNORE_CXX_SEEK")
endif ()

#-----------------------------------------------------------------------------
# Apply Definitions to compiler in this directory and below
#-----------------------------------------------------------------------------
add_definitions (${HDF_EXTRA_C_FLAGS})

#-----------------------------------------------------------------------------
# Generate configure file
#-----------------------------------------------------------------------------
configure_file (${HDF_RESOURCES_DIR}/H5cxx_config.h.in
                ${HDF5_BINARY_DIR}/H5cxx_pubconf.h
)

#-----------------------------------------------------------------------------
# Define cpp Library
#-----------------------------------------------------------------------------
set (CPP_SOURCES
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5AbstractDs.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5ArrayType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5AtomType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Attribute.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5CommonFG.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5CompType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DataSet.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DataSpace.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DataType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DcreatProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DxferProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5EnumType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Exception.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5FaccProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5FcreatProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5File.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5FloatType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Group.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5IdComponent.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5IntType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5LaccProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5LcreatProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Library.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Location.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Object.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5OcreatProp.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5PredType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5PropList.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5StrType.cpp
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5VarLenType.cpp
)

set (CPP_HDRS
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5AbstractDs.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Alltypes.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5ArrayType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5AtomType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Attribute.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Classes.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5CommonFG.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5CompType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Cpp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5CppDoc.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DataSet.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DataSpace.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DataType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DcreatProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5DxferProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5EnumType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Exception.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5FaccProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5FcreatProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5File.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5FloatType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Group.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5IdComponent.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Include.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5IntType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5LaccProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5LcreatProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Library.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Location.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5Object.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5OcreatProp.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5PredType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5PropList.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5StrType.h
    ${HDF5_CPP_SRC_SOURCE_DIR}/H5VarLenType.h
)

add_library (${HDF5_CPP_LIB_TARGET} STATIC ${CPP_SOURCES} ${CPP_HDRS})
set_property(TARGET ${HDF5_CPP_LIB_TARGET} APPEND PROPERTY INCLUDE_DIRECTORIES "${HDF5_SRC_DIR};${HDF5_BINARY_DIR}")
TARGET_C_PROPERTIES (${HDF5_CPP_LIB_TARGET} STATIC " " " ")
target_link_libraries (${HDF5_CPP_LIB_TARGET} PUBLIC ${HDF5_LIB_TARGET})
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_CPP_LIB_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_CPP_LIB_TARGET} ${HDF5_CPP_LIB_NAME} STATIC 0)
set_target_properties (${HDF5_CPP_LIB_TARGET} PROPERTIES
    FOLDER libraries/cpp
    INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
)
set (install_targets ${HDF5_CPP_LIB_TARGET})

if (BUILD_SHARED_LIBS)
  add_library (${HDF5_CPP_LIBSH_TARGET} SHARED ${CPP_SOURCES} ${CPP_HDRS})
  set_property(TARGET ${HDF5_CPP_LIBSH_TARGET} APPEND PROPERTY INCLUDE_DIRECTORIES "${HDF5_SRC_DIR};${HDF5_BINARY_DIR}")
  TARGET_C_PROPERTIES (${HDF5_CPP_LIBSH_TARGET} SHARED " " " ")
  target_link_libraries (${HDF5_CPP_LIBSH_TARGET} PUBLIC ${HDF5_LIBSH_TARGET})
  set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_CPP_LIBSH_TARGET}")
  H5_SET_LIB_OPTIONS (${HDF5_CPP_LIBSH_TARGET} ${HDF5_CPP_LIB_NAME} SHARED "CXX")
  set_target_properties (${HDF5_CPP_LIBSH_TARGET} PROPERTIES
      FOLDER libraries/cpp
      COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB"
      INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
      INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB=1
  )
  set (install_targets ${install_targets} ${HDF5_CPP_LIBSH_TARGET})
endif ()

#-----------------------------------------------------------------------------
# Add file(s) to CMake Install
#-----------------------------------------------------------------------------
install (
    FILES
        ${CPP_HDRS}
    DESTINATION
        ${HDF5_INSTALL_INCLUDE_DIR}
    COMPONENT
        cppheaders
)

#-----------------------------------------------------------------------------
# Add Target(s) to CMake Install for import into other projects
#-----------------------------------------------------------------------------
if (HDF5_EXPORTED_TARGETS)
  if (BUILD_SHARED_LIBS)
    INSTALL_TARGET_PDB (${HDF5_CPP_LIBSH_TARGET} ${HDF5_INSTALL_BIN_DIR} cpplibraries)
  endif ()
  INSTALL_TARGET_PDB (${HDF5_CPP_LIB_TARGET} ${HDF5_INSTALL_BIN_DIR} cpplibraries)

  install (
      TARGETS
          ${install_targets}
      EXPORT
          ${HDF5_EXPORTED_TARGETS}
      LIBRARY DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT cpplibraries
      ARCHIVE DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT cpplibraries
      RUNTIME DESTINATION ${HDF5_INSTALL_BIN_DIR} COMPONENT cpplibraries
      FRAMEWORK DESTINATION ${HDF5_INSTALL_FWRK_DIR} COMPONENT cpplibraries
      INCLUDES DESTINATION include
  )
endif ()

#-----------------------------------------------------------------------------
# Create pkgconfig files
#-----------------------------------------------------------------------------
set (_PKG_CONFIG_PREFIX ${CMAKE_INSTALL_PREFIX})
set (_PKG_CONFIG_EXEC_PREFIX \${prefix})
set (_PKG_CONFIG_LIBDIR \${exec_prefix}/lib)
set (_PKG_CONFIG_INCLUDEDIR \${prefix}/include)
set (_PKG_CONFIG_LIBNAME "${HDF5_CPP_LIB_CORENAME}")
set (_PKG_CONFIG_VERSION "${HDF5_PACKAGE_VERSION}")

set (_PKG_CONFIG_LIBS_PRIVATE)

set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${HDF5_CPP_LIB_CORENAME}")
if (BUILD_SHARED_LIBS)
  set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${HDF5_CPP_LIB_CORENAME}")
endif ()

set (_PKG_CONFIG_REQUIRES "${HDF5_LIB_CORENAME}")
set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_LIB_CORENAME}")

configure_file (
    ${HDF_RESOURCES_DIR}/libhdf5.pc.in
    ${HDF5_BINARY_DIR}/CMakeFiles/${HDF5_CPP_LIB_CORENAME}-${HDF5_PACKAGE_VERSION}.pc
    @ONLY
)
install (
    FILES ${HDF5_BINARY_DIR}/CMakeFiles/${HDF5_CPP_LIB_CORENAME}-${HDF5_PACKAGE_VERSION}.pc
    DESTINATION ${HDF5_INSTALL_LIB_DIR}/pkgconfig
    COMPONENT cpplibraries
)

if (NOT WIN32)
  set (_PKG_CONFIG_COMPILER ${CMAKE_CXX_COMPILER})
  configure_file (
      ${HDF_RESOURCES_DIR}/libh5cc.in
      ${HDF5_BINARY_DIR}/CMakeFiles/h5c++
      @ONLY
  )
  install (
      FILES ${HDF5_BINARY_DIR}/CMakeFiles/h5c++
      DESTINATION ${HDF5_INSTALL_BIN_DIR}
      PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
      COMPONENT cpplibraries
  )
endif ()