CMakeLists.txt 13.2 KB
Newer Older
Cédric Lachat's avatar
Cédric Lachat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
##  Copyright 2009-2016 Inria
##
## This file is part of the PaMPA software package for parallel
## mesh partitioning and adaptation.
##
## PaMPA is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## any later version.
## 
## PaMPA is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## In this respect, the user's attention is drawn to the risks associated
## with loading, using, modifying and/or developing or reproducing the
## software by the user in light of its specific status of free software,
## that may mean that it is complicated to manipulate, and that also
## therefore means that it is reserved for developers and experienced
## professionals having in-depth computer knowledge. Users are therefore
## encouraged to load and test the software's suitability as regards
## their requirements in conditions enabling the security of their
## systems and/or data to be ensured and, more generally, to use and
## operate it in the same conditions as regards security.
## 
## The fact that you are presently reading this means that you have had
## knowledge of the GPLv3 license and that you accept its terms.
##
#############################################################
##
##    \file        CMakeLists.txt
##
##    \authors     Cedric Lachat
##
##    \brief       This file is main configuration file
##                 to build PaMPA with CMake
##
##    \date        Version 1.0: from: 31 May 2011
##                              to:    4 Oct 2016
##
#############################################################





########################
#  Main configuration  #
########################

if (DEFINED ENV{JENKINS})
  set(CMAKE_BUILD_TYPE $ENV{BUILD} CACHE STRING "toto" FORCE)
endif ()


cmake_minimum_required(VERSION 2.6.4)
if (NOT DEFINED FORTRAN_INTERFACE)
endif ()
if (FORTRAN_INTERFACE)
endif ()
if ((NOT DEFINED FORTRAN_INTERFACE) OR (FORTRAN_INTERFACE))
  project(PAMPA C Fortran CXX)
else ()
  project(PAMPA C)
  #project(PAMPA C CXX) # XXX XXX à remettre
endif ()

# Add CTest
enable_testing()

# Add modules
include(CMakeDependentOption)
include(CheckSymbolExists)


set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeScripts)
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/MOD)

# Define some variables which will be fill in with ccmake or cmake-gui
set(VALGRIND_EXE "/usr/bin/valgrind" CACHE TYPE "Valgrind with its path")
set(VALGRIND_ARGS "" CACHE TYPE "Valgrind arguments")
mark_as_advanced(VALGRIND_EXE VALGRIND_ARGS)

option(FORTRAN_INTERFACE "Build fortran interface to use PaMPA in fortran programs" OFF)
if (FORTRAN_INTERFACE)
  add_definitions (-DNOT_DOXYGEN)
endif ()

set (PTHREAD_LIST "None;IO;Comm;All")
set (PTHREAD "All" CACHE STRING "Pthread use level: possible values ${PTHREAD_LIST}")
set_property (CACHE PTHREAD PROPERTY STRINGS ${PTHREAD_LIST})
list (FIND PTHREAD_LIST ${PTHREAD} FND)

if (${FND} EQUAL -1)
  message (FATAL_ERROR "Value for PTHREAD is not correct, you have to choose one item in the following list ${PTHREAD_LIST}")
endif ()


set (COMM_TYPE_LIST "Automatic;Point-to-point;Collective")
set (COMM_TYPE "Point-to-point" CACHE STRING "Communication type chosen to exhange data between subdomains: possible values ${COMM_TYPE_LIST}")
set_property (CACHE COMM_TYPE PROPERTY STRINGS ${COMM_TYPE_LIST})
list (FIND COMM_TYPE_LIST ${COMM_TYPE} FND)

if (${FND} EQUAL -1)
  message (FATAL_ERROR "Value for COMM_TYPE is not correct, you have to choose one item in the following list ${COMM_TYPE_LIST}")
endif ()

if (COMM_TYPE STREQUAL "Point-to-point")
  add_definitions (-DPAMPA_COMM_PTOP)
elseif (COMM_TYPE STREQUAL "Collective")
  add_definitions (-DPAMPA_COMM_COLL)
endif ()

