CMakeLists.txt 14.4 KB
Newer Older
1
project(Xdmf)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
2 3
cmake_minimum_required(VERSION 2.6)

4 5 6
#Needed to build DSM because relative paths are used to add its libraries
if (POLICY CMP0015)
	cmake_policy(SET CMP0015 NEW)
7
endif ()
8

9 10 11 12
if(MSVC10)
	SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
	SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
endif()

set(XDMF_LIBNAME "Xdmf" CACHE STRING "Name for this xdmf library to avoid collision")
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
if(BUILD_SHARED_LIBS)
  set(LIBTYPE SHARED)
  set(BUILD_SHARED 1)
else()
  set(LIBTYPE STATIC)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XdmfConfig.hpp.in
               ${CMAKE_CURRENT_BINARY_DIR}/XdmfConfig.hpp)


# Enable CMake testing
option(XDMF_BUILD_TESTING "Build Tests" OFF)
if(XDMF_BUILD_TESTING)
  enable_testing()
  include(CTest)
endif()
33

34
if (BUILD_SHARED_LIBS)
35 36 37 38
  #STRING(REGEX MATCH "-fPIC" IS_FPIC "${CMAKE_CXX_FLAGS}")
  #if ("${IS_FPIC}" STREQUAL "")
  #  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  #endif ("${IS_FPIC}" STREQUAL "")
39 40 41
  add_definitions(-DXDMFSTATIC)
endif (BUILD_SHARED_LIBS)

42
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
43 44 45 46 47 48 49 50 51
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH
  ${CMAKE_CURRENT_SOURCE_DIR}/CMake
  ${CMAKE_CURRENT_SOURCE_DIR}/CMake/VersionSuite)
if(XDMF_BUILD_TESTING)
  list(APPEND CMAKE_MODULE_PATH
    ${CMAKE_CURRENT_SOURCE_DIR}/CMake/TestingSuite)
endif()
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
52

53
include(XdmfFunctions)
54

55 56 57
# Converting Install Prefix to an absolute path
get_filename_component(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)

58
# RPath
59 60 61 62
#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)
63

64 65 66
# Should we build with documentation
option(XDMF_BUILD_DOCUMENTATION OFF)
if(XDMF_BUILD_DOCUMENTATION)
67
  add_subdirectory(doc)
68
endif()
69

70 71 72 73
# Wrapper Setup
option(XDMF_WRAP_PYTHON OFF)
option(XDMF_WRAP_JAVA OFF)

74 75 76 77 78 79 80 81 82 83 84 85 86
#check for TIFF
find_package(TIFF)
if (TIFF_FOUND)
  add_definitions(-DXDMF_BUILD_TIFF)
  mark_as_advanced(FORCE TIFF_INCLUDE_DIR)
  mark_as_advanced(FORCE TIFF_LIBRARIES)
  mark_as_advanced(FORCE TIFF_LIBRARY)
  include_directories(${TIFF_INCLUDE_DIR})
  get_filename_component(TIFF_LIBRARY_DIR "${TIFF_LIBRARY}" PATH)
  set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${TIFF_LIBRARY_DIR})
  set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${TIFF_LIBRARIES})
endif (TIFF_FOUND)

87 88
# Test for DSM
option(XDMF_BUILD_DSM OFF)
89
mark_as_advanced(XDMF_BUILD_DSM)
90

91
if(XDMF_BUILD_DSM)
92 93 94 95 96 97
  find_package(MPI REQUIRED)
  if(MPI_FOUND)
    include_directories(${MPI_INCLUDE_PATH})
    set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
    get_filename_component(MPI_LIBRARY_DIR ${MPI_LIBRARY} PATH)
    set(XDMF_LIBRARY_DIRS ${XDMF_LIBRARY_DIRS} ${MPI_LIBRARY_DIR})
