CMakeLists.txt 14.1 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 7 8
#Needed to build DSM because relative paths are used to add its libraries
if (POLICY CMP0015)
	cmake_policy(SET CMP0015 NEW)
endif (POLICY CMP0015)

9 10 11 12 13 14
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})
endif(MSVC10)

15 16 17 18 19 20 21 22 23 24
option(BUILD_SHARED_LIBS ON PARENT_SCOPE)

if (BUILD_SHARED_LIBS)
  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 "")
  add_definitions(-DXDMFSTATIC)
endif (BUILD_SHARED_LIBS)

25
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
26
include_directories(${CMAKE_BINARY_DIR})
27
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
28 29 30 31
set(CMAKE_MODULE_PATH
  ${CMAKE_SOURCE_DIR}/CMake
  ${CMAKE_SOURCE_DIR}/CMake/TestingSuite
  ${CMAKE_SOURCE_DIR}/CMake/VersionSuite)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
32

33
include(XdmfFunctions)
34

35 36 37
# Converting Install Prefix to an absolute path
get_filename_component(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)

38 39 40 41 42
# RPath
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)
43

44 45 46
# Should we build with documentation
option(XDMF_BUILD_DOCUMENTATION OFF)
if(XDMF_BUILD_DOCUMENTATION)
47
  add_subdirectory(doc)
48 49
endif(XDMF_BUILD_DOCUMENTATION)

50 51 52
# Enable CMake testing
option(BUILD_TESTING "Build Tests" OFF)
if(BUILD_TESTING)
53 54
  enable_testing()
  include(CTest)
55
endif(BUILD_TESTING)
56

57 58 59 60
# Wrapper Setup
option(XDMF_WRAP_PYTHON OFF)
option(XDMF_WRAP_JAVA OFF)

61 62 63 64 65 66 67 68 69 70 71 72 73
#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)

74 75 76
# Test for DSM
option(XDMF_BUILD_DSM OFF)

77
if(XDMF_BUILD_DSM)
78 79 80 81 82 83
  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})
84 85 86 87 88
    # 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")
    endif (NOT "${IS_INTEL}" STREQUAL "")
89
  endif(MPI_FOUND)
90
  option(XDMF_BUILD_DSM_THREADS ON)
91 92 93 94
  if (XDMF_WRAP_PYTHON)
    mark_as_advanced(FORCE PYTHON_INCLUDE_MPI4PY_DIR)
    set(PYTHON_INCLUDE_MPI4PY_DIR "" CACHE STRING "Directory containing mpi4py/mpi4py.i")
  endif (XDMF_WRAP_PYTHON)
95
  add_definitions(-DXDMF_BUILD_DSM)
96 97
endif(XDMF_BUILD_DSM)

98 99
# If we are wrapping either, we need swig
if(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
100 101 102 103 104
  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")
  endif(${SWIG_VERSION} LESS 2.0.0)
105 106 107 108
endif(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)

# If we are wrapping python, let's include it in the top level
if(XDMF_WRAP_PYTHON)
109 110
  find_package(PythonInterp REQUIRED)
  find_package(PythonLibs REQUIRED)
111
  if (XDMF_BUILD_DSM)
112 113 114 115 116 117
    find_package (MPI4PY REQUIRED)
    if (MPI4PY_FOUND)
      if ("${PYTHON_INCLUDE_MPI4PY_DIR}" STREQUAL "")
        set(PYTHON_INCLUDE_MPI4PY_DIR ${MPI4PY_INCLUDE_DIR})
      endif ()
    endif ()
118
    include_directories(${PYTHON_INCLUDE_DIRS} ${MPI_CXX_INCLUDE_PATH} ${PYTHON_INCLUDE_MPI4PY_DIR})
119 120 121
  else (XDMF_BUILD_DSM)
    include_directories(${PYTHON_INCLUDE_DIRS})
  endif (XDMF_BUILD_DSM)
122 123 124 125 126 127 128 129

  # 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:
130 131
  #     Target Name = the output target name will have ${python_name} as its name
  macro(XDMF_SWIG_PYTHON python_name)
132
    set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
133 134
    # optimize swig generation --- these are all flags corresponding to -O
    # except -fvirtual which breaks visitor operation
135
    set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -modern -fastdispatch -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone)
136 137 138
    #Enables DSM
    if (XDMF_BUILD_DSM)
      set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM)
139 140 141
      if (XDMF_BUILD_DSM_THREADS)
        set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM_THREADS)
      endif (XDMF_BUILD_DSM_THREADS)
142
    endif (XDMF_BUILD_DSM)
143
    set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
144
    set(swig_extra_generated_files "")