set (INT_SIZE_LIST "Default;32bits;64bits;long")
set (INT_SIZE "Default" CACHE STRING "Integer size for PAMPA_Num and PAMPAF_Num, you have to choose one item between ${INT_SIZE_LIST}")
set_property (CACHE INT_SIZE PROPERTY STRINGS ${INT_SIZE_LIST})
list (FIND INT_SIZE_LIST ${INT_SIZE} FND)

if (${FND} EQUAL -1)
  message (FATAL_ERROR "Value for INT_SIZE is not correct, you have to choose one item in the following list ${INT_SIZE_LIST}")
endif ()

if (INT_SIZE STREQUAL "32bits")
  add_definitions (-DINTSIZE32)
elseif (INT_SIZE STREQUAL "64bits")
  add_definitions (-DINTSIZE64)
elseif (INT_SIZE STREQUAL "long")
  add_definitions (-DLONG)
endif ()

132
option(PAMPA_ADAPT "Adapt functions" OFF)
Cédric Lachat's avatar
Cédric Lachat committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
if (PAMPA_ADAPT)
  add_definitions (-DPAMPA_ADAPT)
endif ()

option(PAMPA_MULTILEVEL "Multilevel meshes" OFF)

option(PAMPA_RENAME "Rename internal function names" ON)
if (PAMPA_RENAME)
  add_definitions (-DPAMPA_RENAME)
endif ()

option(COMMON_MEMORY_TRACE "In-house memory usage tracing" OFF)
if (COMMON_MEMORY_TRACE)
  add_definitions (-DCOMMON_MEMORY_TRACE)
endif ()

cmake_dependent_option(COMMON_MEMORY_USER_FILE "User file (defined as char PAMPA_memFilename[]) for memory logs" OFF "COMMON_MEMORY_TRACE" OFF)
if (COMMON_MEMORY_USER_FILE)
  add_definitions (-DCOMMON_MEMORY_USER_FILE)
endif ()

option(SAMPLES "Build samples" ON)
if (SAMPLES)
  set (SAMPLE_TYPE_LIST "All;Compounds;Units")
  set (SAMPLE_TYPE "All" CACHE STRING "Choose which categories of samples: possible values ${SAMPLE_TYPE_LIST}")
  set_property (CACHE SAMPLE_TYPE PROPERTY STRINGS ${SAMPLE_TYPE_LIST})
  list (FIND SAMPLE_TYPE_LIST ${SAMPLE_TYPE} FND)

  if (${FND} EQUAL -1)
    message (FATAL_ERROR "Value for SAMPLE_TYPE is not correct, you have to choose one item in the following list ${SAMPLE_TYPE_LIST}")
  endif ()

  set (SAMPLE_PREFIX "pampa")
endif ()

if (EXISTS ${PAMPA_SOURCE_DIR}/doc/CMakeLists.txt)
  option(PAMPA_BUILD_DOC "Build documentation for PaMPA" OFF)
  mark_as_advanced(PAMPA_BUILD_DOC)
endif()
option(PAMPA_BUILD_ALONE "Build PaMPA in one build folder" OFF)
mark_as_advanced(PAMPA_BUILD_ALONE)
#######################
# Find some libraries #
#######################


if (COMMON_COMPRESSION)
  # BZIP2
  find_package (BZip2)
  if (BZIP2_FOUND)
    add_definitions (-DCOMMON_FILE_COMPRESS_BZ2)
    include_directories(${BZIP2_INCLUDE_DIR})
    list (APPEND PAMPA_DEPENDENCIES ${BZIP2_LIBRARY} ${BZIP2_LIBRARIES})
  endif (BZIP2_FOUND)
  ## LZMA
  #find_package (LibLZMA)
  #if (LibLZMA_FOUND)
  #  add_definitions (-DCOMMON_FILE_COMPRESS_LZMA)
  #  include_directories(${LibLZMA_INCLUDE_DIR})
  #  list (APPEND PAMPA_DEPENDENCIES ${LibLZMA_LibRARIES})
  #endif (LibLZMA_FOUND)
  # ZLIB
  find_package (ZLIB)
  if (ZLIB_FOUND)
    add_definitions (-DCOMMON_FILE_COMPRESS_GZ)
    include_directories(${ZLIB_INCLUDE_DIR})
    list (APPEND PAMPA_DEPENDENCIES ${ZLIB_LIBRARIES})
  endif (ZLIB_FOUND)