98 99 100 101
    # intel compiler requires an extra tag for CXX_FLAGS in order to properly build
    STRING(REGEX MATCH "icpc" IS_INTEL "${CMAKE_CXX_COMPILER}")
    if (NOT "${IS_INTEL}" STREQUAL "")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMPICH_IGNORE_CXX_SEEK")
102 103
    endif ()
  endif()
104
  option(XDMF_BUILD_DSM_THREADS ON)
105 106 107
  if (XDMF_WRAP_PYTHON)
    mark_as_advanced(FORCE PYTHON_INCLUDE_MPI4PY_DIR)
    set(PYTHON_INCLUDE_MPI4PY_DIR "" CACHE STRING "Directory containing mpi4py/mpi4py.i")
108
  endif ()
109
  add_definitions(-DXDMF_BUILD_DSM)
110
endif()
111

112 113
# If we are wrapping either, we need swig
if(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
114 115 116 117
  find_package(SWIG REQUIRED)
  include(${SWIG_USE_FILE})
  if(${SWIG_VERSION} LESS 2.0.0)
    message(SEND_ERROR "Swig must be version 2.0.0 or greater")
118 119
  endif()
endif()
120 121 122

# If we are wrapping python, let's include it in the top level
if(XDMF_WRAP_PYTHON)
123 124
  find_package(PythonInterp ${REQUESTED_PYTHON_VERSION} REQUIRED)
  find_package(PythonLibs ${REQUESTED_PYTHON_VERSION} REQUIRED)
125
  if (XDMF_BUILD_DSM)
126 127 128 129 130 131
    find_package (MPI4PY REQUIRED)
    if (MPI4PY_FOUND)
      if ("${PYTHON_INCLUDE_MPI4PY_DIR}" STREQUAL "")
        set(PYTHON_INCLUDE_MPI4PY_DIR ${MPI4PY_INCLUDE_DIR})
      endif ()
    endif ()
132
    include_directories(${PYTHON_INCLUDE_DIRS} ${MPI_CXX_INCLUDE_PATH} ${PYTHON_INCLUDE_MPI4PY_DIR})
133
  else ()
134
    include_directories(${PYTHON_INCLUDE_DIRS})
135
  endif ()
136 137 138 139 140 141 142 143

  # A macro to swig and create the python files
  # Since we essentually do the same thing inside and outside core, it
  # would be easier as a macro
  # Parameters:
  #     python_name = the name of the intended target to be wrapped
  #     ${ARGN} = any dependencies needed by the target
  # Output:
144 145
  #     Target Name = the output target name will have ${python_name} as its name
  macro(XDMF_SWIG_PYTHON python_name)
146
    set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
147 148
    # optimize swig generation --- these are all flags corresponding to -O
    # except -fvirtual which breaks visitor operation
149
    set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -modern -fastdispatch -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone)
150 151 152
    #Enables DSM
    if (XDMF_BUILD_DSM)
      set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM)
153 154
      if (XDMF_BUILD_DSM_THREADS)
        set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM_THREADS)
155 156
      endif ()
    endif ()
157
    set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
158
    set(swig_extra_generated_files "")
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
159 160
    swig_add_module(${python_name}Python python ${python_name}.i)
    swig_link_libraries(${python_name}Python ${python_name} ${PYTHON_LIBRARIES})
161 162
    set_property(DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
163
      ${CMAKE_CURRENT_BINARY_DIR}/${python_name}.pyc
164
    )
165 166 167

    if("${ARGN}" STRGREATER "")
      add_dependencies(${python_name} "${ARGN}")
168
    endif()
169 170

    if(WIN32)
171
      if(NOT MSVC10)
