-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
136 lines (115 loc) · 4.49 KB
/
CMakeLists.txt
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
132
133
134
135
136
#
# vic2d CMake config file
#
PROJECT ( vic2d )
CMAKE_MINIMUM_REQUIRED ( VERSION 2.8.12 )
ENABLE_LANGUAGE (Fortran)
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
IF (NOT CMAKE_BUILD_TYPE)
SET (CMAKE_BUILD_TYPE "Release")
ENDIF ()
SET (CMAKE_BUILD_TYPE "Release" CACHE STRING "Select which configuration to build")
SET (CMAKE_INSTALL_PREFIX CACHE PATH "Installation location for binaries, sample inputs, and licenses")
SET (USE_OMP FALSE CACHE BOOL "Use OpenMP multithreading")
SET (CMAKE_VERBOSE_MAKEFILE on)
SET (CMAKE_EXPORT_COMPILE_COMMANDS on)
IF( NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE "Release" )
ENDIF()
IF (CMAKE_COMPILER_IS_GNUCXX)
SET (CMAKE_C_FLAGS "-Wall -Wformat -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-O0 -funroll-loops -ffast-math -g -ggdb -fbounds-check")
SET (CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -ffast-math -fomit-frame-pointer")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -funroll-loops -ffast-math -fomit-frame-pointer -g -ggdb3")
SET (CMAKE_Fortran_FLAGS "-Wall -ffree-line-length-none -Wextra -fno-frontend-optimize")
SET (CMAKE_Fortran_FLAGS_DEBUG "-O0 -funroll-loops -ffast-math -g -ggdb -fbounds-check")
SET (CMAKE_Fortran_FLAGS_RELEASE "-O2 -funroll-loops -ffast-math -fomit-frame-pointer")
SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O2 -funroll-loops -ffast-math -fomit-frame-pointer -g -ggdb3")
IF(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
ENDIF ()
ELSEIF (CMAKE_C_COMPILER_ID STREQUAL "Clang")
SET (CMAKE_C_FLAGS "-Wall -Wformat -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb")
SET (CMAKE_C_FLAGS_RELEASE "-O3")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -ggdb")
ELSEIF (MSVC)
SET (CMAKE_C_FLAGS "/Ox")
ENDIF ()
# suppress the FindOpenMP warnings
cmake_policy(SET CMP0054 NEW)
# allow -flto with static libraries
# https://stackoverflow.com/questions/39236917/using-gccs-link-time-optimization-with-static-linked-libraries
#SET(CMAKE_AR "gcc-ar")
#SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
#SET(CMAKE_C_ARCHIVE_FINISH true)
IF ( WIN32 )
SET ( PLATFORM_LIBS ${FRAMEWORK_LIBS} )
# OpenMP for multithreading
IF( USE_OMP )
FIND_PACKAGE (OpenMP REQUIRED)
IF (OPENMP_FOUND)
#MESSAGE ("OPENMP FOUND")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
ENDIF ()
ENDIF()
SET( EXTERNAL_LIBS png z )
ELSEIF ( APPLE )
INCLUDE_DIRECTORIES ( /System/Library/Frameworks )
FIND_LIBRARY (COCOA_LIBRARY Cocoa)
FIND_LIBRARY (IOKIT_LIBRARY IOKit)
MARK_AS_ADVANCED (COCOA_LIBRARY IOKIT_LIBRARY)
SET (PLATFORM_LIBS ${FRAMEWORK_LIBS} ${COCOA_LIBRARY} ${IOKIT_LIBRARY})
# OpenMP for multithreading
IF( USE_OMP )
FIND_PACKAGE (OpenMP REQUIRED)
IF (OPENMP_FOUND)
#MESSAGE ("OPENMP FOUND")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
ENDIF ()
ENDIF()
ELSEIF ( UNIX )
# OpenMP for multithreading
IF( USE_OMP )
FIND_PACKAGE( OpenMP REQUIRED )
IF( OPENMP_FOUND )
#message("OPENMP FOUND")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_C_FLAGS}")
ENDIF()
ELSE()
# suppress the warning
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas")
# need to find pthreads (for std::async?)
FIND_PACKAGE( Threads REQUIRED )
ENDIF()
SET( EXTERNAL_LIBS png z )
ENDIF ()
INCLUDE_DIRECTORIES ( "src" )
ADD_DEFINITIONS (${CPREPROCDEFS})
FILE(GLOB HEADERS "src/*.h" )
SET(LIBSRCS2D ${HEADERS}
"src/libvicmoc2d.c"
"src/gr2.f"
"src/utility.c"
"src/maskops.c"
"src/mud2sp_extern.c"
"src/mud2sp_full.f" )
SET(SRCS2D ${HEADERS}
"src/vic2d.c"
"src/particles.c"
"src/inout.c" )
SET(LIBSRCS3D ${HEADERS}
"src/libvicmoc3d.c"
"src/gr3.f"
"src/utility.c"
"src/mud3sp.f" )
# targets
ADD_LIBRARY ( "vicmoc2d" STATIC ${LIBSRCS2D} )
ADD_EXECUTABLE ( "vic2d" ${SRCS2D} )
TARGET_LINK_LIBRARIES( "vic2d" "vicmoc2d" ${EXTERNAL_LIBS} )
ADD_LIBRARY ( "vicmoc3d" STATIC ${LIBSRCS3D} )