CMakeLists.txt 10.9 KB
Newer Older
1
2
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)

3
project(COOL)
4

5
# Sanity checks and debug printouts for new lcgcmake builds (CORALCOOL-2846)
6
message(STATUS "====== WELCOME TO COOL CMakeLists.txt =======")
7
8
9
10
11
12
string(TIMESTAMP date "%Y-%m-%d %H:%M:%S")
message(STATUS "Date is ${date}")
cmake_host_system_information(RESULT host QUERY HOSTNAME)
message(STATUS "Hostname is ${host}")
message(STATUS "OS is ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION}")
message(STATUS "=============================================")
13
14
15
16
17
18
19

# Require BINARY_TAG to be set a priori (CORALCOOL-2846).
# [Do not set BINARY_TAG from host arch/os/compiler any more (CORALCOOL-2851)]
# [Do not set BINARY_TAG from CMTCONFIG/CMAKECONFIG any more (CORALCOOL-2850)]
IF("${BINARY_TAG} " STREQUAL " ")
  message(FATAL_ERROR "BINARY_TAG is not set")
ELSE()
20
  message(STATUS "BINARY_TAG is ${BINARY_TAG}") # CORAL/COOL
21
22
ENDIF()

23
24
25
26
# Print out the initial values of all other relevant variables.
# Note that the C and C++ compiler paths are usually inferred from CC and CXX.
# Most of these are only CMake variables, not environment variables, and some
# are CORAL/COOL-specific (see https://cmake.org/Wiki/CMake_Useful_Variables)
27
message(STATUS "Boost_ADDITIONAL_VERSIONS is ${Boost_ADDITIONAL_VERSIONS}")
28
message(STATUS "Boost_COMPILER is ${Boost_COMPILER}")
29
message(STATUS "Boost_NO_BOOST_CMAKE is ${Boost_NO_BOOST_CMAKE}")
30
31
message(STATUS "CMAKE_BINARY_DIR is ${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}")
32
33
message(STATUS "CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER is ${CMAKE_CXX_COMPILER}")
34
35
36
37
38
39
40
41
42
43
44
message(STATUS "CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX}")
message(STATUS "CMAKE_PREFIX_PATH [env] is $ENV{CMAKE_PREFIX_PATH}") # env only
message(STATUS "CMAKE_SOURCE_DIR is ${CMAKE_SOURCE_DIR}")
message(STATUS "CMAKE_USE_CCACHE is ${CMAKE_USE_CCACHE}") # CORAL/COOL
message(STATUS "CMAKE_USE_CCACHE [env] is $ENV{CMAKE_USE_CCACHE}") # CORAL/COOL
message(STATUS "CMAKE_VERBOSE_MAKEFILE is ${CMAKE_VERBOSE_MAKEFILE}")
message(STATUS "LD_LIBRARY_PATH [env] is $ENV{LD_LIBRARY_PATH}")
message(STATUS "LCG_VERSION is ${LCG_VERSION}") # CORAL/COOL
message(STATUS "LCG_releases_base is ${LCG_releases_base}") # CORAL/COOL
message(STATUS "=============================================")
45

46
47
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

48
49
50
51
52
53
54
55
56
# Print out a banner after any other targets are built
# Add a dependency of this target on all other targets of this project
# See http://stackoverflow.com/questions/25240105/
add_custom_target(POST_BUILD_BANNER ALL
  COMMAND ${CMAKE_COMMAND} -E echo "== COOL build completed"
  COMMAND ${CMAKE_COMMAND} -E echo_append "== Date is "
  COMMAND date
  VERBATIM)

57
58
59
60
61
62
63
64
include(CORALBuildFlags)
include(CORALEnableCCache)
include(CORALEnableDistCC)

# enable build-time and run-time environments
include(CORALEnvironmentHandling)
coral_enable_env()

65
# compiler-related link setup and runtime environment (CORALCOOL-2853)
66
67
# - set CC and CXX (with absolute real paths) in the runtime environment
# - guess the real path to stdc++.so, set it in rpath and LD_LIBRARY_PATH
Andrea Valassi's avatar
Andrea Valassi committed
68
69
70
#   (now reenabled also for clang, see CORALCOOL-2855)
#   (skip this for icc, see CORALCOOL-2797 - FIXME!)
#   (skip this for Darwin, see CORALCOOL-2806 - FIXME?)
71
72
# - no longer set the PATH to the compilers (use $CC and $CXX with full paths)
#   (exclude /usr/bin if you add it back, see CORALCOOL-2803)
73
74
75
76
get_filename_component(compiler_cc_path ${CMAKE_C_COMPILER} REALPATH)
get_filename_component(compiler_cxx_path ${CMAKE_CXX_COMPILER} REALPATH)
coral_build_and_release_env(SET CC ${compiler_cc_path})
coral_build_and_release_env(SET CXX ${compiler_cxx_path})
77
IF(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" AND NOT BINARY_TAG MATCHES "icc")
78
79
80
81
  include(GuessCompilerRuntimePaths)
  GuessCompilerRuntimePaths(compiler_lib_path compiler_bin_path)
  # this ensures that the compiler libraries are in the rpath
  link_directories(${compiler_lib_path})
82
83
  # this is needed by test runtime also for lcg-xxx-yyy builds
  coral_build_and_release_env(PREPEND LD_LIBRARY_PATH ${compiler_lib_path})
84
ENDIF()
85
86
87
88

enable_testing()

# declare install locations
89
90
91
92
if (CMAKE_INSTALL_PREFIX STREQUAL /usr/local)
  # Allow overriding via "-DCMAKE_INSTALL_PREFIX=xxx"
  # [NB The default value is not "", it is "/usr/local" (see CMakeCache.txt)]
  set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/${BINARY_TAG})
