CMakeLists.txt 6.59 KB
Newer Older
1
2
project(XdmfCore)
cmake_minimum_required(VERSION 2.6)
3
4
5
if (POLICY CMP0015)
  cmake_policy(SET CMP0015 NEW)
endif (POLICY CMP0015)
6

7
include(CheckCXXSourceCompiles)
Brian Panneton's avatar
Brian Panneton committed
8
include(SetUpVersion)
9

10
11
if(VERSION_CONTROL_AUTOUPDATE OR 
    NOT EXISTS ${CMAKE_BINARY_DIR}/XdmfVersion.hpp)
12
  VersionCreate("Xdmf" "2" "XDMFCORE_EXPORT" "XdmfCore.hpp")
13
14
endif(VERSION_CONTROL_AUTOUPDATE OR 
    NOT EXISTS ${CMAKE_BINARY_DIR}/XdmfVersion.hpp)
Brian Panneton's avatar
Brian Panneton committed
15

16
17
set(BUILD_SHARED_LIBS true)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
18
19
20
21
22
include_directories(${CMAKE_BINARY_DIR})
set(CMAKE_SKIP_BUILD_RPATH  FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
23

24
25
option(XDMF_BUILD_DSM OFF)

26
mark_as_advanced(CLEAR Boost_INCLUDE_DIR)
27
28
find_package(Boost REQUIRED)
if(Boost_FOUND)
29
30
  include_directories(${Boost_INCLUDE_DIRS})
  mark_as_advanced(FORCE Boost_INCLUDE_DIR)
31
32
endif(Boost_FOUND)

33
34
35
mark_as_advanced(CLEAR HDF5_C_INCLUDE_DIR)
mark_as_advanced(CLEAR HDF5_hdf5_LIBRARY_DEBUG)
mark_as_advanced(CLEAR HDF5_hdf5_LIBRARY_RELEASE)
36
37
find_package(HDF5 REQUIRED)
if(HDF5_FOUND)
38
39
40
  mark_as_advanced(FORCE HDF5_C_INCLUDE_DIR)
  mark_as_advanced(FORCE HDF5_hdf5_LIBRARY_DEBUG)
  mark_as_advanced(FORCE HDF5_hdf5_LIBRARY_RELEASE)
41
  include_directories(${HDF5_INCLUDE_DIRS})
42
  include_directories(${HDF5_C_INCLUDE_DIR})
43
44
  get_filename_component(HDF5_LIBRARY_DIR "${HDF5_hdf5_LIBRARY_RELEASE}" PATH)
  set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${HDF5_LIBRARY_DIR})
45
  set(HDF5_LIBRARIES ${HDF5_hdf5_LIBRARY_RELEASE})
46
47
  # FIXME: Would like to get this info from HDF5 so we don't have conflicting
  # MPI versions
48
49
50
51
  if(HDF5_IS_PARALLEL)
    find_package(MPI REQUIRED)
    if(MPI_FOUND)
      include_directories(${MPI_INCLUDE_PATH})
52
      set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
53
54
      get_filename_component(MPI_LIBRARY_DIR ${MPI_LIBRARY} PATH)
      set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${MPI_LIBRARY_DIR})
55
56
57
58
    endif(MPI_FOUND)
  endif(HDF5_IS_PARALLEL)
  get_filename_component(HDF5_ROOT "${HDF5_INCLUDE_DIR}/../" REALPATH)
  set(HDF5_BINARY_DIRS ${HDF5_ROOT}/bin ${HDF5_ROOT}/dll)
59
  set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${HDF5_LIBRARIES})
60
61
  set(XDMF_HDF5_BINARY_DIRS ${HDF5_BINARY_DIRS} PARENT_SCOPE)
  set(XDMF_BINARIES ${XDMF_BINARIES} ${HDF5_BINARY_DIRS})
62
63
64
65
endif(HDF5_FOUND)

find_package(LibXml2 REQUIRED)
if(LIBXML2_FOUND)
66
  include_directories(${LIBXML2_INCLUDE_DIR})
67
68
69
70
71
  get_filename_component(LIBXML2_ROOT "${LIBXML2_INCLUDE_DIR}/../" REALPATH)
  set(LIBXML2_BINARY_DIRS ${LIBXML2_ROOT}/bin)
  set(LIBXML2_BINARY_DIRS ${LIBXML2_BINARY_DIRS} PARENT_SCOPE)
  set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${LIBXML2_LIBRARIES})
  set(XDMF_BINARIES ${XDMF_BINARIES} ${LIBXML2_BINARY_DIRS})
72
73
endif(LIBXML2_FOUND)

74
75
76
77
78
79
80
81
82
# Perform compile-time checks and generate XdmfConfig.hpp
unset(HAVE_BOOST_SHARED_DYNAMIC_CAST CACHE)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Boost_INCLUDE_DIRS})
check_cxx_source_compiles("
#include <boost/shared_ptr.hpp>

struct Base { virtual ~Base(){} };
struct Derived : public Base {};

83
int main(int ac, char * av)
84
85
86
87
88
89
90
91
92
{
  boost::shared_ptr<Base> ptr(new Base());
  boost::shared_dynamic_cast<Derived>(ptr);
}
"
HAVE_BOOST_SHARED_DYNAMIC_CAST)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XdmfConfig.hpp.in 
               ${CMAKE_BINARY_DIR}/XdmfConfig.hpp)