145 146
    swig_add_module(${python_name}Python python ${python_name}.i)
    swig_link_libraries(${python_name}Python ${python_name} ${PYTHON_LIBRARIES})
147 148
    set_property(DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
149 150
      ${CMAKE_BINARY_DIR}/${python_name}.pyc
    )
151 152 153 154 155 156

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

    if(WIN32)
157
	  if(NOT MSVC10)
158
        set_target_properties(${SWIG_MODULE_${python_name}Python_REAL_NAME}
159 160 161 162 163 164 165
          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)
166 167
    endif(WIN32)

168 169 170 171
    set_target_properties(${SWIG_MODULE_${python_name}Python_REAL_NAME}
      PROPERTIES
      OUTPUT_NAME "_${python_name}")

172 173 174 175 176 177 178 179 180
    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)
    endif(NOT "${${python_name}Parent}" STREQUAL "")

181 182
    install(FILES ${CMAKE_BINARY_DIR}/${python_name}.py
      DESTINATION lib/python)
183
    install(TARGETS ${SWIG_MODULE_${python_name}Python_REAL_NAME}
184
      DESTINATION lib/python)
185
  endmacro(XDMF_SWIG_PYTHON)
186 187 188 189
endif(XDMF_WRAP_PYTHON)

# If we are wrapping java, let's include it in the top level
if(XDMF_WRAP_JAVA)
190 191 192 193 194 195 196 197 198 199 200 201 202
  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:
203 204 205
  #     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)
206 207 208 209
    set(${java_name}_JAVA_JAR ${CMAKE_BINARY_DIR}/${java_name}.jar)
    set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
    set(XDMF_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
    set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
210
    set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -v -make_default -package mil.army.arl.xdmf)
211
    set_source_files_properties(${java_name}.i PROPERTIES CPLUSPLUS ON)
212
    set(swig_extra_generated_files "")
213 214 215 216
    swig_add_module(${java_name}Java java ${java_name}.i)
    swig_link_libraries(${java_name}Java ${java_name})

    if(WIN32)
217 218 219 220 221 222 223 224 225
	  if(NOT MSVC10)
        set_target_properties(${SWIG_MODULE_${java_name}Java_REAL_NAME}
          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)
226
      set(java_files *.java)
227
      set(java_dest "bin")
228
      set(separator "\;")
229
    else(WIN32)