172
        set_target_properties(${SWIG_MODULE_${python_name}Python_REAL_NAME}
173 174 175
          PROPERTIES
          PREFIX ../
          IMPORT_PREFIX ../
176 177 178
          RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
179
      endif()
180
    endif()
181

182 183 184 185
    set_target_properties(${SWIG_MODULE_${python_name}Python_REAL_NAME}
      PROPERTIES
      OUTPUT_NAME "_${python_name}")

186 187 188 189 190 191 192
    string(TOUPPER ${python_name} python_name_upper)
    set(${python_name_upper}_PYTHON
      ${CMAKE_INSTALL_PREFIX}/lib/python/${python_name}.py)
    get_directory_property(${python_name}Parent PARENT_DIRECTORY)
    if(NOT "${${python_name}Parent}" STREQUAL "")
      set(${python_name_upper}_PYTHON ${${python_name_upper}_PYTHON}
        PARENT_SCOPE)
193
    endif()
194

Joseph G. Hennessey's avatar
Joseph G. Hennessey committed
195
    install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${python_name}.py
196
      DESTINATION lib/python)
197
    install(TARGETS ${SWIG_MODULE_${python_name}Python_REAL_NAME}
198
      DESTINATION lib/python)
199 200
  endmacro()
endif()
201 202 203

# If we are wrapping java, let's include it in the top level
if(XDMF_WRAP_JAVA)
204 205 206 207 208 209 210 211 212 213 214 215 216
  find_package(Java REQUIRED)
  find_package(JNI REQUIRED)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}
    ${JAVA_INCLUDE_PATH}
    ${JAVA_INCLUDE_PATH2})

  # A macro to swig and create the jar files
  # Since we essentually do the same thing inside and outside core, it
  # would be easier as a macro
  # Parameters:
  #     java_name = the name of the intended target to be wrapped
  #     ${ARGN} = any dependencies needed by the target
  # Output:
217 218 219
  #     Target Name     = the output target name will have ${java_name}Java as its name
  #     Target Jar      = the output target jar will have ${java_name}Java.jar as its name
  macro(XDMF_SWIG_JAVA java_name)
220
    set(${java_name}_JAVA_JAR ${CMAKE_BINARY_DIR}/${java_name}.jar)
221
    set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