93
94
95
96
97
98
99
else()
  # Resolve symlinks in user-provided CMAKE_INSTALL_PREFIX (CORALCOOL-2836)
  get_filename_component(CMAKE_INSTALL_PREFIX_name ${CMAKE_INSTALL_PREFIX} NAME)
  get_filename_component(CMAKE_INSTALL_PREFIX_parent ${CMAKE_INSTALL_PREFIX} DIRECTORY)
  file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX_parent})
  get_filename_component(CMAKE_INSTALL_PREFIX_parent ${CMAKE_INSTALL_PREFIX_parent} REALPATH)
  set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX_parent}/${CMAKE_INSTALL_PREFIX_name})
100
endif()
101
102
103
104
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# globally required headers
105
106
find_package(CORAL REQUIRED)
include_directories(${CORAL_INCLUDE_DIRS})
107

108
# Add PATHs to cmake, ninja
109
110
111
112
113
114
115
116
117
# [NB do this first so all other paths are prepended to these (CORALCOOL-2803)]
get_filename_component(_path ${CMAKE_MAKE_PROGRAM} PATH) # PATH to ninja
if (NOT _path STREQUAL /usr/bin)
  coral_build_and_release_env(PREPEND PATH ${_path})
endif()
get_filename_component(_path ${CMAKE_COMMAND} PATH) # PATH to cmake
if (NOT _path STREQUAL /usr/bin)
  coral_build_and_release_env(PREPEND PATH ${_path})
endif()
118

119
120
121
122
IF(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  execute_process(COMMAND env -i LANG=$ENV{LANG} man -C /private/etc/man.conf -w OUTPUT_VARIABLE default_manpath OUTPUT_STRIP_TRAILING_WHITESPACE)
ELSE()
  execute_process(COMMAND env -i LANG=$ENV{LANG} man -C /etc/man.config -w OUTPUT_VARIABLE default_manpath OUTPUT_STRIP_TRAILING_WHITESPACE)
123
124
125
ENDIF()

coral_release_env(PREPEND PATH              ${CMAKE_INSTALL_PREFIX}/examples/bin
126
127
                  PREPEND PATH              ${CMAKE_INSTALL_PREFIX}/tests/bin
                  PREPEND PATH              ${CMAKE_INSTALL_PREFIX}/bin
Andrea Valassi's avatar
Andrea Valassi committed
128
                  PREPEND LD_LIBRARY_PATH   ${CMAKE_INSTALL_PREFIX}/examples/lib
Andrea Valassi's avatar
Andrea Valassi committed
129
130
                  PREPEND LD_LIBRARY_PATH   ${CMAKE_INSTALL_PREFIX}/tests/lib
                  PREPEND LD_LIBRARY_PATH   ${CMAKE_INSTALL_PREFIX}/lib
131
132
133
134
                  PREPEND PYTHONPATH        ${CMAKE_INSTALL_PREFIX}/lib
                  PREPEND PYTHONPATH        ${CMAKE_INSTALL_PREFIX}/python
                  PREPEND ROOT_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/include
                  APPEND  MANPATH           ${default_manpath}
135
                  #SET     CMTCONFIG         ${BINARY_TAG} # NO (CORALCOOL-2850)
136
                  SET     BINARY_TAG        ${BINARY_TAG})
137
coral_build_env(APPEND  MANPATH         ${default_manpath}
138
                #SET     CMTCONFIG       ${BINARY_TAG} # NO (CORALCOOL-2850)
139
140
141
                SET     BINARY_TAG      ${BINARY_TAG})

# subdirectories to include
Andrea Valassi's avatar
Andrea Valassi committed
142
set(subdirs CoolKernel RelationalCool CoolApplication
Andrea Valassi's avatar
Andrea Valassi committed
143
144
            Utilities/CoolDBDiscovery Utilities/ACE Examples
            PyCool PyCoolUtilities)
145
146
147
148
149
150
151
152
153
154
155
156

# add the subdirectories
foreach(subdir ${subdirs})
  message(STATUS "Adding subdirectory ${subdir}")
  include_directories(src/${subdir})
  add_subdirectory(src/${subdir})
endforeach()

# add environment for external packages
get_property(packages_found GLOBAL PROPERTY PACKAGES_FOUND)
#message("${packages_found}")
foreach(pack ${packages_found})
157
  coral_build_and_release_env(PACKAGE ${pack})
158
159
160
161
endforeach()

# This subdir only does (build) environment for tests and it's better to
# use it after the externals.
162
163
message(STATUS "Adding subdirectory CoolTest")
add_subdirectory(src/CoolTest)
164

Andrea Valassi's avatar
Andrea Valassi committed
165
coral_build_env(PREPEND PATH              ${CMAKE_BINARY_DIR}/examples/bin
166
                PREPEND PATH              ${CMAKE_BINARY_DIR}/tests/bin
Andrea Valassi's avatar
Andrea Valassi committed
167
                PREPEND PATH              ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
168
                PREPEND LD_LIBRARY_PATH   ${CMAKE_BINARY_DIR}/examples/lib
Andrea Valassi's avatar
Andrea Valassi committed
169
170
171
                PREPEND LD_LIBRARY_PATH   ${CMAKE_BINARY_DIR}/tests/lib
                PREPEND LD_LIBRARY_PATH   ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
                PREPEND PYTHONPATH        ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
Andrea Valassi's avatar
Andrea Valassi committed
172
                PREPEND PYTHONPATH        ${CMAKE_BINARY_DIR}/python
173
                PREPEND ROOT_INCLUDE_PATH ${CMAKE_BINARY_DIR}/include)
174

175
if(NOT "$ENV{VERBOSE} " STREQUAL " ")
176
  coral_build_and_release_env(SET VERBOSE $ENV{VERBOSE})
177
178
endif()

179
if(NOT "$ENV{LCG_release_area} " STREQUAL " ")
180
  coral_build_and_release_env(SET LCG_release_area $ENV{LCG_release_area})
181
endif()
182
183
184
if(NOT "$ENV{LCG_hostos} " STREQUAL " ")
  coral_build_and_release_env(SET LCG_hostos $ENV{LCG_hostos})
endif()
185
186
187

coral_generate_env_conf()

Andrea Valassi's avatar
Andrea Valassi committed
188
189
configure_file(cmake/cc-run.in cc-run @ONLY)
configure_file(cmake/cc-sh.in cc-sh @ONLY)
190
execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/cc-run ${CMAKE_BINARY_DIR}/cc-sh)
191
192
193
194
file(COPY cmake/.bashrc DESTINATION env)
file(COPY cmake/xenv DESTINATION env)
file(COPY cmake/EnvConfig DESTINATION env PATTERN ".svn" EXCLUDE PATTERN "*.pyc" EXCLUDE)

