CMakeLists.txt 5.86 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
include(TestBigEndian)
10

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

17 18
set(BUILD_SHARED_LIBS true)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
19 20 21 22 23
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)
24

25 26
option(XDMF_BUILD_DSM OFF)

27 28 29 30
if(XDMF_BUILD_DSM)
  option(XDMF_BUILD_DSM_THREADS ON)
endif(XDMF_BUILD_DSM)

31
mark_as_advanced(CLEAR Boost_INCLUDE_DIR)
32 33
find_package(Boost REQUIRED)
if(Boost_FOUND)
34 35
  include_directories(${Boost_INCLUDE_DIRS})
  mark_as_advanced(FORCE Boost_INCLUDE_DIR)
36 37
endif(Boost_FOUND)

38 39 40
mark_as_advanced(CLEAR HDF5_C_INCLUDE_DIR)
mark_as_advanced(CLEAR HDF5_hdf5_LIBRARY_DEBUG)
mark_as_advanced(CLEAR HDF5_hdf5_LIBRARY_RELEASE)
41 42
find_package(HDF5 REQUIRED)
if(HDF5_FOUND)
43 44 45
  mark_as_advanced(FORCE HDF5_C_INCLUDE_DIR)
  mark_as_advanced(FORCE HDF5_hdf5_LIBRARY_DEBUG)
  mark_as_advanced(FORCE HDF5_hdf5_LIBRARY_RELEASE)
46
  include_directories(${HDF5_INCLUDE_DIRS})
47
  include_directories(${HDF5_C_INCLUDE_DIR})
48 49
  get_filename_component(HDF5_LIBRARY_DIR "${HDF5_hdf5_LIBRARY_RELEASE}" PATH)
  set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${HDF5_LIBRARY_DIR})
50
  set(HDF5_LIBRARIES ${HDF5_hdf5_LIBRARY_RELEASE})
51 52
  # FIXME: Would like to get this info from HDF5 so we don't have conflicting
  # MPI versions
53 54 55 56
  if(HDF5_IS_PARALLEL)
    find_package(MPI REQUIRED)
    if(MPI_FOUND)
      include_directories(${MPI_INCLUDE_PATH})
57
      set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
58 59
      get_filename_component(MPI_LIBRARY_DIR ${MPI_LIBRARY} PATH)
      set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${MPI_LIBRARY_DIR})
60 61 62 63
    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)
64
  set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${HDF5_LIBRARIES})
65 66
  set(XDMF_HDF5_BINARY_DIRS ${HDF5_BINARY_DIRS} PARENT_SCOPE)
  set(XDMF_BINARIES ${XDMF_BINARIES} ${HDF5_BINARY_DIRS})
67 68 69 70
endif(HDF5_FOUND)

find_package(LibXml2 REQUIRED)
if(LIBXML2_FOUND)
71
  include_directories(${LIBXML2_INCLUDE_DIR})
72 73 74 75 76
  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})
77 78
endif(LIBXML2_FOUND)

79
# Perform compile-time checks and generate XdmfConfig.hpp
80 81 82

TEST_BIG_ENDIAN(XDMF_BIG_ENDIAN)

83 84 85 86 87 88 89 90
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 {};

91
int main(int ac, char * av[])
92 93 94 95 96 97 98 99 100
{
  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)

101
set(XdmfCoreSources
102
  XdmfArray
103
  XdmfArrayReference
104
  XdmfArrayType
105
  XdmfBinaryController
106 107
  XdmfCoreItemFactory
  XdmfCoreReader
108
  XdmfError
109
  XdmfFunction
110 111 112 113 114 115 116
  XdmfHDF5Controller
  XdmfHDF5Writer
  XdmfHeavyDataController
  XdmfHeavyDataWriter
  XdmfInformation
  XdmfItem
  XdmfItemProperty
Kenneth Leiter's avatar
Kenneth Leiter committed
117
  XdmfSparseMatrix
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
118
  XdmfSubset
119 120 121 122
  XdmfSystemUtils
  ${CMAKE_BINARY_DIR}/XdmfVersion
  XdmfVisitor
  XdmfWriter)
123 124

add_library(XdmfCore ${XdmfCoreSources})
125 126
link_directories(${XDMF_LIBRARY_DIRS})
target_link_libraries(XdmfCore ${XDMF_LIBRARIES})
127

128
if(WIN32)
129
  add_definitions(-D_HDF5USEDLL_ -D_HDF5USEHLDLL_)
130
  set_target_properties(XdmfCore PROPERTIES 
131 132 133 134 135 136 137 138 139
      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)
140 141
endif(WIN32)

142
if(XDMF_WRAP_JAVA)
143
  XDMF_SWIG_JAVA(XdmfCore)
144 145
endif(XDMF_WRAP_JAVA)

146
if(XDMF_WRAP_PYTHON)
147
  XDMF_SWIG_PYTHON(XdmfCore)
148 149
endif(XDMF_WRAP_PYTHON)

150
set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} PARENT_SCOPE)
151
if(WIN32)
152
    set(XDMFCORE_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/XdmfCore.lib PARENT_SCOPE)
153 154 155
endif(WIN32)

if(UNIX)
156 157
    set(XDMFCORE_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmfCore.so
        PARENT_SCOPE)
158 159 160 161 162 163
endif(UNIX)

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

165 166 167 168
file(GLOB_RECURSE
  XdmfCoreHeaders
  "*.hpp" "*.tpp" "*.i"
  "../CMake/VersionSuite/*.hpp")
169
file(GLOB LokiHeaders loki/*.h)
170
install(FILES ${XdmfCoreHeaders} DESTINATION include)
171
install(FILES ${LokiHeaders} DESTINATION include/loki)
172 173 174 175 176 177 178 179 180 181 182 183
install(TARGETS XdmfCore
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib)

set(XdmfCore_INCLUDE_DIRS
  ${Boost_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${HDF5_INCLUDE_DIR}
  ${LIBXML2_INCLUDE_DIR}
  ${PYTHON_INCLUDE_DIRS}
  CACHE INTERNAL "")
184

185
set(XDMF_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include PARENT_SCOPE)
186
set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${CMAKE_INSTALL_PREFIX}/lib)
187
set(XDMF_DIR ${CMAKE_INSTALL_PREFIX} PARENT_SCOPE)
188 189
set(XDMF_BINARIES ${XDMF_BINARIES} ${CMAKE_INSTALL_PREFIX}/bin)

190 191 192 193
if(XDMF_BUILD_DSM)
  add_subdirectory(dsm)
endif(XDMF_BUILD_DSM)

194
if(BUILD_TESTING)
195
  add_subdirectory(tests)
196
endif(BUILD_TESTING)
197

198 199
set(XDMF_LIBRARIES ${XDMF_LIBRARIES} PARENT_SCOPE)
set(XDMF_BINARIES ${XDMF_BINARIES} PARENT_SCOPE)
200