CMakeLists.txt 15.5 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
32
33
34
35
36
37
38
# Explicitly setting the C and C++ compiler flags for the RelWithDebInfo build
# in order to prevent the -O2 flag from being used.
#
# The CASTOR executables are not running short of CPU cycles.  The extra
# effort required to debug released binaries compiled with the -O2 option is
# therefore not justified.
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")

39
IF(NOT CMAKE_BUILD_TYPE STREQUAL "")
40
  # If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition and dump it in the cache
41
  message(STATUS "Setting build type to ${CMAKE_BUILD_TYPE} as requested.")
42
43
44
  SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build.")
ELSE()
  # log choosen default (RelWithDebInfo) and set it
45
46
  message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
  message (STATUS "Override with -DCMAKE_BUILD_TYPE:STRING=Debug")  
47
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
48
  # Set the possible values of build type for cmake-gui
49
50
51
  # this command is not yet available in SLC6's cmake 2.6
  # set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
ENDIF(NOT CMAKE_BUILD_TYPE STREQUAL "")
52

53
54
55
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!")
56
  return()
57
endif ("${CMAKE_SOURCE_DIR}" MATCHES "${CMAKE_BINARY_DIR}")
58
59
60
61
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)
62

Steven Murray's avatar
Steven Murray committed
63

64
# Generate the compilation variables, if needed
65
66
67
if (NOT DEFINED COMPILE_SERVER)
  message (STATUS "Setting COMPILE_SERVER to the value of 1")
  message (STATUS "Override with -DCOMPILE_SERVER:STRING=0")
68
  set(COMPILE_SERVER 1)
69
70
else (NOT DEFINED COMPILE_SERVER)
  message (STATUS "Already set: COMPILE_SERVER=${COMPILE_SERVER}")
71
endif (NOT DEFINED COMPILE_SERVER)
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
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)
  
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
  if (${COMPILE_SERVER} STREQUAL "1")
    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 ()
  endif (${COMPILE_SERVER} STREQUAL "1")
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
  
  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)
  
342
  ##############################################################################
343
  # Rules to install the shared log and spool directories
344
  ##############################################################################
345
346
347
  CastorInstallDir (/var/log/castor)
  CastorInstallDir (/var/log/spool/castor)
  
348
  ##############################################################################
349
  # Include the subdirectories of the project
350
  ##############################################################################
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
  
  # 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)
387
    add_subdirectory (test)
388
389
  endif (${COMPILE_SERVER} STREQUAL "1")
ENDIF(DEFINED PackageOnly)
390

391

392

393
################################################################################
394
395
# Packaging step (replacing the maketar)
# See http://www.vtk.org/Wiki/CMakeUserUseRPMTools
396
################################################################################
397
if (${COMPILE_PACKAGING} STREQUAL "1")
398
399
  include(cmake/UseRPMToolsEnvironment.cmake)
  set(CPACK_SOURCE_PACKAGE_FILE_NAME
400
   "${PROJECT_NAME}-${CASTOR_VERSION}-${CASTOR_RELEASE}")
401
  message (STATUS
402
403
404
    "Setting package file name to: ${CPACK_SOURCE_PACKAGE_FILE_NAME}")
  include(CPack)
  include(cmake/UseRPMTools.cmake)
405
406
407
  if (RPMTools_FOUND)
    message (STATUS "Generating spec file from debian package structure...")
    execute_process (
408
      COMMAND ./makespec.py
409
      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
410
      OUTPUT_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.spec.in
411
      OUTPUT_VARIABLE result)
412
413
414
415
    if (NOT ${result} STREQUAL "")
       string (REGEX REPLACE "\n$" "" result ${result})
      message (STATUS "${result}")
    endif (NOT ${result} STREQUAL "")
416
417
    RPMTools_ADD_RPM_TARGETS(
      ${PROJECT_NAME} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.spec.in)
418
419
  endif (RPMTools_FOUND)
endif (${COMPILE_PACKAGING} STREQUAL "1")
420

421
#add_custom_target(test test/castorUnitTests
422
423
#                    COMMENT "Not running the unit tests" VERBATIM)

424
configure_file(test/castorThreadedUnitTests.supp test/castorThreadedUnitTests.supp COPYONLY)
425
426
427
428
add_custom_target(test test/castorUnitTests
                    COMMAND valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 test/castorUnitTests
                    COMMAND test/castorThreadedUnitTests
                    COMMAND valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 test/castorThreadedUnitTests
429
                    COMMAND valgrind --tool=helgrind -v --demangle=no --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=test/castorThreadedUnitTests.supp test/castorThreadedUnitTests
430
431
                    COMMAND test/castorMultiprocessUnitTests
                    COMMAND valgrind --tool=helgrind --error-exitcode=1 test/castorMultiprocessUnitTests
432
                    DEPENDS test/castorUnitTests test/castorThreadedUnitTests test/castorMultiprocessUnitTests test/castorThreadedUnitTests.supp
433
                    COMMENT "Running unit tests" VERBATIM)
434