File: CMakeLists.txt

package info (click to toggle)
metview 5.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 44,932 kB
  • sloc: cpp: 211,811; ansic: 33,467; xml: 3,942; sh: 2,942; yacc: 1,183; fortran: 762; lex: 761; perl: 700; python: 340; f90: 236; makefile: 92
file content (234 lines) | stat: -rw-r--r-- 9,603 bytes parent folder | download
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
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

#### NOTE: rpcmars.h rpcmars.c should not be in the distro!!!

# the 'plain' filenames of the MARS source code
set(_libMars_srcs
    tcp.c server.c request.c expand.c
	hash.c memory.c logfile.c options.c
	api.c apibase.c base.c netbase.c netcdf.c hdf5.c nullbase.c fdb5base.cc forwardbase.c
	gribbase.c nfdbbase.c dhsbase.c odb.cc odbbase.c
	multibase.c archive.c retrieve.c ibmblk.c
	lock.c files.c sh2ll.c guess.c hypercube.c
	check.c environ.c
	handler.c target.c grib.c calc.c field.c
	list.c tools.c hidden.c index.c bufr.c
	externf.c service.c xservice.c
	udp.c queue.c variable.c
	filebase.c account.c cos.c pproc.h pproc.cc pproc_none.cc restricted.c
	wind.c control.c stream.c
	remove.c authenticate.c flatfilebase.c time.c timer.c json.c
	version.c statistics.c metadata.c ecaccess.c free.c
	schedule.c

    # add the header files because we use this list to help create the tarball later
	api.h base.h bufr.h control.h cos.h ecaccess.h field.h globals.h grib.h hypercube.h
	ibmblk.h index.h json.h lang.h mars.h mcs.h
	ncmerge.h ncschema.h nctarget.h nctypes.h netbase.h
	netbase.h odb.h proto.h queue.h restricted.h tools.h variable.h 
)


# extra files which will be needed in the tarball
set(extra_files_for_tarball
    ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
    ${MARS_SOURCE}/rpcmars.x
    ${MARS_SOURCE}/langy.y
    ${MARS_SOURCE}/langl.l
    ${MARS_SOURCE}/CMakeLists.txt            # needed for bundle tarball
    ${MARS_SOURCE}/mars_client_version.c.in  # needed for bundle tarball
    ${MARS_SOURCE}/mars_client_version.h.in  # needed for bundle tarball
    ${MARS_SOURCE}/mars_client_config.h.in   # needed for bundle tarball
)    


if( HAVE_PPROC_EMOS )
    list( APPEND _libMars_srcs pproc_emos.cc )
endif()

if( HAVE_PPROC_MIR )
    list( APPEND _libMars_srcs pproc_mir.cc )
endif()

if(HAVE_NETCDF)
  list(APPEND _libMars_srcs
    nctarget.c
    nctypes.c
    ncschema.c
    ncmerge.c
    )
endif()



# add the path to where the source files are located
foreach( file ${_libMars_srcs} )
    list( APPEND libMars_srcs ${MARS_SOURCE}/${file} )
endforeach()


ecbuild_generate_config_headers()
configure_file( ${MARS_SOURCE}/mars_client_config.h.in    mars_client_config.h   )


# get the MARS client version number (just invent it for now since we don't use it)

set(MARS_CLIENT_MAJOR_VERSION 0)
set(MARS_CLIENT_MINOR_VERSION 0)
set(MARS_CLIENT_PATCH_VERSION 0)
configure_file( ${MARS_SOURCE}/mars_client_version.h.in  mars_client_version.h )
configure_file( ${MARS_SOURCE}/mars_client_version.c.in  mars_client_version.c )



# copy all the MARS source files to a subdirectory of the build directory; this is
# so that we have a clean version of the MARS client source code in its own directory
# which can be packaged into the export tarball.
# NO - see code at the end of this file for the real solution
#foreach( file ${libMars_srcs} )
#    get_filename_component( basefile ${file} NAME )
#    configure_file(${file} "${CMAKE_BINARY_DIR}/src/libMarsClient/${basefile}" COPYONLY) # copy to binary dir
#endforeach()