222
    set(XDMF_JAVA_DIR ${CMAKE_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
223
    set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
224
    set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -v -make_default -package mil.army.arl.xdmf)
225
    set_source_files_properties(${java_name}.i PROPERTIES CPLUSPLUS ON)
226
    set(swig_extra_generated_files "")
227 228 229 230
    swig_add_module(${java_name}Java java ${java_name}.i)
    swig_link_libraries(${java_name}Java ${java_name})

    if(WIN32)
231 232 233 234 235
	  if(NOT MSVC10)
        set_target_properties(${SWIG_MODULE_${java_name}Java_REAL_NAME}
          PROPERTIES
          PREFIX ../
          IMPORT_PREFIX ../
236 237 238 239
          RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
	  endif()
240
      set(java_files *.java)
241
      set(java_dest "bin")
242
      set(separator "\;")
243
    else()
244
      set(java_files ${XDMF_JAVA_DIR}/*.java)
245
      set(java_dest "lib/java")
246
      set(separator ":")
247
    endif()
248 249 250 251 252 253 254 255

    add_custom_target(${java_name}_Java_Dir ALL DEPENDS ${XDMF_JAVA_DIR})
    add_custom_command(OUTPUT ${XDMF_JAVA_DIR}
      COMMAND ${CMAKE_COMMAND} -E make_directory ${XDMF_JAVA_DIR})
    add_custom_target(Compiled_${java_name}_Jar ALL DEPENDS
      ${${java_name}_JAVA_JAR})
    add_custom_command(OUTPUT ${${java_name}_JAVA_JAR}
      COMMAND ${CMAKE_COMMAND} -E chdir ${XDMF_JAVA_PACKAGE_DIR}
256
              ${JAVA_COMPILE} -cp \".${java_cp_jars}\" ${java_files}
257 258
      COMMAND ${JAVA_ARCHIVE} -cvf ${${java_name}_JAVA_JAR}
             "${XDMF_JAVA_PACKAGE_DIR}/*.class")
259 260 261 262 263
    add_dependencies(${java_name}Java ${java_name}_Java_Dir)
    add_dependencies(Compiled_${java_name}_Jar ${java_name}Java)

    if(NOT ${ARGN} EQUAL "")
      add_dependencies(Compiled_${java_name}_Jar "${ARGN}")
264
    endif()
265 266 267

    set_property(DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
268
      ${CMAKE_CURRENT_BINARY_DIR}/${java_name}.jar
269
      ${XDMF_JAVA_DIR})
270

271
    set(java_cp_jars "${java_cp_jars}${separator}${${java_name}_JAVA_JAR}")
272 273 274 275 276 277 278
    string(TOUPPER ${java_name} java_name_upper)
    set(${java_name_upper}_JAVA_JAR
      ${CMAKE_INSTALL_PREFIX}/lib/java/${java_name}.jar)
    get_directory_property(${java_name}Parent PARENT_DIRECTORY)
    if(NOT "${${java_name}Parent}" STREQUAL "")
      set(${java_name_upper}_JAVA_JAR ${${java_name_upper}_JAVA_JAR}
        PARENT_SCOPE)
279
      set(java_cp_jars "${java_cp_jars}" PARENT_SCOPE)
280
    endif()
281

282
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${java_name}.jar
283 284 285
      DESTINATION lib/java)
    install(TARGETS ${SWIG_MODULE_${java_name}Java_REAL_NAME}
      DESTINATION ${java_dest})
286 287
  endmacro()
endif()
288

289
add_subdirectory(core)
290
include_directories(${XdmfCore_INCLUDE_DIRS} ${XdmfDSM_INCLUDE_DIRS})
291
link_directories(${XDMF_LIBRARY_DIRS})
292

293 294
option(XDMF_BUILD_CORE_ONLY OFF)
if(NOT XDMF_BUILD_CORE_ONLY)
295
  set(XdmfSources
296
    XdmfAggregate
297 298 299 300 301 302 303
    XdmfAttribute
    XdmfAttributeCenter
    XdmfAttributeType
    XdmfCurvilinearGrid
    XdmfDomain
    XdmfGeometry
    XdmfGeometryType
Kenneth Leiter's avatar
Kenneth Leiter committed
304
    XdmfGraph
305 306 307
    XdmfGrid
    XdmfGridCollection
    XdmfGridCollectionType
308
    XdmfGridController
309
    XdmfGridTemplate
310 311 312 313 314 315 316
    XdmfItemFactory
    XdmfMap
    XdmfReader
    XdmfRectilinearGrid
    XdmfRegularGrid
    XdmfSet
    XdmfSetType
317
    XdmfTemplate
318 319 320 321
    XdmfTime
    XdmfTopology
    XdmfTopologyType
    XdmfUnstructuredGrid)
322

323
  add_library(XdmfObjects OBJECT ${XdmfSources})
David DeMarle's avatar
David DeMarle committed
324 325
  set_target_properties(XdmfObjects PROPERTIES
    POSITION_INDEPENDENT_CODE True)
326
  add_library(${XDMF_LIBNAME} $<TARGET_OBJECTS:XdmfObjects>)
327 328 329 330 331 332 333
  if (BUILD_SHARED_LIBS)
    add_library(Xdmf_Static STATIC $<TARGET_OBJECTS:XdmfObjects>)
    if (UNIX)
      set_target_properties(Xdmf_Static PROPERTIES
        OUTPUT_NAME "Xdmf")
    endif (UNIX)
  endif (BUILD_SHARED_LIBS)
334
  if(XDMF_BUILD_DSM)
335
    target_link_libraries(${XDMF_LIBNAME} XdmfCore XdmfDSM)
336 337 338
    if (BUILD_SHARED_LIBS)
      target_link_libraries(Xdmf_Static XdmfCore_Static XdmfDSM_Static)
    endif (BUILD_SHARED_LIBS)
339
  else(XDMF_BUILD_DSM)
340
    target_link_libraries(${XDMF_LIBNAME} XdmfCore)
341 342 343
    if (BUILD_SHARED_LIBS)
      target_link_libraries(Xdmf_Static XdmfCore_Static)
    endif (BUILD_SHARED_LIBS)
344
  endif(XDMF_BUILD_DSM)
345 346 347
  if (COMMAND vtk_target_install)
    vtk_target_install(${XDMF_LIBNAME})
  endif()
348 349

  if(WIN32)
350 351
    if (BUILD_SHARED_LIBS)
      set_target_properties(${XDMF_LIBNAME} PROPERTIES
352
        DEFINE_SYMBOL Xdmf_EXPORTS)
353 354
      set_target_properties(Xdmf_Static PROPERTIES
        DEFINE_SYMBOL Xdmf_EXPORTS)
355
    endif ()
356
    if(NOT MSVC10)
357
      set_target_properties(${XDMF_LIBNAME} PROPERTIES
358 359 360 361 362
        PREFIX ../
        IMPORT_PREFIX ../
        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
        LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
        ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
363 364 365 366 367 368 369
      if (BUILD_SHARED_LIBS)
        set_target_properties(Xdmf_Static PROPERTIES
          PREFIX ../
          IMPORT_PREFIX ../
          RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
          LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
          ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
370 371 372
      endif ()
    endif()
  endif()
373 374

  if(XDMF_WRAP_JAVA)
375 376
    XDMF_SWIG_JAVA(${XDMF_LIBNAME} Compiled_XdmfCore_Jar)
  endif()
377 378

  if(XDMF_WRAP_PYTHON)
379 380 381 382
    if (NOT BUILD_SHARED_LIBS)
      message(FATAL_ERROR "Python Wrappers do not function"
                          " properly without shared libraries")
    endif (NOT BUILD_SHARED_LIBS)
David DeMarle's avatar
David DeMarle committed
383
    if (XDMF_BUILD_DSM)
David DeMarle's avatar
David DeMarle committed
384 385 386 387
      XDMF_SWIG_PYTHON(${XDMF_LIBNAME} XdmfCore XdmfDSM)
    else()
      XDMF_SWIG_PYTHON(${XDMF_LIBNAME} XdmfCore)
    endif()
388
    set(XDMF_PYTHON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/python/)
389
  endif()
390

391
  if(XDMF_BUILD_TESTING)
392
    add_subdirectory(tests)
393
  endif()
394 395 396 397

  option(XDMF_BUILD_UTILS OFF)
  if(XDMF_BUILD_UTILS)
    add_subdirectory(utils)
398
  endif()
399

400
  if(WIN32)
401 402
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/${XDMF_LIBNAME}.lib)
  endif()
403 404
  
  if(UNIX)
405
    if (BUILD_SHARED_LIBS)
406
      set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/lib${XDMF_LIBNAME}.so)
407
    else (BUILD_SHARED_LIBS)
408
      set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/lib${XDMF_LIBNAME}.a)
409
    endif (BUILD_SHARED_LIBS)
410
  endif(UNIX)
411

412
  if(APPLE)
413 414
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/lib${XDMF_LIBNAME}.dylib)
  endif()
415
  
416 417 418 419 420
  file(GLOB XdmfHeaders 
    "*.hpp" 
    "*.tpp" 
    "*.i" 
    "CMake/VersionSuite/*.hpp"
421
    "${CMAKE_CURRENT_BINARY_DIR}/*.hpp"
422
  )
423
  install(FILES ${XdmfHeaders} DESTINATION include)
424
  install(TARGETS ${XDMF_LIBNAME}
425 426 427
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib)
428 429 430 431 432 433
  if (BUILD_SHARED_LIBS)
    install(TARGETS Xdmf_Static
      RUNTIME DESTINATION bin
      LIBRARY DESTINATION lib
      ARCHIVE DESTINATION lib)
  endif (BUILD_SHARED_LIBS)
434
endif()
435

436
xdmf_create_config_file(${PROJECT_NAME})
437 438
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  DESTINATION ${CMAKE_INSTALL_PREFIX})