endif (COMMON_COMPRESSION)


# PT-Scotch
option (PTSCOTCH "Build PaMPA with PT-Scotch dependencies" ON)
if (PTSCOTCH)
  add_definitions (-DPTSCOTCH)
  set(PTSCOTCH_HOME "" CACHE PATH "PT-Scotch home directory")
  find_package(PTSCOTCH REQUIRED)

  file(STRINGS "${PTSCOTCH_INCLUDE_DIR}/scotch.h" CHECK_SCOTCH_VERSION REGEX "^[ \t]*#define[ \t]+SCOTCH_[A-Z]+[ \t]+[0-9]+.*$")

  foreach(item IN ITEMS VERSION RELEASE PATCHLEVEL)
    string(REGEX REPLACE ".*#define[ \t]+SCOTCH_${item}[ \t]+([0-9]+).*" "\\1" XYZ ${CHECK_SCOTCH_VERSION})
    set (SCOTCH_${item} ${XYZ})
  endforeach()
  # XXX uncomment this test when Scotch 6.0.4 will be available
  #if (${SCOTCH_VERSION}.${SCOTCH_RELEASE}.${SCOTCH_PATCHLEVEL} VERSION_LESS 6.0.4)
  #  message (FATAL_ERROR "PT-Scotch version must be greater than or equal to 6.0.4")
  #endif ()
  include_directories(${PTSCOTCH_INCLUDE_DIR})
else ()
  unset (PTSCOTCH_HOME CACHE)
endif  ()


# MPI
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
if (MPI_C_LIBRARIES)
  list (APPEND PAMPA_DEPENDENCIES ${MPI_C_LIBRARIES} m)
else ()
  list (APPEND PAMPA_DEPENDENCIES ${MPI_LIBRARIES} m)
endif ()
235
set(MPI_COMPILER mpicc)
Cédric Lachat's avatar
Cédric Lachat committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461

if (PAMPA_BUILD_ALONE)
include_directories(${PAMPA_SOURCE_DIR}/include)
endif ()