195
196
file(COPY ${CMAKE_BINARY_DIR}/cc-run ${CMAKE_BINARY_DIR}/cc-sh DESTINATION ${CMAKE_BINARY_DIR}/TMP.install)
file(COPY ${CMAKE_BINARY_DIR}/env DESTINATION ${CMAKE_BINARY_DIR}/TMP.install PATTERN "*.xenv*" EXCLUDE)
197

198
configure_file(cmake/run_nightly_tests_cmake.sh.in TMP.install/run_nightly_tests_cmake.sh @ONLY)
199
200
201
execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/TMP.install/run_nightly_tests_cmake.sh)

install(PROGRAMS ${CMAKE_BINARY_DIR}/TMP.install/cc-run ${CMAKE_BINARY_DIR}/TMP.install/cc-sh ${CMAKE_BINARY_DIR}/TMP.install/run_nightly_tests_cmake.sh DESTINATION .)
202
install(DIRECTORY ${CMAKE_BINARY_DIR}/TMP.install/env DESTINATION . USE_SOURCE_PERMISSIONS PATTERN "*.pyc" EXCLUDE PATTERN "*.xenvc" EXCLUDE)
203

204
205
206
207
208
209
210
211
212
# Workarounds for System Integrity Protection on MacOSX 10.11 (CORALCOOL-2884)
IF(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/bash COMMAND ${CMAKE_COMMAND} -E copy /bin/bash ${CMAKE_BINARY_DIR}/bin/bash DEPENDS /bin/bash)
  add_custom_target(bin_bash ALL DEPENDS ${CMAKE_BINARY_DIR}/bin/bash)
  install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/bash DESTINATION bin)
  add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/env COMMAND ${CMAKE_COMMAND} -E copy /usr/bin/env ${CMAKE_BINARY_DIR}/bin/env DEPENDS /usr/bin/env)
  add_custom_target(bin_env ALL DEPENDS ${CMAKE_BINARY_DIR}/bin/env)
  install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/env DESTINATION bin)
ENDIF()
213
214

# Print out a banner before any other targets are built
215
216
217
218
219
220
# Add a dependency on this target from the lowest level targets of the project
add_custom_target(PRE_BUILD_BANNER ALL
  COMMAND ${CMAKE_COMMAND} -E echo "== COOL build starting"
  COMMAND ${CMAKE_COMMAND} -E echo_append "== Date is "
  COMMAND date
  COMMAND ${CMAKE_COMMAND} -E echo_append "== Hostname is "
221
  COMMAND hostname
222
  COMMAND ${CMAKE_COMMAND} -E echo_append "== OS is "
223
  COMMAND uname -sr
224
  COMMAND ${CMAKE_COMMAND} -E echo_append "== Starting build from "
225
226
  COMMAND pwd
  VERBATIM)