CMakeLists.txt 13.2 KB
Newer Older
Steven Murray's avatar
More    
Steven Murray committed
1
#                      CMakeLists.txt
2
#
Steven Murray's avatar
More    
Steven Murray committed
3
4
# This file is part of the Castor project.
# See http://castor.web.cern.ch/castor
5
#
Steven Murray's avatar
More    
Steven Murray committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright (C) 2003  CERN
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
Eric Cano's avatar
Eric Cano committed
20
# Steven.Murray@cern.ch Eric.Cano@cern.ch
21
22
#

23
24
25
################################################################################
# Project definition section - In source build forbidding
################################################################################
26
cmake_minimum_required (VERSION 2.6)
27

28
project(castor)
29
30
31

set(CMAKE_BUILD_TYPE Debug)

32
33
34
if ("${CMAKE_SOURCE_DIR}" MATCHES "${CMAKE_BINARY_DIR}")
  message (SEND_ERROR "In source building not supported. Please run something like: \"mkdir ../build; ( src=`pwd`; cd ../build; cmake $src ); make -C ../build\"")
  message (SEND_ERROR "Now that you reached that point you will unfortnately have to cleanup your source directory: \"rm -rf CMakeFiles/ CMakeCache.txt\". Sorry!")
35
  return()
36
endif ("${CMAKE_SOURCE_DIR}" MATCHES "${CMAKE_BINARY_DIR}")
37
38
39
40
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(cmake/CASTORVersion.cmake)
41

Steven Murray's avatar
Steven Murray committed
42

43
# Generate the compilation variables, if needed
44
45
46
if (NOT DEFINED COMPILE_SERVER)
  message (STATUS "Setting COMPILE_SERVER to the value of 1")
  message (STATUS "Override with -DCOMPILE_SERVER:STRING=0")
47
  set(COMPILE_SERVER 1)
48
49
else (NOT DEFINED COMPILE_SERVER)
  message (STATUS "Already set: COMPILE_SERVER=${COMPILE_SERVER}")
50
endif (NOT DEFINED COMPILE_SERVER)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
IF(DEFINED PackageOnly)
  message (STATUS "Running CMake in package-only mode")
   set(COMPILE_PACKAGING "1") 