# Pthread
if (NOT PTHREAD STREQUAL "None")
  find_package(Threads REQUIRED)
  if (NOT CMAKE_USE_PTHREADS_INIT) # if pthread was not found
    message (FATAL_ERROR "Pthread are not available")
  endif()
  if (PTHREAD STREQUAL "IO" OR PTHREAD STREQUAL "All")
    add_definitions(-DCOMMON_PTHREAD)
  endif ()
  if (PTHREAD STREQUAL "Comm" OR PTHREAD STREQUAL "All")
    add_definitions(-DPAMPA_PTHREAD)
  endif ()
  list (APPEND PAMPA_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
endif ()

# Define PaMPA version
set(PAMPA_CORE_VERSION "2")
set(PAMPA_CORE_RELEASE "0")
set(PAMPA_CORE_PATCHLEVEL "0")

# Add some flags
add_definitions(-Drestrict=__restrict)


# Check CMake version
if (${CMAKE_VERSION} VERSION_LESS 2.8.4)
  set (OLD_CMAKE 1)
endif ()
set (LIBRARY_OUTPUT_DIRECTORY ${PAMPA_SOURCE_DIR}/pampa_lib)


# SCM Version Option
option (SCM_VERSIONS "Get SCM Versions for softwares" OFF)
if (SCM_VERSIONS)
  add_definitions(-DSCM_VERSIONS)
  if (PTSCOTCH)
    set(SCM_PTSCOTCH_HOME "" CACHE PATH "SCM PT-Scotch path")
    list(APPEND VERSIONS_EXT_ARGS
      PTSCOTCH:${SCM_PTSCOTCH_HOME}:${PTSCOTCH_LIBRARY},${SCOTCH_LIBRARY},${PTSCOTCH_EXTRA_LIBRARY})
    list(APPEND VERSIONS_EXT_DEPS
      ${PTSCOTCH_LIBRARY} ${SCOTCH_LIBRARY} ${PTSCOTCH_EXTRA_LIBRARY})
  endif  ()
endif ()

option(COMMON_COMPRESSION "Build with founded compression libraries (CMake will search automatically which are availables" ON)


########################
#       tests          #
########################

if (CMAKE_VERSION VERSION_GREATER "2.8.11")
  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test2.c "
  #include <stdio.h>
  #include <stdlib.h>

  #ifdef EXT
  extern
  #endif
  inline void f() {
  }
  ")

  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test.c "
  #include <stdio.h>
  #include <stdlib.h>

  int main() {
  f();
  return 0;
  }
  ")

  try_compile(TEST_INLINE ${CMAKE_CURRENT_BINARY_DIR}/test
    SOURCES ${CMAKE_CURRENT_BINARY_DIR}/test.c ${CMAKE_CURRENT_BINARY_DIR}/test2.c
    )

  if (NOT TEST_INLINE)
    try_compile(TEST_INLINE ${CMAKE_CURRENT_BINARY_DIR}/test2
      SOURCES ${CMAKE_CURRENT_BINARY_DIR}/test.c ${CMAKE_CURRENT_BINARY_DIR}/test2.c
      COMPILE_DEFINITIONS -DEXT
      )
    if (NOT TEST_INLINE)
      message (FATAL_ERROR "internal error")
    else ()
      add_definitions (-DPAMPA_WORD_EXTERN)
    endif ()
  endif ()
else (CMAKE_VERSION VERSION_GREATER "2.8.11")
  if (CMAKE_C_COMPILER MATCHES "gcc") # XXX Is-it just for gcc?
    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test.c "
    #include <stdio.h>
    #include <stdlib.h>

    extern
    inline void f() {
    }

    int main() {
    f();
    return 0;
    }
    ")

    try_compile(TEST_INLINE ${CMAKE_CURRENT_BINARY_DIR}/test
      ${CMAKE_CURRENT_BINARY_DIR}/test.c
      )

    if (TEST_INLINE)
      add_definitions (-DPAMPA_WORD_EXTERN)
    endif ()

  endif (CMAKE_C_COMPILER MATCHES "gcc")
endif (CMAKE_VERSION VERSION_GREATER "2.8.11")

########################
#    libpampa     #
########################

add_subdirectory(${PAMPA_SOURCE_DIR}/src/libpampa)

# Add dependency on PT-Scotch
if (PTSCOTCH)
  list (APPEND PAMPA_DEPENDENCIES ${PTSCOTCH_LIBRARY})
  list (APPEND PAMPA_DEPENDENCIES ${SCOTCH_LIBRARY})
  list (APPEND PAMPA_DEPENDENCIES ${PTSCOTCH_EXTRA_LIBRARY})
endif ()



########################
#        samples       #
########################

if (SAMPLES)
add_subdirectory(${PAMPA_SOURCE_DIR}/src/samples)
endif ()



########################
#        tests         #
########################

# Add target on Unix
if(UNIX)
  add_custom_target(all_and_test COMMAND make all COMMAND ctest --force-new-ctest-process --output-on-failure)
endif(UNIX)





########################
#      real clean      #
########################

if(UNIX)
  if (PAMPA_BUILD_ALONE)
    add_custom_target(realclean
      COMMAND make clean
      COMMAND ${CMAKE_COMMAND} -E remove ${PAMPA_SOURCE_DIR}/include/*
      COMMAND ${CMAKE_COMMAND} -E remove ${PAMPA_SOURCE_DIR}/lib/*
      )
  else ()
    add_custom_target(realclean
      COMMAND make clean
      )
  endif ()
endif(UNIX)

########################
#       install        #
########################




########################
#      uninstall       #
########################

# uninstall target
configure_file(
  "${PAMPA_SOURCE_DIR}/src/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY)

add_custom_target(uninstall
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)






########################
#    documentation     #
########################

if (PAMPA_BUILD_DOC)
  add_subdirectory(${PAMPA_SOURCE_DIR}/doc)
endif ()


##################
#    message     #
##################

message (STATUS "
********************************************************************
*                                                                  *
*      We are very eager to get feed-back from our users!          *
*                                                                  *
*   Please send us an e-mail (pampaATinria.fr) to tell us how      *
*   PaMPA works for you.                                           *
*   It will help us update our roadmap and provide new features.   *
*                                                                  *
********************************************************************
")