CMakeLists.txt 7.4 KB

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