123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- ################################################################################
- # CMake configuration file for building LPJ-GUESS
- #
- # To build LPJ-GUESS with this build system cmake needs to be installed.
- # If it's not installed it can be downloaded for free from www.cmake.org.
- #
- cmake_minimum_required(VERSION 2.8)
- if (UNIX)
- set(CMAKE_Fortran_COMPILER "mpif90")
- endif(UNIX)
- project(guess)
- #select grid resolution
- #set (GRID "T255" CACHE STRING "Grid <T159/T255>")
- set (GRID T255)
- if (GRID MATCHES "T255")
- add_definitions(-DGRID_T255)
- elseif (GRID MATCHES "T159")
- add_definitions(-DGRID_T159)
- else()
- exit(-1)
- endif()
- # should we compress output?
- set(COMPRESS_OUTPUT true)
- if(COMPRESS_OUTPUT)
- set(LIBS ${LIBS} z)
- add_definitions(-DCOMPRESS_OUTPUT)
- message(STATUS "Output compression has been enabled.")
- endif(COMPRESS_OUTPUT)
- # Compiler flags for building with Microsoft Visual C++
- if (MSVC)
- # Disable warnings about using secure functions like sprintf_s instead of
- # regular sprintf etc.
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
- endif()
- # The following are configuration variables for the build.
- # Rather than editing them here, you should either edit them
- # in the graphical cmake tools (cmake-gui on Windows, ccmake
- # on Unix) or pass them in as parameters to cmake.
- if (UNIX)
- enable_language(Fortran)
- endif(UNIX)
- # A variable controlling whether or not to include unit tests
- # Unit tests are disabled in old VS 6.0, since CATCH doesn't compile in such
- # an old compiler.
- if (NOT MSVC_VERSION EQUAL "1200")
- set(UNIT_TESTS "OFF" CACHE BOOL "Whether to include unit tests")
- endif()
- if (UNIX)
- # Setup the SYSTEM variable, currently only used to choose which
- # submit.sh to generate (for submitting to job queue)
-
- # Figure out what value it should have initially, based on the
- # environment variable ARCH if it's set.
- if (NOT $ENV{ARCH} STREQUAL "")
- set(DEFAULT_SYSTEM $ENV{ARCH})
- else()
- set(DEFAULT_SYSTEM "")
- endif()
- set(SYSTEM ${DEFAULT_SYSTEM} CACHE STRING "System to build for (empty (=simba), gimle, platon, alarik or multicore)")
- endif (UNIX)
- # Where to search for cmake modules
- # (used by cmake when the include() command is used in a cmake file)
- set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
- # NetCDF - look for libraries and include files, and use them if found
- find_package(NetCDF QUIET)
- # NB! Adding the following line to .bashrc helps cmake to find the netcdf files:
- # export CMAKE_PREFIX_PATH=/software/apps/netcdf/4.3.2/i1402-hdf5-1.8.14/
- if (NETCDF_FOUND)
- # Windows version:
- # include_directories(${NETCDF_INCLUDE_DIRS})
- # Unix version:
- if (UNIX)
- include_directories(${NETCDF_INCLUDE_DIRS}
- ${guess_SOURCE_DIR}/../oasis3-mct/ecconf/build/lib/psmile.MPI1)
- else()
- include_directories(${NETCDF_INCLUDE_DIRS})
- endif(UNIX)
- set(LIBS ${LIBS} ${NETCDF_LIBRARIES})
- add_definitions(-DHAVE_NETCDF)
- # Unix only:
- if (UNIX)
- link_directories(${guess_SOURCE_DIR}/../oasis3-mct/ecconf/lib
- ${NETCDF_INCLUDE_DIRS}/../lib)
- set(LIBS ${LIBS} psmile.MPI1 mct mpeu scrip netcdf netcdff)
- endif (UNIX)
- else()
- include_directories(//$(EBROOTNETCDF)/include $(EBROOTNETCDFMINFORTRAN)/include
- ${guess_SOURCE_DIR}/../oasis3-mct/ecconf/build/lib/psmile.MPI1)
- link_directories(${guess_SOURCE_DIR}/../oasis3-mct/ecconf/lib
- //$(EBROOTNETCDF)/lib64 $(EBROOTNETCDFMINFORTRAN)/lib
- ${guess_SOURCE_DIR}/../oasis3-mct/ecconf/build/lib/psmile.MPI1)
- add_definitions(-DHAVE_NETCDF)
- set(LIBS ${LIBS} psmile.MPI1 mct mpeu scrip
- netcdff netcdf)
- endif()
- # MPI - used if found (not needed on Windows)
- if (NOT CMAKE_HOST_WIN32)
- find_package(MPI QUIET)
- endif()
- # These are deprecated according to documentation in the FindMPI module,
- # but for some reason not hidden. Let's not display them for the typical
- # LPJ-GUESS user who hasn't got MPI installed.
- mark_as_advanced(MPI_LIBRARY MPI_EXTRA_LIBRARY)
- if (MPI_FOUND)
- include_directories(${MPI_INCLUDE_PATH})
- set(LIBS ${LIBS} ${MPI_LIBRARIES})
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
- # The following is needed because the 3 lines above assume that, if
- # MPI_FOUND, ${MPI_INCLUDE_PATH} and ${MPI_LIBRARIES} and
- # ${MPI_COMPILE_FLAGS} are defined. This is not necessarily the case, for
- # example on the CRAY at cca.
- include_directories($(EBROOTIMPI)/mpi/latest/include)
- link_directories($(EBROOTIMPI)/mpi/latest/lib)
- set(LIBS ${LIBS} mpi mpifort)
- add_definitions(-DHAVE_MPI)
- else()
- include_directories($(EBROOTIMPI)/mpi/latest/include)
- link_directories($(EBROOTIMPI)/mpi/latest/lib)
- add_definitions(-DHAVE_MPI)
- set(LIBS ${LIBS} mpi mpifort)
- endif()
- # Where the compiler should search for header files
- include_directories(${guess_SOURCE_DIR}/framework
- ${guess_SOURCE_DIR}/libraries/gutil ${guess_SOURCE_DIR}/libraries/plib
- ${guess_SOURCE_DIR}/libraries/guessnc ${guess_SOURCE_DIR}/modules ${guess_SOURCE_DIR}/cru/guessio)
- # The following directories contain source code and
- # additional CMakeLists.txt files
- add_subdirectory(framework)
- add_subdirectory(modules)
- add_subdirectory(cru)
- add_subdirectory(libraries)
- if (UNIT_TESTS)
- add_subdirectory(tests)
- endif()
- # Add the command line program's target
- if (GRID MATCHES "T255")
- if (WIN32)
- # Let the exe be called guesscmd so it doesn't collide with the dll target
- set(guess_command_name "guesscmd_T255")
- else()
- # On Unix we don't have the dll so the command line binary can be called guess
- set(guess_command_name "guess_T255")
- endif()
- elseif(GRID MATCHES "T159")
- if (WIN32)
- # Let the exe be called guesscmd so it doesn't collide with the dll target
- set(guess_command_name "guesscmd_T159")
- else()
- # On Unix we don't have the dll so the command line binary can be called guess
- set(guess_command_name "guess_T159")
- endif()
- endif()
- # Specify the executable to build, and which sources to build it from
- add_executable(${guess_command_name} ${guess_sources} command_line_version/main.cpp)
- # Rule for building the unit test binary
- if (UNIT_TESTS)
- add_executable(runtests ${guess_sources} ${test_sources})
- endif()
- # Specify libraries to link to the executable
- target_link_libraries(${guess_command_name} ${LIBS})
- if (WIN32)
- # Create guess.dll (used with the graphical Windows shell)
- add_library(guess SHARED ${guess_sources} windows_version/dllmain.cpp)
- # Specify libraries to link to the dll
- target_link_libraries(guess ${LIBS})
- endif (WIN32)
- # The custom build rule for generating the submit script from a template.
- # The submit script is generated each time the command line binary is built.
- # Removed in EC-Earth branch!
- # Rule for running unit tests automatically
- if (UNIT_TESTS)
- add_custom_command(TARGET runtests
- POST_BUILD
- COMMAND runtests
- COMMENT "Running tests")
- endif()
- if (UNIX)
- # pgCC 6 doesn't seem to recognize -rdynamic, so remove it
- # (we shouldn't need it anyway)
- # It seems the CMake developers have fixed this in newer versions
- # (sometime after 2.8)
- SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
- SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
- endif(UNIX)
- if (UNIX)
- # Set default build type to Release on Unix
- if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE Release CACHE STRING
- "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
- FORCE)
- endif(NOT CMAKE_BUILD_TYPE)
- endif(UNIX)
|