CMakeLists.txt 10.2 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)

Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
15
set(BUILD_SHARED_LIBS true)
16
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
17
include_directories(${CMAKE_BINARY_DIR})
18
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
19 20 21 22
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
23

24
include(XdmfFunctions)
25

26 27 28 29 30
# 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)
31

32 33 34
# Should we build with documentation
option(XDMF_BUILD_DOCUMENTATION OFF)
if(XDMF_BUILD_DOCUMENTATION)
35
  add_subdirectory(doc)
36 37
endif(XDMF_BUILD_DOCUMENTATION)

38 39 40
# Enable CMake testing
option(BUILD_TESTING "Build Tests" OFF)
if(BUILD_TESTING)
41 42
  enable_testing()
  include(CTest)
43
endif(BUILD_TESTING)
44

45 46 47 48
# Wrapper Setup
option(XDMF_WRAP_PYTHON OFF)
option(XDMF_WRAP_JAVA OFF)

49 50 51
# Test for DSM
option(XDMF_BUILD_DSM OFF)

52 53 54 55
if(XDMF_BUILD_DSM)
  option(XDMF_BUILD_DSM_THREADS ON)
endif(XDMF_BUILD_DSM)

56 57
# If we are wrapping either, we need swig
if(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
58 59 60 61 62
  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)
63 64 65 66
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)
67 68
  find_package(PythonInterp REQUIRED)
  find_package(PythonLibs REQUIRED)
69 70 71 72 73
  if (XDMF_BUILD_DSM)
    include_directories(${PYTHON_INCLUDE_DIRS} ${MPI_CXX_INCLUDE_PATH})
  else (XDMF_BUILD_DSM)
    include_directories(${PYTHON_INCLUDE_DIRS})
  endif (XDMF_BUILD_DSM)
74 75 76 77 78 79 80 81

  # 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:
82 83
  #     Target Name = the output target name will have ${python_name} as its name
  macro(XDMF_SWIG_PYTHON python_name)
84
    set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
85 86
    # optimize swig generation --- these are all flags corresponding to -O
    # except -fvirtual which breaks visitor operation
87
    set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -modern -fastdispatch -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone)
88 89 90 91
    #Enables DSM
    if (XDMF_BUILD_DSM)
      set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -DXDMF_BUILD_DSM)
    endif (XDMF_BUILD_DSM)
92
    set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
93
    set(swig_extra_generated_files "")
94 95 96 97
    swig_add_module(${python_name} python ${python_name}.i)
    swig_link_libraries(${python_name} ${python_name} ${PYTHON_LIBRARIES})
    set_property(DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
98 99
      ${CMAKE_BINARY_DIR}/${python_name}.pyc
    )
100 101 102 103 104 105

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

    if(WIN32)
106 107 108 109 110 111 112 113 114
	  if(NOT MSVC10)
        set_target_properties(${SWIG_MODULE_${python_name}_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)
115 116
    endif(WIN32)

117 118 119 120 121 122 123 124 125
    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 "")

126 127 128 129
    install(FILES ${CMAKE_BINARY_DIR}/${python_name}.py
      DESTINATION lib/python)
    install(TARGETS ${SWIG_MODULE_${python_name}_REAL_NAME}
      DESTINATION lib/python)
130
  endmacro(XDMF_SWIG_PYTHON)
131 132 133 134
endif(XDMF_WRAP_PYTHON)

# If we are wrapping java, let's include it in the top level
if(XDMF_WRAP_JAVA)
135 136 137 138 139 140 141 142 143 144 145 146 147
  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:
148 149 150
  #     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)
151 152 153 154
    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})
155
    set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -v -make_default -package mil.army.arl.xdmf)
156
    set_source_files_properties(${java_name}.i PROPERTIES CPLUSPLUS ON)
157
    set(swig_extra_generated_files "")
158 159 160 161
    swig_add_module(${java_name}Java java ${java_name}.i)
    swig_link_libraries(${java_name}Java ${java_name})

    if(WIN32)
162 163 164 165 166 167 168 169 170
	  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)
171
      set(java_files *.java)
172
      set(java_dest "bin")
173
      set(separator "\;")
174
    else(WIN32)