ELSE(DEFINED PackageOnly)
  message (STATUS "Running in full configuration mode.")
  message (STATUS "Override with -DPackageOnly:Bool=true")
  # Generate the compilation variables, if needed
  if (NOT DEFINED COMPILE_PACKAGING)
    message (STATUS "Setting COMPILE_PACKAGING to the value of 1")
    message (STATUS "Override with -DCOMPILE_PACKAGING:STRING=0")
    set(COMPILE_PACKAGING 1)
  else (NOT DEFINED COMPILE_PACKAGING)
    message (STATUS "Already set: COMPILE_PACKAGING=${COMPILE_PACKAGING}")
  endif (NOT DEFINED COMPILE_PACKAGING)

  ################################################################################
  # Configure header file
  ################################################################################
  configure_file(${CMAKE_SOURCE_DIR}/h/patchlevel.h.in
    ${CMAKE_BINARY_DIR}/h/patchlevel.h)
  
  ################################################################################
  # Global rules and variables
  ################################################################################
  set (CASTOR_DEST_BIN_DIR /usr/bin)
  set (CASTOR_DEST_LIB_DIR /usr/lib64)
  set (CASTOR_DEST_MAN_DIR /usr/share/man)
  set (CASTOR_DEST_INCLUDE_DIR /usr/include)
  set (CASTOR_DEST_PERL_LIBDIR /usr/lib/perl/CASTOR)
  set (CASTOR_DEST_C_HEADERS_DIR ${CASTOR_DEST_INCLUDE_DIR}/castor/h)
  set (CASTOR_DEST_CPP_HEADERS_DIR ${CASTOR_DEST_INCLUDE_DIR}/castor/castor)
  set (CASTOR_DEST_WWW_DIR /var/www)
  
  message (STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
  message (STATUS "CMAKE_SIZEOF_VOID_P = ${CMAKE_SIZEOF_VOID_P}")
  if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND
     ${CMAKE_SIZEOF_VOID_P} MATCHES "8")
    set (CASTOR_DEST_LIB_DIR /usr/lib64)
    message (STATUS "CASTOR_DEST_LIB_DIR = ${CASTOR_DEST_LIB_DIR}")
  else ()
    set (CASTOR_DEST_LIB_DIR /usr/lib)
    message (STATUS "CASTOR_DEST_LIB_DIR = ${CASTOR_DEST_LIB_DIR}")
  endif ()
  
  find_package (uuid REQUIRED)
  find_package (python REQUIRED)
  
  set (CASTOR_BIN_SCRIPT_PERMS
    OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ             OWNER_EXECUTE
    WORLD_READ             WORLD_EXECUTE)
  
  set (CASTOR_ETC_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_ETC_CRON_D_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_ETC_XINETD_D_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_EXAMPLE_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_HEADER_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_INITSCRIPT_PERMS
    OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ             GROUP_EXECUTE
    WORLD_READ             WORLD_EXECUTE)
  
  set (CASTOR_LOGROTATE_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_MAN_PAGE_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_NON_EXEC_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  set (CASTOR_PYTHON_LIB_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ            
    WORLD_READ)
  
  set (CASTOR_SCRIPT_PERMS
    OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ             GROUP_EXECUTE
    WORLD_READ             WORLD_EXECUTE)
  
  set (CASTOR_SYSCONFIG_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ
    WORLD_READ)
  
  include_directories(${CMAKE_BINARY_DIR})
  include_directories(${CMAKE_BINARY_DIR}/h)
  include_directories(${CMAKE_SOURCE_DIR})
  include_directories(${CMAKE_SOURCE_DIR}/h)
  
  find_package (oracle REQUIRED)
  
  function (CastorAddProC _name)
    add_custom_command (
      OUTPUT ${_name}.c DEPENDS ${_name}.pc
      COMMAND
        ORACLE_HOME=${ORACLE_HOME}
        LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${ORACLE_LIBDIR}
        ${ORACLE_BIN}/proc
        iname=${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pc
        oname=${CMAKE_CURRENT_BINARY_DIR}/${_name}.c
        ${ORACLE_PROCINC}
        include=${CMAKE_SOURCE_DIR}/h threads=yes
        char_map=string
        parse=full
        prefetch=1000)
  
    # Append the oracle specific compilation flags and also use -Wno-error to
    # override the default -Werror compilation rule in the case of source files
    # produced by the Pro*C precompiler.  Such files contain generated code that
    # generates warnings.
    set_property (SOURCE ${_name}.c
      PROPERTY COMPILE_FLAGS "${ORACLE_CPPFLAGS} -Wno-error")
  endfunction ()
  
  function (CastorInstallDir _name)
    install (CODE
      "message (STATUS \"Installing directory \$ENV{DESTDIR}${_name}\")")
    install (CODE "file (MAKE_DIRECTORY \$ENV{DESTDIR}${_name})")
  endfunction ()
  
  function (CastorInstallEtcCronD _name)
    install (FILES ${_name}.cron_d
      DESTINATION /etc/cron.d
      PERMISSIONS ${CASTOR_ETC_CRON_D_PERMS}
      RENAME ${_name})
  endfunction ()
  
  function (CastorInstallEtcExample _name)
    install (FILES ${_name}.etc
      DESTINATION /etc
      PERMISSIONS ${CASTOR_ETC_PERMS}
      RENAME ${_name}.example)
  endfunction ()
  
  function (CastorInstallEtcXinetdD _name)
    install (FILES ${_name}.xinetd_d
      DESTINATION /etc/xinetd.d
      PERMISSIONS ${CASTOR_ETC_XINETD_D_PERMS}
      RENAME ${_name})
  endfunction ()
  
  function (CastorInstallExample _name _dest)
    install (FILES ${_name}
      DESTINATION ${_dest}
      PERMISSIONS ${CASTOR_EXAMPLE_PERMS}
      RENAME ${_name}.example)
  endfunction ()
  
  function (CastorInstallScript _name)
    install (FILES ${_name}
      DESTINATION ${CASTOR_DEST_BIN_DIR}
      PERMISSIONS ${CASTOR_BIN_SCRIPT_PERMS})
  endfunction ()
  
  function (CastorInstallManPage _name _section)
    install (FILES ${_name}.man
      DESTINATION ${CASTOR_DEST_MAN_DIR}/man${_section}
      PERMISSIONS ${CASTOR_MAN_PAGE_PERMS}
      RENAME ${_name}.${_section}castor)
  endfunction ()
  
  function (CastorInstallExeManPage _name)
    CastorInstallManPage (${_name} 1)
  endfunction ()
  
  function (CastorInstallSysManPage _name)
    CastorInstallManPage (${_name} 2)
  endfunction ()
  
  function (CastorInstallLibManPage _name)
    CastorInstallManPage (${_name} 3)
  endfunction ()
  
  function (CastorInstallFileManPage _name)
    CastorInstallManPage (${_name} 4)
  endfunction ()
  
  function (CastorInstallAdmManPage _name)
    CastorInstallManPage (${_name} 8)
  endfunction ()
  
  function (CastorInstallLogrotate _name)
    install (FILES ${_name}.logrotate
      DESTINATION /etc/logrotate.d
      PERMISSIONS ${CASTOR_LOGROTATE_PERMS}
      RENAME ${_name})
  endfunction ()
  
  function (CastorInstallSysconfigExample _name)
    install (FILES ${_name}.sysconfig
      DESTINATION /etc/sysconfig
      PERMISSIONS ${CASTOR_SYSCONFIG_PERMS}
      RENAME ${_name}.example)
  endfunction ()
  
  function (CastorInstallInitScript _name)
    install (FILES ${_name}.init
      DESTINATION /etc/init.d
      PERMISSIONS ${CASTOR_INITSCRIPT_PERMS}
      RENAME ${_name})
  endfunction ()
  
  set (CASTOR_CONFIG_PERMS
    OWNER_READ OWNER_WRITE
    GROUP_READ)
  
  function (CastorInstallConfigFile _name)
    install (FILES ${_name}CONFIG
      DESTINATION /etc/castor
      PERMISSIONS ${CASTOR_CONFIG_PERMS}
      RENAME ${_name}CONFIG.example)
  endfunction ()
  
  function (CastorInstallConfigFileLowercase _name)
    install (FILES ${_name}
      DESTINATION /etc/castor
      PERMISSIONS ${CASTOR_CONFIG_PERMS}
      RENAME ${_name}.example)
  endfunction ()
  
  function (CastorSetLibraryVersions _name)
    set_target_properties (${_name} PROPERTIES
    VERSION ${MAJOR_CASTOR_VERSION}.${MINOR_CASTOR_VERSION}
    SOVERSION ${MAJOR_CASTOR_VERSION})
  endfunction ()
  
  set (CMAKE_C_FLAGS "-fPIC -Wall -Wextra -Werror -Wno-unused-parameter")
  
  if (APPLE)
    set (CMAKE_SHARED_LINKER_FLAGS
      "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
  else (APPLE)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
  endif (APPLE)
  
  set (CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
  
  set_property (DIRECTORY PROPERTY COMPILE_DEFINITIONS _LARGEFILE64_SOURCE)
  
  ################################################################################
  # Rules to install the shared log and spool directories
  ################################################################################
  CastorInstallDir (/var/log/castor)
  CastorInstallDir (/var/log/spool/castor)
  
  ################################################################################
  # Include the subdirectories of the project
  ################################################################################
  
  # Some directories have client components, and get included unconditionnaly
  # inside them, we can filter further down what we need or not.
  # The ones with only server components can already be filtered out for the 
  # clients builds here.
  
  add_subdirectory (castor)
  add_subdirectory (client/src/stager)
  add_subdirectory (common)
  add_subdirectory (dlf)
  if (${COMPILE_SERVER} STREQUAL "1")
    add_subdirectory (gridftp2)
  endif (${COMPILE_SERVER} STREQUAL "1")
  add_subdirectory (h)
  if (${COMPILE_SERVER} STREQUAL "1")
    add_subdirectory (hsmtools)
    add_subdirectory (monitoring)
  endif (${COMPILE_SERVER} STREQUAL "1")
  add_subdirectory (ns)
  add_subdirectory (rfio)
  add_subdirectory (rmc)
  add_subdirectory (security)
  add_subdirectory (shlib)
  if (${COMPILE_SERVER} STREQUAL "1")
    add_subdirectory (tapebridge)
    add_subdirectory (traffic-shaping)
  endif (${COMPILE_SERVER} STREQUAL "1")
  add_subdirectory (upv)
  add_subdirectory (vdqm)
  add_subdirectory (vmgr)
  if (${COMPILE_SERVER} STREQUAL "1")
    add_subdirectory (xrootd)
  endif (${COMPILE_SERVER} STREQUAL "1")
  add_subdirectory (tape)
  if (${COMPILE_SERVER} STREQUAL "1")
    add_subdirectory (rtcopy)
364
    add_subdirectory (test)
365
366
  endif (${COMPILE_SERVER} STREQUAL "1")
ENDIF(DEFINED PackageOnly)
367

368

369

370
################################################################################
371
372
# Packaging step (replacing the maketar)
# See http://www.vtk.org/Wiki/CMakeUserUseRPMTools
373
################################################################################
374
if (${COMPILE_PACKAGING} STREQUAL "1")
375
376
  include(cmake/UseRPMToolsEnvironment.cmake)
  set(CPACK_SOURCE_PACKAGE_FILE_NAME
377
   "${PROJECT_NAME}-${CASTOR_VERSION}-${CASTOR_RELEASE}")
378
  message (STATUS
379
380
381
    "Setting package file name to: ${CPACK_SOURCE_PACKAGE_FILE_NAME}")
  include(CPack)
  include(cmake/UseRPMTools.cmake)
382
383
  if (RPMTools_FOUND)
    execute_process (COMMAND ${CMAKE_COMMAND} -E copy
384
385
      ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.spec.in.head
      ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.spec.in)
386
387
    message (STATUS "Generating spec file from debian package structure...")
    execute_process (
388
389
390
      COMMAND ./makespec.in.sh ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.spec.in 2>&1
      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
      OUTPUT_VARIABLE result)
391
392
393
394
    if (NOT ${result} STREQUAL "")
       string (REGEX REPLACE "\n$" "" result ${result})
      message (STATUS "${result}")
    endif (NOT ${result} STREQUAL "")
395
396
    RPMTools_ADD_RPM_TARGETS(
      ${PROJECT_NAME} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.spec.in)
397
398
  endif (RPMTools_FOUND)
endif (${COMPILE_PACKAGING} STREQUAL "1")