230
      set(java_files ${XDMF_JAVA_DIR}/*.java)
231
      set(java_dest "lib/java")
232
      set(separator ":")
233 234 235 236 237 238 239 240 241
    endif(WIN32)

    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}
242
              ${JAVA_COMPILE} -cp \".${java_cp_jars}\" ${java_files}
243 244
      COMMAND ${JAVA_ARCHIVE} -cvf ${${java_name}_JAVA_JAR}
             "${XDMF_JAVA_PACKAGE_DIR}/*.class")
245 246 247 248 249 250 251 252 253 254 255
    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}")
    endif(NOT ${ARGN} EQUAL "")

    set_property(DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
      ${CMAKE_BINARY_DIR}/${java_name}.jar
      ${XDMF_JAVA_DIR})
256

257
    set(java_cp_jars "${java_cp_jars}${separator}${${java_name}_JAVA_JAR}")
258 259 260 261 262 263 264
    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)
265
      set(java_cp_jars "${java_cp_jars}" PARENT_SCOPE)
266 267
    endif(NOT "${${java_name}Parent}" STREQUAL "")

268 269 270 271
    install(FILES ${CMAKE_BINARY_DIR}/${java_name}.jar
      DESTINATION lib/java)
    install(TARGETS ${SWIG_MODULE_${java_name}Java_REAL_NAME}
      DESTINATION ${java_dest})
272
  endmacro(XDMF_SWIG_JAVA)
273 274
endif(XDMF_WRAP_JAVA)

275
add_subdirectory(core)
276
include_directories(${XdmfCore_INCLUDE_DIRS} ${XdmfDSM_INCLUDE_DIRS})
277
link_directories(${XDMF_LIBRARY_DIRS})
278

279 280
option(XDMF_BUILD_CORE_ONLY OFF)
if(NOT XDMF_BUILD_CORE_ONLY)
281
  set(XdmfSources
282
    XdmfAggregate
283 284 285 286 287 288 289
    XdmfAttribute
    XdmfAttributeCenter
    XdmfAttributeType
    XdmfCurvilinearGrid
    XdmfDomain
    XdmfGeometry
    XdmfGeometryType
290
    XdmfGraph
291 292 293
    XdmfGrid
    XdmfGridCollection
    XdmfGridCollectionType
294
    XdmfGridController
295
    XdmfGridTemplate
296 297 298 299 300 301 302
    XdmfItemFactory
    XdmfMap
    XdmfReader
    XdmfRectilinearGrid
    XdmfRegularGrid
    XdmfSet
    XdmfSetType
303
    XdmfTemplate
304 305 306 307
    XdmfTime
    XdmfTopology
    XdmfTopologyType
    XdmfUnstructuredGrid)
308

309 310 311 312 313 314 315 316 317
  add_library(XdmfObjects OBJECT ${XdmfSources})
  add_library(Xdmf $<TARGET_OBJECTS:XdmfObjects>)
  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)
318 319
  if(XDMF_BUILD_DSM)
    target_link_libraries(Xdmf XdmfCore XdmfDSM)
320 321 322
    if (BUILD_SHARED_LIBS)
      target_link_libraries(Xdmf_Static XdmfCore_Static XdmfDSM_Static)
    endif (BUILD_SHARED_LIBS)
323 324
  else(XDMF_BUILD_DSM)
    target_link_libraries(Xdmf XdmfCore)
325 326 327
    if (BUILD_SHARED_LIBS)
      target_link_libraries(Xdmf_Static XdmfCore_Static)
    endif (BUILD_SHARED_LIBS)
328
  endif(XDMF_BUILD_DSM)
329 330

  if(WIN32)
331
    set_target_properties(Xdmf PROPERTIES
332
      DEFINE_SYMBOL Xdmf_EXPORTS)
333 334 335 336
    if (BUILD_SHARED_LIBS)
      set_target_properties(Xdmf_Static PROPERTIES
        DEFINE_SYMBOL Xdmf_EXPORTS)
    endif (BUILD_SHARED_LIBS)
337
    if(NOT MSVC10)
338
      set_target_properties(Xdmf PROPERTIES
339 340 341 342 343
        PREFIX ../
        IMPORT_PREFIX ../
        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
        LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
        ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
344 345 346 347 348 349 350 351 352
      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})
      endif (BUILD_SHARED_LIBS)
    endif(NOT MSVC10)
353
   endif(WIN32)
354 355 356 357 358 359

  if(XDMF_WRAP_JAVA)
    XDMF_SWIG_JAVA(Xdmf Compiled_XdmfCore_Jar)
  endif(XDMF_WRAP_JAVA)

  if(XDMF_WRAP_PYTHON)
360 361 362 363 364 365 366 367 368
    if (NOT BUILD_SHARED_LIBS)
      message(FATAL_ERROR "Python Wrappers do not function"
                          " properly without shared libraries")
    endif (NOT BUILD_SHARED_LIBS)
    if (XDMF_BUILD_DSM)
      XDMF_SWIG_PYTHON(Xdmf XdmfCore XdmfDSM)
    else (XDMF_BUILD_DSM)
      XDMF_SWIG_PYTHON(Xdmf XdmfCore)
    endif (XDMF_BUILD_DSM)
369
    set(XDMF_PYTHON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/python/)
370 371 372 373 374 375 376 377 378 379 380
  endif(XDMF_WRAP_PYTHON)

  if(BUILD_TESTING)
    add_subdirectory(tests)
  endif(BUILD_TESTING)

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

381 382 383
  if(WIN32)
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/Xdmf.lib)
  endif(WIN32)
384 385
  
  if(UNIX)
386 387 388 389 390
    if (BUILD_SHARED_LIBS)
      set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmf.so)
    else (BUILD_SHARED_LIBS)
      set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmf.a)
    endif (BUILD_SHARED_LIBS)
391
  endif(UNIX)
392

393 394 395 396
  if(APPLE)
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmf.dylib)
  endif(APPLE)
  
397 398 399 400 401 402 403
  file(GLOB XdmfHeaders 
    "*.hpp" 
    "*.tpp" 
    "*.i" 
    "CMake/VersionSuite/*.hpp"
    "${CMAKE_BINARY_DIR}/*.hpp"
  )
404 405 406 407 408
  install(FILES ${XdmfHeaders} DESTINATION include)
  install(TARGETS Xdmf
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib)
409 410 411 412 413 414
  if (BUILD_SHARED_LIBS)
    install(TARGETS Xdmf_Static
      RUNTIME DESTINATION bin
      LIBRARY DESTINATION lib
      ARCHIVE DESTINATION lib)
  endif (BUILD_SHARED_LIBS)
415
endif(NOT XDMF_BUILD_CORE_ONLY)
416

417
xdmf_create_config_file(${PROJECT_NAME})
418 419
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  DESTINATION ${CMAKE_INSTALL_PREFIX})