93
set(XdmfCoreSources
94
95
96
97
  XdmfArray
  XdmfArrayType
  XdmfCoreItemFactory
  XdmfCoreReader
98
  XdmfError
99
  XdmfFunction
100
101
102
103
104
105
106
  XdmfHDF5Controller
  XdmfHDF5Writer
  XdmfHeavyDataController
  XdmfHeavyDataWriter
  XdmfInformation
  XdmfItem
  XdmfItemProperty
Kenneth Leiter's avatar
Kenneth Leiter committed
107
  XdmfSparseMatrix
108
109
110
111
  XdmfSystemUtils
  ${CMAKE_BINARY_DIR}/XdmfVersion
  XdmfVisitor
  XdmfWriter)
112

113
option(XDMF_BUILD_DSM OFF)
114
if(XDMF_BUILD_DSM)
115
116
117
  set(XdmfCoreSources
    ${XdmfCoreSources}
    XdmfHDF5ControllerDSM
118
119
120
121
122
    XdmfHDF5WriterDSM
    XdmfDSMCommMPI
    XdmfDSMBuffer
    XdmfDSMManager
    XdmfDSMDriver)
123
124
125

  find_package(H5FDdsm REQUIRED NO_MODULE)
  if(H5FDdsm_FOUND)
126
127
128
129
    include_directories(${H5FDdsm_INCLUDE_DIR})
    get_filename_component(H5FDdsm_LIBRARY_DIR 
                           "${H5FDdsm_INCLUDE_DIR}/../lib" REALPATH)
    set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${H5FDdsm_LIBRARY_DIR})
130
    get_property(h5fddsm_lib_location TARGET H5FDdsm PROPERTY LOCATION)
131
132
    set(H5FDdsm_LIBRARIES ${h5fddsm_lib_location})
    set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${H5FDdsm_LIBRARIES})
133
134
135
136
  else(H5FDdsm_FOUND)
    message(SEND_ERROR
      "Cannot find HDF5 DSM!  Please set H5FDdsm_DIR and configure again.")
  endif(H5FDdsm_FOUND)
137
138
endif(XDMF_BUILD_DSM)

139
add_library(XdmfCore ${XdmfCoreSources})
140
141
link_directories(${XDMF_LIBRARY_DIRS})
target_link_libraries(XdmfCore ${XDMF_LIBRARIES})
142

143
if(WIN32)
144
  add_definitions(-D_HDF5USEDLL_ -D_HDF5USEHLDLL_)
145
  set_target_properties(XdmfCore PROPERTIES 
146
147
148
149
150
151
152
153
154
      DEFINE_SYMBOL XdmfCore_EXPORTS)
  if(NOT MSVC10)
	set_target_properties(XdmfCore PROPERTIES
      PREFIX ../
      IMPORT_PREFIX ../
      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
      ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  endif(NOT MSVC10)
155
156
endif(WIN32)

157
if(XDMF_WRAP_JAVA)
158
  XDMF_SWIG_JAVA(XdmfCore)
159
160
endif(XDMF_WRAP_JAVA)

161
if(XDMF_WRAP_PYTHON)
162
  XDMF_SWIG_PYTHON(XdmfCore)
163
164
endif(XDMF_WRAP_PYTHON)

165
set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} PARENT_SCOPE)
166
if(WIN32)
167
    set(XDMFCORE_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/XdmfCore.lib PARENT_SCOPE)
168
169
170
endif(WIN32)

if(UNIX)
171
172
    set(XDMFCORE_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmfCore.so
        PARENT_SCOPE)
173
174
175
176
177
178
endif(UNIX)

if(APPLE)
    set(XDMFCORE_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmfCore.dylib
        PARENT_SCOPE)
endif(APPLE)
179

180
181
182
183
file(GLOB_RECURSE
  XdmfCoreHeaders
  "*.hpp" "*.tpp" "*.i"
  "../CMake/VersionSuite/*.hpp")
184
file(GLOB LokiHeaders loki/*.h)
185
install(FILES ${XdmfCoreHeaders} DESTINATION include)
186
install(FILES ${LokiHeaders} DESTINATION include/loki)
187
188
189
190
191
install(TARGETS XdmfCore
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib)

192
if(XDMF_BUILD_DSM)
193
194
195
196
set(XdmfCore_INCLUDE_DIRS
  ${Boost_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${HDF5_INCLUDE_DIR}
197
  ${H5FDdsm_INCLUDE_DIR}
198
199
200
  ${LIBXML2_INCLUDE_DIR}
  ${PYTHON_INCLUDE_DIRS}
  CACHE INTERNAL "")
201
202
203
204
205
206
207
208
209
else(XDMF_BUILD_DSM)
set(XdmfCore_INCLUDE_DIRS
  ${Boost_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${HDF5_INCLUDE_DIR}
  ${LIBXML2_INCLUDE_DIR}
  ${PYTHON_INCLUDE_DIRS}
  CACHE INTERNAL "")
endif(XDMF_BUILD_DSM)
210

211
212
213
set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${CMAKE_INSTALL_PREFIX}/lib)
set(XDMF_BINARIES ${XDMF_BINARIES} ${CMAKE_INSTALL_PREFIX}/bin)

214
if(BUILD_TESTING)
215
  add_subdirectory(tests)
216
endif(BUILD_TESTING)
217

218
219
set(XDMF_LIBRARIES ${XDMF_LIBRARIES} PARENT_SCOPE)
set(XDMF_BINARIES ${XDMF_BINARIES} PARENT_SCOPE)
220