# add the local and generated files - they are not in the MARS source directory
list( APPEND libMars_srcs ${CMAKE_CURRENT_BINARY_DIR}/langy.c ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.c)


if ( NOT FDB_FOUND )
    add_definitions(-DNOFDB)
endif()

if ( NOT HAVE_FDB5 )
    add_definitions(-DNOFDB5)
endif()

find_package(CMath)



# rpcgen, when creating the .c file, has an include for the header file;
# unfortunately, it does not know where the header file has been generated, so it
# assumes it will be in the source directory. This is wrong, it should be the
# binary directory. Therefore, we first copy the .x file to the binary directory
# and work on it there. Note: will this cause a problem with in-source builds?
# If so, we may need to first check whether the file already exists.

if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
    configure_file(${MARS_SOURCE}/rpcmars.x ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.x)
endif()

ADD_CUSTOM_COMMAND(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.h
	COMMAND ${RPCGEN_EXECUTABLE} -h -o ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.h ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.x
    DEPENDS ${MARS_SOURCE}/rpcmars.x)

ADD_CUSTOM_COMMAND(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.c
	COMMAND ${RPCGEN_EXECUTABLE} -c -o ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.c ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.x
    DEPENDS ${MARS_SOURCE}/rpcmars.x)

ADD_CUSTOM_COMMAND(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/langl.c
	COMMAND lex -l ${MARS_SOURCE}/langl.l\; sed -e s/yy/yy_mars/g < lex.yy.c | egrep -v "^#line" > ${CMAKE_CURRENT_BINARY_DIR}/langl.c
    DEPENDS ${MARS_SOURCE}/langl.l)

ADD_CUSTOM_COMMAND(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/langy.c
	COMMAND yacc -t ${MARS_SOURCE}/langy.y\; sed -e s/yy/yy_mars/g < y.tab.c | egrep -v "^#line" > ${CMAKE_CURRENT_BINARY_DIR}/langy.c
    DEPENDS ${MARS_SOURCE}/langy.y)

ADD_CUSTOM_TARGET(mvmarsxdr DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.h ${CMAKE_CURRENT_BINARY_DIR}/rpcmars.c)
ADD_CUSTOM_TARGET(mvmarslex DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/langy.c   ${CMAKE_CURRENT_BINARY_DIR}/langl.c)

###set( libMars_srcs ${libMars_srcs} PARENT_SCOPE )

include_directories(BEFORE   ${CMAKE_CURRENT_BINARY_DIR} ${METVIEW_STANDARD_INCLUDES} ${METVIEW_ODB_API_INCLUDE_DIRS})



if (ODB_API_FOUND)
    set(ODB_FLAG ODB_SUPPORT)
else()
    set(ODB_FLAG NOODB)
endif()


ecbuild_add_library( TARGET      MvMars
                     TYPE        SHARED
		     VERSION     0.0.0
		     SOVERSION   0d
                     GENERATED   mars_client_version.c
                     SOURCES     ${libMars_srcs} mars_client_version.c
                     TEMPLATES   ${common_templates}
                     DEFINITIONS ${METVIEW_EXTRA_DEFINITIONS} ${ODB_FLAG}
                     LIBS        ${MARS_FEATURE_LIBRARIES} ${METVIEW_EXTRA_LIBRARIES} ${METVIEW_ODB_API_LIBRARIES} ${CURL_LIBRARIES}
                     PRIVATE_INCLUDES
                         ${NETCDF_INCLUDE_DIRS}
                         ${MIR_INCLUDE_DIRS}
                    )

