CMakeLists.txt.tmpl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. ################################################################################
  2. # CMake configuration file for building LPJ-GUESS
  3. #
  4. # To build LPJ-GUESS with this build system cmake needs to be installed.
  5. # If it's not installed it can be downloaded for free from www.cmake.org.
  6. #
  7. cmake_minimum_required(VERSION 2.8)
  8. if (UNIX)
  9. set(CMAKE_Fortran_COMPILER "[[[PLT:ACTIVE:FC]]]")
  10. endif(UNIX)
  11. project(guess)
  12. set (GRID "T255" CACHE STRING "Grid <T159/T255>")
  13. if (GRID MATCHES "T255")
  14. add_definitions(-DGRID_T255)
  15. elseif (GRID MATCHES "T159")
  16. add_definitions(-DGRID_T159)
  17. else()
  18. exit(-1)
  19. endif()
  20. # Compiler flags for building with Microsoft Visual C++
  21. if (MSVC)
  22. # Disable warnings about using secure functions like sprintf_s instead of
  23. # regular sprintf etc.
  24. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
  25. endif()
  26. # The following are configuration variables for the build.
  27. # Rather than editing them here, you should either edit them
  28. # in the graphical cmake tools (cmake-gui on Windows, ccmake
  29. # on Unix) or pass them in as parameters to cmake.
  30. if (UNIX)
  31. enable_language(Fortran)
  32. endif(UNIX)
  33. # A variable controlling whether or not to include unit tests
  34. # Unit tests are disabled in old VS 6.0, since CATCH doesn't compile in such
  35. # an old compiler.
  36. if (NOT MSVC_VERSION EQUAL "1200")
  37. set(UNIT_TESTS "OFF" CACHE BOOL "Whether to include unit tests")
  38. endif()
  39. if (UNIX)
  40. # Setup the SYSTEM variable, currently only used to choose which
  41. # submit.sh to generate (for submitting to job queue)
  42. # Figure out what value it should have initially, based on the
  43. # environment variable ARCH if it's set.
  44. if (NOT $ENV{ARCH} STREQUAL "")
  45. set(DEFAULT_SYSTEM $ENV{ARCH})
  46. else()
  47. set(DEFAULT_SYSTEM "")
  48. endif()
  49. set(SYSTEM ${DEFAULT_SYSTEM} CACHE STRING "System to build for (empty (=simba), gimle, platon, alarik or multicore)")
  50. endif (UNIX)
  51. # Where to search for cmake modules
  52. # (used by cmake when the include() command is used in a cmake file)
  53. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
  54. # NetCDF - look for libraries and include files, and use them if found
  55. find_package(NetCDF QUIET)
  56. # NB! Adding the following line to .bashrc helps cmake to find the netcdf files:
  57. # export CMAKE_PREFIX_PATH=/software/apps/netcdf/4.3.2/i1402-hdf5-1.8.14/
  58. if (NETCDF_FOUND)
  59. # Windows version:
  60. # include_directories(${NETCDF_INCLUDE_DIRS})
  61. # Unix version:
  62. if (UNIX)
  63. include_directories(${NETCDF_INCLUDE_DIRS}
  64. ${guess_SOURCE_DIR}/../oasis3-mct/ecconf/build/lib/psmile.MPI1)
  65. else()
  66. include_directories(${NETCDF_INCLUDE_DIRS})
  67. endif(UNIX)
  68. set(LIBS ${LIBS} ${NETCDF_LIBRARIES})
  69. add_definitions(-DHAVE_NETCDF)
  70. # Unix only:
  71. if (UNIX)
  72. link_directories(${guess_SOURCE_DIR}/../oasis3-mct/ecconf/lib
  73. ${NETCDF_INCLUDE_DIRS}/../lib)
  74. set(LIBS ${LIBS} psmile.MPI1 mct mpeu scrip netcdf netcdff)
  75. endif (UNIX)
  76. else()
  77. include_directories([[[PLT:ACTIVE:NETCDF_BASE_DIR]]]/[[[PLT:ACTIVE:NETCDF_INC_SUBDIR]]]
  78. ${guess_SOURCE_DIR}/../oasis3-mct/ecconf/build/lib/psmile.MPI1)
  79. link_directories(${guess_SOURCE_DIR}/../oasis3-mct/ecconf/lib
  80. [[[PLT:ACTIVE:NETCDF_BASE_DIR]]]/[[[PLT:ACTIVE:NETCDF_LIB_SUBDIR]]]
  81. ${guess_SOURCE_DIR}/../oasis3-mct/ecconf/build/lib/psmile.MPI1)
  82. add_definitions(-DHAVE_NETCDF)
  83. set(LIBS ${LIBS} psmile.MPI1 mct mpeu scrip
  84. [[[PLT:ACTIVE:NETCDF_LIBS_WITHOUT_L]]])
  85. endif()
  86. # MPI - used if found (not needed on Windows)
  87. if (NOT CMAKE_HOST_WIN32)
  88. find_package(MPI QUIET)
  89. endif()
  90. # These are deprecated according to documentation in the FindMPI module,
  91. # but for some reason not hidden. Let's not display them for the typical
  92. # LPJ-GUESS user who hasn't got MPI installed.
  93. mark_as_advanced(MPI_LIBRARY MPI_EXTRA_LIBRARY)
  94. if (MPI_FOUND)
  95. include_directories(${MPI_INCLUDE_PATH})
  96. set(LIBS ${LIBS} ${MPI_LIBRARIES})
  97. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
  98. # The following is needed because the 3 lines above assume that, if
  99. # MPI_FOUND, ${MPI_INCLUDE_PATH} and ${MPI_LIBRARIES} and
  100. # ${MPI_COMPILE_FLAGS} are defined. This is not necessarily the case, for
  101. # example on the CRAY at cca.
  102. include_directories([[[PLT:ACTIVE:MPI_BASE_DIR]]]/[[[PLT:ACTIVE:MPI_INC_SUBDIR]]])
  103. link_directories([[[PLT:ACTIVE:MPI_BASE_DIR]]]/[[[PLT:ACTIVE:MPI_LIB_SUBDIR]]])
  104. set(LIBS ${LIBS} [[[PLT:ACTIVE:MPI_LIBS_WITHOUT_L]]])
  105. add_definitions(-DHAVE_MPI)
  106. else()
  107. include_directories([[[PLT:ACTIVE:MPI_BASE_DIR]]]/[[[PLT:ACTIVE:MPI_INC_SUBDIR]]])
  108. link_directories([[[PLT:ACTIVE:MPI_BASE_DIR]]]/[[[PLT:ACTIVE:MPI_LIB_SUBDIR]]])
  109. add_definitions(-DHAVE_MPI)
  110. set(LIBS ${LIBS} [[[PLT:ACTIVE:MPI_LIBS_WITHOUT_L]]])
  111. endif()
  112. # Where the compiler should search for header files
  113. include_directories(${guess_SOURCE_DIR}/framework
  114. ${guess_SOURCE_DIR}/libraries/gutil ${guess_SOURCE_DIR}/libraries/plib
  115. ${guess_SOURCE_DIR}/libraries/guessnc ${guess_SOURCE_DIR}/modules ${guess_SOURCE_DIR}/cru/guessio)
  116. # The following directories contain source code and
  117. # additional CMakeLists.txt files
  118. add_subdirectory(framework)
  119. add_subdirectory(modules)
  120. add_subdirectory(cru)
  121. add_subdirectory(libraries)
  122. if (UNIT_TESTS)
  123. add_subdirectory(tests)
  124. endif()
  125. # Add the command line program's target
  126. if (GRID MATCHES "T255")
  127. if (WIN32)
  128. # Let the exe be called guesscmd so it doesn't collide with the dll target
  129. set(guess_command_name "guesscmd_T255")
  130. else()
  131. # On Unix we don't have the dll so the command line binary can be called guess
  132. set(guess_command_name "guess_T255")
  133. endif()
  134. elseif(GRID MATCHES "T159")
  135. if (WIN32)
  136. # Let the exe be called guesscmd so it doesn't collide with the dll target
  137. set(guess_command_name "guesscmd_T159")
  138. else()
  139. # On Unix we don't have the dll so the command line binary can be called guess
  140. set(guess_command_name "guess_T159")
  141. endif()
  142. endif()
  143. # Specify the executable to build, and which sources to build it from
  144. add_executable(${guess_command_name} ${guess_sources} command_line_version/main.cpp)
  145. # Rule for building the unit test binary
  146. if (UNIT_TESTS)
  147. add_executable(runtests ${guess_sources} ${test_sources})
  148. endif()
  149. # Specify libraries to link to the executable
  150. target_link_libraries(${guess_command_name} ${LIBS})
  151. if (WIN32)
  152. # Create guess.dll (used with the graphical Windows shell)
  153. add_library(guess SHARED ${guess_sources} windows_version/dllmain.cpp)
  154. # Specify libraries to link to the dll
  155. target_link_libraries(guess ${LIBS})
  156. endif (WIN32)
  157. # The custom build rule for generating the submit script from a template.
  158. # The submit script is generated each time the command line binary is built.
  159. # Removed in EC-Earth branch!
  160. # Rule for running unit tests automatically
  161. if (UNIT_TESTS)
  162. add_custom_command(TARGET runtests
  163. POST_BUILD
  164. COMMAND runtests
  165. COMMENT "Running tests")
  166. endif()
  167. if (UNIX)
  168. # pgCC 6 doesn't seem to recognize -rdynamic, so remove it
  169. # (we shouldn't need it anyway)
  170. # It seems the CMake developers have fixed this in newer versions
  171. # (sometime after 2.8)
  172. SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  173. SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  174. endif(UNIX)
  175. if (UNIX)
  176. # Set default build type to Release on Unix
  177. if(NOT CMAKE_BUILD_TYPE)
  178. set(CMAKE_BUILD_TYPE Release CACHE STRING
  179. "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
  180. FORCE)
  181. endif(NOT CMAKE_BUILD_TYPE)
  182. endif(UNIX)