175
      set(java_files ${XDMF_JAVA_DIR}/*.java)
176
      set(java_dest "lib/java")
177
      set(separator ":")
178 179 180 181 182 183 184 185 186
    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}
187
              ${JAVA_COMPILE} -cp \".${java_cp_jars}\" ${java_files}
188 189
      COMMAND ${JAVA_ARCHIVE} -cvf ${${java_name}_JAVA_JAR}
             "${XDMF_JAVA_PACKAGE_DIR}/*.class")
190 191 192 193 194 195 196 197 198 199 200
    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})
201

202
    set(java_cp_jars "${java_cp_jars}${separator}${${java_name}_JAVA_JAR}")
203 204 205 206 207 208 209
    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)
210
      set(java_cp_jars "${java_cp_jars}" PARENT_SCOPE)
211 212
    endif(NOT "${${java_name}Parent}" STREQUAL "")

213 214 215 216
    install(FILES ${CMAKE_BINARY_DIR}/${java_name}.jar
      DESTINATION lib/java)
    install(TARGETS ${SWIG_MODULE_${java_name}Java_REAL_NAME}
      DESTINATION ${java_dest})
217
  endmacro(XDMF_SWIG_JAVA)
218 219
endif(XDMF_WRAP_JAVA)

220
add_subdirectory(core)
221
include_directories(${XdmfCore_INCLUDE_DIRS} ${XdmfDSM_INCLUDE_DIRS})
222
link_directories(${XDMF_LIBRARY_DIRS})
223

224 225
option(XDMF_BUILD_CORE_ONLY OFF)
if(NOT XDMF_BUILD_CORE_ONLY)
226 227 228 229 230 231 232 233
  set(XdmfSources
    XdmfAttribute
    XdmfAttributeCenter
    XdmfAttributeType
    XdmfCurvilinearGrid
    XdmfDomain
    XdmfGeometry
    XdmfGeometryType
234
    XdmfGraph
235 236 237 238 239 240 241 242 243 244 245 246 247 248
    XdmfGrid
    XdmfGridCollection
    XdmfGridCollectionType
    XdmfItemFactory
    XdmfMap
    XdmfReader
    XdmfRectilinearGrid
    XdmfRegularGrid
    XdmfSet
    XdmfSetType
    XdmfTime
    XdmfTopology
    XdmfTopologyType
    XdmfUnstructuredGrid)
249

250
  add_library(Xdmf ${XdmfSources})
251 252 253 254 255
  if(XDMF_BUILD_DSM)
    target_link_libraries(Xdmf XdmfCore XdmfDSM)
  else(XDMF_BUILD_DSM)
    target_link_libraries(Xdmf XdmfCore)
  endif(XDMF_BUILD_DSM)
256 257

  if(WIN32)
258 259 260 261 262 263 264 265 266 267 268
	set_target_properties(Xdmf PROPERTIES
      DEFINE_SYMBOL Xdmf_EXPORTS)
    if(NOT MSVC10)
	  set_target_properties(Xdmf 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)
   endif(WIN32)
269 270 271 272 273 274

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

  if(XDMF_WRAP_PYTHON)
275
    XDMF_SWIG_PYTHON(Xdmf XdmfCore XdmfDSM)
276 277 278 279 280 281 282 283 284 285 286
  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)

287 288 289
  if(WIN32)
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/Xdmf.lib)
  endif(WIN32)
290 291 292 293
  
  if(UNIX)
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmf.so)
  endif(UNIX)
294

295 296 297 298
  if(APPLE)
    set(XDMF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libXdmf.dylib)
  endif(APPLE)
  
299 300 301 302 303 304 305
  file(GLOB XdmfHeaders 
    "*.hpp" 
    "*.tpp" 
    "*.i" 
    "CMake/VersionSuite/*.hpp"
    "${CMAKE_BINARY_DIR}/*.hpp"
  )
306 307 308 309 310
  install(FILES ${XdmfHeaders} DESTINATION include)
  install(TARGETS Xdmf
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib)
311
endif(NOT XDMF_BUILD_CORE_ONLY)
312

313
xdmf_create_config_file(${PROJECT_NAME})
314 315
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  DESTINATION ${CMAKE_INSTALL_PREFIX})