# we generate a separate MARS library which is static, hopefully making
# the inline C and Fortran easier to handle (fewer dependencies this way)
# ecbuild_add_library( TARGET      MvMarsStatic
#                      TYPE        STATIC
#                      GENERATED   mars_client_version.c
#                      SOURCES     ${libMars_srcs} mars_client_version.c
#                      TEMPLATES   ${common_templates}
#                      DEFINITIONS ${METVIEW_EXTRA_DEFINITIONS} ${ODB_FLAG}
#                      LIBS        ${MARS_FEATURE_LIBRARIES} ${METVIEW_EXTRA_LIBRARIES} ${METVIEW_ODB_API_LIBRARIES} ${CURL_LIBRARIES}
#                      PRIVATE_INCLUDES
#                          ${NETCDF_INCLUDE_DIRS}
#                          ${MIR_INCLUDE_DIRS}
#                     )
# 
ADD_DEPENDENCIES(MvMars       mvmarsxdr mvmarslex)
# ADD_DEPENDENCIES(MvMarsStatic mvmarsxdr mvmarslex)



if(NOT DEFINED METVIEW_BUNDLE)

    # for the tarball, we want to include the MARS client source, but only the files that we actually
    # use in Metview. So we create a list of all files in the source, then subtract from it the list
    # of source files defined previously as libMars_srcs.

    # first, list all the files in the MARS source directory - these are the files we will NOT pack
    file(GLOB mars_unwanted_src_files   "${MARS_SOURCE}/*")
    file(GLOB mars_unwanted_tools_files "${MARS_SOURCE}/tools/*")
    list(APPEND mars_unwanted_src_files ${mars_unwanted_tools_files})

    # remove each wanted source file from the list
    foreach( file ${libMars_srcs} ${extra_files_for_tarball})
        list(REMOVE_ITEM mars_unwanted_src_files ${file})
    endforeach()

    # these filenames will be treated as regular expressions, so we need to be more
    # explicit and put a dollar sign at the end so that they don't match with too much
    set(mars_real_unwanted_src_files "")
    foreach( file ${mars_unwanted_src_files} )
        list(APPEND mars_real_unwanted_src_files "${file}\$")
    endforeach()

    # add our revised list to ECBUILD_DONT_PACK_FILES
    # - we don't use ecbuild_dont_pack() because it makes everything relative to the
    #   source directory
    list( APPEND ECBUILD_DONT_PACK_FILES ${mars_real_unwanted_src_files})
    set( ECBUILD_DONT_PACK_FILES ${ECBUILD_DONT_PACK_FILES} CACHE INTERNAL "" )

endif()


# soon to be redundant - remove unwanted files from libMars/MARS
# list of files (regular expressions) to exclude from the source tarball
# note "MARS/m$" - the dollar is required because otherwise CPACK will exclude any
# file beginning with an 'm'!
ecbuild_dont_pack(REGEX "MARS/config*")
ecbuild_dont_pack(REGEX "MARS/make*")
ecbuild_dont_pack(FILES "MARS/mars.test;MARS/m$;MARS/gnumake_target;MARS/Makefile;MARS/account_check.c")
ecbuild_dont_pack(FILES "MARS/blk.c;MARS/certify.c;MARS/cpli.h;MARS/cvers.h;MARS/dce.c;MARS/dce.h;MARS/dcebase.c;MARS/dceclient.c")
ecbuild_dont_pack(FILES "MARS/dceremote.c;MARS/dceserver.c;MARS/eccert.c;MARS/eccert.h;MARS/ecopt.h;MARS/emoscycle.c;MARS/extargs.c;")
ecbuild_dont_pack(FILES "MARS/feedtask.c;MARS/gpl-3.0.txt;MARS/grib_api_release.c;MARS/htest.c;MARS/lckfile.c")
ecbuild_dont_pack(FILES "MARS/licence_header;MARS/mars.c;MARS/marsdce.c;MARS/marsdce.h;MARS/marsfdb.c;MARS/marsmon.c;MARS/marsversion.c")
ecbuild_dont_pack(FILES "MARS/mcs.c;MARS/mrpc.x;MARS/msbase.c;MARS/multidef.c;MARS/multidef.h;MARS/ocean.c")
ecbuild_dont_pack(FILES "MARS/rdb.c;MARS/reqmerge.c;MARS/source.c;MARS/source.h;MARS/test.c;MARS/testh.c;MARS/teststats.c")