commonSetup.cmake 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. ################################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ################################################################################
  16. # File : commonSetup.cmake
  17. #
  18. #########################################################
  19. # Description:
  20. # ------------
  21. # sets up various cmake options.
  22. #########################################################
  23. IF ("${COMMONSETUP_DONE}" STREQUAL "")
  24. SET (COMMONSETUP_DONE 1)
  25. MACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
  26. STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
  27. IF (insource)
  28. MESSAGE(FATAL_ERROR "${_errorMessage}")
  29. ENDIF(insource)
  30. ENDMACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
  31. macro_ensure_out_of_source_build("The LexisNexis Hpcc requires an out of source build.
  32. Please remove the directory ${CMAKE_BINARY_DIR}/CMakeFiles
  33. and the file ${CMAKE_BINARY_DIR}/CMakeCache.txt,
  34. then create a separate build directory and run 'cmake path_to_source [options]' there.")
  35. cmake_policy ( SET CMP0011 NEW )
  36. if (NOT (CMAKE_MAJOR_VERSION LESS 3))
  37. cmake_policy ( SET CMP0026 OLD )
  38. if (NOT (CMAKE_MINOR_VERSION LESS 1))
  39. cmake_policy ( SET CMP0054 NEW )
  40. endif()
  41. endif()
  42. option(CLIENTTOOLS "Enable the building/inclusion of a Client Tools component." ON)
  43. option(PLATFORM "Enable the building/inclusion of a Platform component." ON)
  44. option(DEVEL "Enable the building/inclusion of a Development component." OFF)
  45. option(CLIENTTOOLS_ONLY "Enable the building of Client Tools only." OFF)
  46. option(INCLUDE_PLUGINS "Enable the building of platform and all plugins for testing purposes" OFF)
  47. option(USE_CASSANDRA "Include the Cassandra plugin in the base package" ON)
  48. option(PLUGIN "Enable building of a plugin" OFF)
  49. option(USE_SHLIBDEPS "Enable the use of dpkg-shlibdeps on ubuntu packaging" OFF)
  50. option(SIGN_MODULES "Enable signing of ecl standard library modules" OFF)
  51. option(USE_CPPUNIT "Enable unit tests (requires cppunit)" OFF)
  52. option(USE_OPENLDAP "Enable OpenLDAP support (requires OpenLDAP)" ON)
  53. option(USE_ICU "Enable unicode support (requires ICU)" ON)
  54. option(USE_BOOST_REGEX "Configure use of boost regex" ON)
  55. option(CENTOS_6_BOOST "Supply regex library on CentOS 6" OFF)
  56. # USE_C11_REGEX is only checked if USE_BOOST_REGEX is OFF
  57. # to disable REGEX altogether turn both off
  58. option(USE_C11_REGEX "Configure use of c++11 std::regex" ON)
  59. option(Boost_USE_STATIC_LIBS "Use boost_regex static library for RPM BUILD" OFF)
  60. option(USE_OPENSSL "Configure use of OpenSSL" ON)
  61. option(USE_ZLIB "Configure use of zlib" ON)
  62. option(USE_CBLAS "Configure use of cblas" ON)
  63. option(USE_H3 "Configure use of Uber H3 geospatial indexing" ON)
  64. if (WIN32)
  65. option(USE_AERON "Include the Aeron message protocol" OFF)
  66. option(USE_GIT "Configure use of GIT (Hooks)" OFF)
  67. else()
  68. option(USE_AERON "Include the Aeron message protocol" ON)
  69. option(USE_GIT "Configure use of GIT (Hooks)" ON)
  70. endif()
  71. option(USE_LIBARCHIVE "Configure use of libarchive" ON)
  72. option(USE_URIPARSER "Configure use of uriparser" OFF)
  73. if (APPLE OR WIN32)
  74. option(USE_NUMA "Configure use of numa" OFF)
  75. else()
  76. option(USE_NUMA "Configure use of numa" ON)
  77. endif()
  78. IF (WIN32)
  79. option(USE_NATIVE_LIBRARIES "Search standard OS locations (otherwise in EXTERNALS_DIRECTORY) for 3rd party libraries" OFF)
  80. ELSE()
  81. option(USE_NATIVE_LIBRARIES "Search standard OS locations (otherwise in EXTERNALS_DIRECTORY) for 3rd party libraries" ON)
  82. ENDIF()
  83. option(USE_GIT_DESCRIBE "Use git describe to generate build tag" ON)
  84. option(CHECK_GIT_TAG "Require git tag to match the generated build tag" OFF)
  85. option(USE_XALAN "Configure use of xalan" OFF)
  86. option(USE_APR "Configure use of Apache Software Foundation (ASF) Portable Runtime (APR) libraries" ON)
  87. option(USE_LIBXSLT "Configure use of libxslt" ON)
  88. option(MAKE_DOCS "Create documentation at build time." OFF)
  89. option(MAKE_DOCS_ONLY "Create a base build with only docs." OFF)
  90. option(DOCS_DRUPAL "Create Drupal HTML Docs" OFF)
  91. option(DOCS_EPUB "Create EPUB Docs" OFF)
  92. option(DOCS_MOBI "Create Mobi Docs" OFF)
  93. option(DOCS_AUTO "DOCS automation" OFF)
  94. option(USE_RESOURCE "Use resource download in ECLWatch" OFF)
  95. option(GENERATE_COVERAGE_INFO "Generate coverage info for gcov" OFF)
  96. option(USE_SIGNED_CHAR "Build system with default char type is signed" OFF)
  97. option(USE_UNSIGNED_CHAR "Build system with default char type is unsigned" OFF)
  98. option(USE_MYSQL "Enable mysql support" ON)
  99. option(USE_LIBMEMCACHED "Enable libmemcached support" ON)
  100. option(USE_PYTHON2 "Enable python2 language support for platform build" ON)
  101. option(USE_PYTHON3 "Enable python3 language support for platform build" ON)
  102. option(USE_OPTIONAL "Automatically disable requested features with missing dependencies" ON)
  103. option(JLIB_ONLY "Build JLIB for other projects such as Configurator, Ganglia Monitoring, etc" OFF)
  104. # Generates code that is more efficient, but will cause problems if target platforms do not support it.
  105. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  106. option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" ON)
  107. else()
  108. option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" OFF)
  109. endif()
  110. if (APPLE OR WIN32)
  111. option(USE_TBB "Enable Threading Building Block support" OFF)
  112. else()
  113. option(USE_TBB "Enable Threading Building Block support" ON)
  114. option(USE_TBBMALLOC "Enable Threading Building Block scalable allocator proxy support" OFF)
  115. option(USE_TBBMALLOC_ROXIE "Enable Threading Building Block scalable allocator proxy support in Roxie" OFF)
  116. endif()
  117. option(LOGGING_SERVICE "Configure use of logging service" ON)
  118. option(WSSQL_SERVICE "Configure use of ws_sql service" ON)
  119. option(USE_DIGISIGN "Use digisign" ON)
  120. set(CUSTOM_PACKAGE_SUFFIX "" CACHE STRING "Custom package suffix to differentiate development builds")
  121. MACRO(SET_PLUGIN_PACKAGE plugin)
  122. string(TOLOWER "${plugin}" pname)
  123. if(DEFINED pluginname)
  124. message(FATAL_ERROR "Cannot enable ${pname}, already declared ${pluginname}")
  125. else()
  126. set(pluginname "${pname}")
  127. endif()
  128. foreach(p in ${PLUGINS_LIST})
  129. if(NOT "${p}" STREQUAL "${plugin}" AND ${p})
  130. message(FATAL_ERROR "Cannot declare multiple plugins in a plugin package")
  131. endif()
  132. endforeach()
  133. set(PLUGIN ON)
  134. set(CLIENTTOOLS OFF)
  135. set(PLATFORM OFF)
  136. set(INCLUDE_PLUGINS OFF)
  137. set(SIGN_MODULES OFF)
  138. set(USE_OPTIONAL OFF) # Force failure if we can't find the plugin dependencies
  139. ENDMACRO()
  140. # Plugin options
  141. set(PLUGINS_LIST
  142. REMBED
  143. V8EMBED
  144. MEMCACHED
  145. REDIS
  146. SQS
  147. MYSQLEMBED
  148. JAVAEMBED
  149. SQLITE3EMBED
  150. KAFKA
  151. COUCHBASEEMBED
  152. SPARK
  153. EXAMPLEPLUGIN)
  154. foreach(plugin ${PLUGINS_LIST})
  155. option(${plugin} "Create a package with ONLY the ${plugin} plugin" OFF)
  156. option(INCLUDE_${plugin} "Include ${plugin} within package for testing" OFF)
  157. option(SUPPRESS_${plugin} "Suppress ${plugin} from INCLUDE_PLUGINS build" OFF)
  158. # Plugin Release build for individual package
  159. if(${plugin})
  160. SET_PLUGIN_PACKAGE("${plugin}")
  161. # Development build with all plugins for testing
  162. # Development build with addition of plugin
  163. elseif((INCLUDE_PLUGINS OR INCLUDE_${plugin}) AND (NOT SUPPRESS_${plugin}) AND (NOT PLUGIN))
  164. set(${plugin} ON)
  165. endif()
  166. endforeach()
  167. #"cmake -DEXAMPLEPLUGIN=ON <path-to/HPCC-Platform/>" will configure the plugin makefiles to be built with "make".
  168. set(CMAKE_MODULE_PATH "${HPCC_SOURCE_DIR}/cmake_modules/")
  169. if ( NOT MAKE_DOCS_ONLY )
  170. set(LIBMEMCACHED_MINVERSION "1.0.10")
  171. if(USE_LIBMEMCACHED)
  172. if(WIN32)
  173. message(STATUS "libmemcached not available on Windows. Disabling for build")
  174. set(USE_LIBMEMCACHED OFF)
  175. elseif(APPLE)
  176. message(STATUS "libmemcached not available on macOS. Disabling for build")
  177. set(USE_LIBMEMCACHED OFF)
  178. else()
  179. find_package(LIBMEMCACHED ${LIBMEMCACHED_MINVERSION} REQUIRED)
  180. add_definitions(-DUSE_LIBMEMCACHED)
  181. include_directories(${LIBMEMCACHED_INCLUDE_DIR})
  182. endif()
  183. endif()
  184. endif()
  185. if (SIGN_MODULES)
  186. message(STATUS "GPG signing check")
  187. execute_process(COMMAND bash "-c" "gpg --version | awk 'NR==1{print $3}'"
  188. OUTPUT_VARIABLE GPG_VERSION
  189. OUTPUT_STRIP_TRAILING_WHITESPACE
  190. ERROR_QUIET)
  191. set(GPG_COMMAND_STR "gpg")
  192. if(${GPG_VERSION} VERSION_GREATER "2.1")
  193. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --pinentry-mode loopback --batch --no-tty")
  194. else()
  195. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --batch --no-tty")
  196. endif()
  197. if(DEFINED SIGN_MODULES_PASSPHRASE)
  198. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --passphrase ${SIGN_MODULES_PASSPHRASE}")
  199. endif()
  200. if(DEFINED SIGN_MODULES_KEYID)
  201. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --default-key ${SIGN_MODULES_KEYID}")
  202. endif()
  203. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --output sm_keycheck.asc --clearsign sm_keycheck.tmp")
  204. execute_process(COMMAND rm -f sm_keycheck.tmp sm_keycheck.asc TIMEOUT 5
  205. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} OUTPUT_QUIET ERROR_QUIET)
  206. execute_process(COMMAND touch sm_keycheck.tmp TIMEOUT 5
  207. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE t_rc
  208. OUTPUT_QUIET ERROR_QUIET)
  209. if(NOT "${t_rc}" STREQUAL "0")
  210. message(FATAL_ERROR "Failed to create sm_keycheck.tmp for signing")
  211. endif()
  212. execute_process(
  213. COMMAND bash "-c" "${GPG_COMMAND_STR}"
  214. TIMOUT 120
  215. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  216. RESULT_VARIABLE rc_var
  217. OUTPUT_VARIABLE out_var
  218. ERROR_VARIABLE err_var
  219. )
  220. if(NOT "${rc_var}" STREQUAL "0")
  221. message(STATUS "GPG signing check - failed")
  222. message(FATAL_ERROR "gpg signing of std ecllibrary unsupported in current environment. \
  223. If you wish to build without a signed std ecllibrary add -DSIGN_MODULES=OFF to your \
  224. cmake invocation.\n${err_var}")
  225. else()
  226. message(STATUS "GPG signing check - done")
  227. endif()
  228. endif()
  229. if ( USE_XALAN AND USE_LIBXSLT )
  230. set(USE_LIBXSLT OFF)
  231. endif()
  232. if ( USE_LIBXSLT )
  233. set(USE_LIBXML2 ON)
  234. endif()
  235. if ( USE_XALAN )
  236. set(USE_XERCES ON)
  237. endif()
  238. if ( MAKE_DOCS AND CLIENTTOOLS_ONLY )
  239. set( MAKE_DOCS OFF )
  240. endif()
  241. if ( MAKE_DOCS_ONLY AND NOT CLIENTTOOLS_ONLY )
  242. set( MAKE_DOCS ON )
  243. if ( USE_DOCS_AUTO )
  244. set ( DOCS_AUTO ON)
  245. endif()
  246. endif()
  247. if ( CLIENTTOOLS_ONLY )
  248. set(PLATFORM OFF)
  249. set(DEVEL OFF)
  250. endif()
  251. option(PORTALURL "Set url to hpccsystems portal download page")
  252. if ( NOT PORTALURL )
  253. set( PORTALURL "http://hpccsystems.com/download" )
  254. endif()
  255. if(UNIX AND SIGN_MODULES)
  256. execute_process(COMMAND bash "-c" "gpg --version | awk 'NR==1{print $3}'"
  257. OUTPUT_VARIABLE GPG_VERSION
  258. OUTPUT_STRIP_TRAILING_WHITESPACE
  259. ERROR_QUIET)
  260. message(STATUS "gpg version ${GPG_VERSION}")
  261. #export gpg public key used for signing to new installation
  262. add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/pub.key
  263. COMMAND bash "-c" "gpg --output=${CMAKE_BINARY_DIR}/pub.key --batch --no-tty --export ${SIGN_MODULES_KEYID}"
  264. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  265. COMMENT "Exporting public key for eclcc signed modules to ${CMAKE_BINARY_DIR}/pub.key"
  266. VERBATIM
  267. )
  268. add_custom_target(export-stdlib-pubkey ALL
  269. DEPENDS ${CMAKE_BINARY_DIR}/pub.key
  270. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  271. )
  272. install(FILES ${CMAKE_BINARY_DIR}/pub.key DESTINATION .${CONFIG_DIR}/rpmnew COMPONENT Runtime)
  273. install(PROGRAMS ${CMAKE_MODULE_PATH}publickey.install DESTINATION etc/init.d/install COMPONENT Runtime)
  274. endif()
  275. ##########################################################
  276. # common compiler/linker flags
  277. if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
  278. set ( CMAKE_BUILD_TYPE "Release" )
  279. elseif (NOT "${CMAKE_BUILD_TYPE}" MATCHES "^Debug$|^Release$|^RelWithDebInfo$")
  280. message (FATAL_ERROR "Unknown build type ${CMAKE_BUILD_TYPE}")
  281. endif ()
  282. message ("-- Making ${CMAKE_BUILD_TYPE} system")
  283. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  284. set ( ARCH64BIT 1 )
  285. else ()
  286. set ( ARCH64BIT 0 )
  287. endif ()
  288. message ("-- 64bit architecture is ${ARCH64BIT}")
  289. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DDEBUG")
  290. IF (USE_INLINE_TSC)
  291. add_definitions (-DINLINE_GET_CYCLES_NOW)
  292. ENDIF()
  293. set (CMAKE_THREAD_PREFER_PTHREAD 1)
  294. find_package(Threads)
  295. IF (NOT THREADS_FOUND)
  296. message(FATAL_ERROR "No threading support found")
  297. ENDIF()
  298. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  299. set (CMAKE_COMPILER_IS_CLANGXX 1)
  300. endif()
  301. if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
  302. set (CMAKE_COMPILER_IS_CLANG 1)
  303. endif()
  304. if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) AND (NOT ${CMAKE_C_COMPILER_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+"))
  305. execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_C_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  306. endif ()
  307. if ((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND (NOT ${CMAKE_CXX_COMPILER_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+"))
  308. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  309. endif()
  310. if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  311. add_definitions (-fvisibility=hidden)
  312. endif ()
  313. if (CMAKE_COMPILER_IS_CLANGXX AND CMAKE_BUILD_TYPE STREQUAL "Debug")
  314. add_definitions (-fsanitize=undefined -fno-sanitize=alignment -fsanitize-trap=undefined)
  315. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=undefined")
  316. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
  317. endif ()
  318. if ((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0.0) AND CMAKE_BUILD_TYPE STREQUAL "Debug")
  319. add_definitions (-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error)
  320. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=undefined")
  321. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
  322. endif ()
  323. if (CMAKE_COMPILER_IS_CLANGXX)
  324. execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
  325. if (${clang_full_version_string} MATCHES "Apple LLVM version ([0-9]+\\.[0-9]+\\.[0-9]+).*")
  326. string (REGEX REPLACE "Apple LLVM version ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" APPLE_CLANG_VERSION ${clang_full_version_string})
  327. endif()
  328. if (${clang_full_version_string} MATCHES ".*based on LLVM ([0-9]+\\.[0-9]+).*")
  329. string (REGEX REPLACE ".*based on LLVM ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION ${clang_full_version_string})
  330. else()
  331. if (${clang_full_version_string} MATCHES ".*clang version ([0-9]+\\.[0-9]+).*")
  332. string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION ${clang_full_version_string})
  333. endif()
  334. endif()
  335. endif ()
  336. if (WIN32)
  337. # On windows, the vcproj generator generates both windows and debug build capabilities, and the release mode is appended to the directory later
  338. # This output location matches what our existing windows release scripts expect - might make sense to move out of tree sometime though
  339. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  340. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  341. # Workaround CMake's odd decision to default windows stack size to 10000000
  342. STRING(REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  343. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
  344. if (${ARCH64BIT} EQUAL 1)
  345. add_definitions(/bigobj)
  346. endif ()
  347. if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
  348. if (${ARCH64BIT} EQUAL 0)
  349. add_definitions(/ZI)
  350. else()
  351. add_definitions(/Zi)
  352. endif ()
  353. endif ()
  354. if ("${GIT_COMMAND}" STREQUAL "")
  355. set ( GIT_COMMAND "git.cmd" )
  356. endif ()
  357. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa")
  358. if (USE_SIGNED_CHAR AND USE_UNSIGNED_CHAR )
  359. message (FATAL_ERROR "Can't use USE_SIGNED_CHAR and USE_UNSIGNED_CHAR together!")
  360. else()
  361. if (USE_SIGNED_CHAR)
  362. message ("Build system with signed char type.")
  363. # This is default for MSVC
  364. endif ()
  365. if (USE_UNSIGNED_CHAR )
  366. message ("Build system with unsigned char type.")
  367. add_definitions(/J)
  368. endif ()
  369. endif ()
  370. #=== WARNING ======
  371. # Temporary disable warnings. Reenable them one by one to reexamine and fix them.
  372. IF (NOT ALL_WARNINGS_ON)
  373. set (WARNINGS_IGNORE "/wd4267 /wd4244 /wd6340 /wd6297 /wd4018 /wd4302 /wd4311 /wd4320 /wd4800") # data conversion warnings
  374. set (WARNINGS_IGNORE "${WARNINGS_IGNORE} /wd4251 /wd4275") # dll-interface for used by clients
  375. set (WARNINGS_IGNORE "${WARNINGS_IGNORE} /wd6246") # local variable hidden by outer scope
  376. set (WARNINGS_IGNORE "${WARNINGS_IGNORE} /wd6031") # Return value ignored
  377. set (WARNINGS_IGNORE "${WARNINGS_IGNORE} /wd4005") # MACRO redef: same value
  378. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS_IGNORE}")
  379. ENDIF()
  380. else ()
  381. if (NOT CMAKE_USE_PTHREADS_INIT)
  382. message (FATAL_ERROR "pthreads support not detected")
  383. endif ()
  384. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin" )
  385. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/libs" )
  386. if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
  387. message ("Using compiler: ${CMAKE_CXX_COMPILER_ID} :: ${CMAKE_CXX_COMPILER_VERSION} :: ${CLANG_VERSION} :: ${APPLE_CLANG_VERSION}")
  388. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fPIC -fmessage-length=0 -Werror=format -Wformat-security -Wformat-nonliteral -pthread -Wuninitialized")
  389. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic")
  390. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-inline-functions")
  391. if (CMAKE_COMPILER_IS_GNUCXX)
  392. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-default-inline")
  393. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.2.4 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.2.4)
  394. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -Werror=format-nonliteral")
  395. endif ()
  396. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.4.0)
  397. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
  398. endif ()
  399. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 2.95.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 2.95.3)
  400. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wparentheses")
  401. endif ()
  402. endif ()
  403. SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
  404. SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE}")
  405. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  406. if (GENERATE_COVERAGE_INFO)
  407. message ("Build system with coverage.")
  408. if (CMAKE_COMPILER_IS_CLANGXX)
  409. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
  410. else()
  411. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  412. endif()
  413. endif()
  414. # Handle forced default char type
  415. if (USE_SIGNED_CHAR AND USE_UNSIGNED_CHAR )
  416. message (FATAL_ERROR "Can't use USE_SIGNED_CHAR and USE_UNSIGNED_CHAR together!")
  417. else()
  418. if (USE_SIGNED_CHAR)
  419. message ("Build system with signed char type.")
  420. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
  421. endif ()
  422. if (USE_UNSIGNED_CHAR )
  423. message ("Build system with unsigned char type.")
  424. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funsigned-char")
  425. endif ()
  426. endif ()
  427. endif ()
  428. if (CMAKE_COMPILER_IS_CLANGXX)
  429. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=logical-op-parentheses -Werror=bool-conversions -Werror=return-type -Werror=comment")
  430. if (APPLE)
  431. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  432. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
  433. endif ()
  434. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=bitwise-op-parentheses -Werror=tautological-compare")
  435. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum -Wno-format-zero-length -Wno-switch")
  436. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") # Silence messages about pthread not being used when linking...
  437. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override -Wno-unknown-warning-option") # Until we fix them all, whcih would be a huge task...
  438. if (CLANG_VERSION VERSION_GREATER 3.6 OR CLANG_VERSION VERSION_EQUAL 3.6 OR APPLE_CLANG_VERSION VERSION_GREATER 6.0)
  439. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pointer-bool-conversion")
  440. endif()
  441. endif()
  442. # All of these are defined in platform.h too, but need to be defned before any system header is included
  443. ADD_DEFINITIONS (-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -D__USE_LARGEFILE64=1 -D__USE_FILE_OFFSET64=1)
  444. if ("${GIT_COMMAND}" STREQUAL "")
  445. set ( GIT_COMMAND "git" )
  446. endif ()
  447. endif ()
  448. macro(HPCC_ADD_EXECUTABLE target)
  449. add_executable(${target} ${ARGN})
  450. endmacro(HPCC_ADD_EXECUTABLE target)
  451. macro(HPCC_ADD_LIBRARY target)
  452. add_library(${target} ${ARGN})
  453. endmacro(HPCC_ADD_LIBRARY target)
  454. # This Macro is provided as Public domain from
  455. # http://www.cmake.org/Wiki/CMakeMacroParseArguments
  456. MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
  457. SET(DEFAULT_ARGS)
  458. FOREACH(arg_name ${arg_names})
  459. SET(${prefix}_${arg_name})
  460. ENDFOREACH(arg_name)
  461. FOREACH(option ${option_names})
  462. SET(${prefix}_${option} FALSE)
  463. ENDFOREACH(option)
  464. SET(current_arg_name DEFAULT_ARGS)
  465. SET(current_arg_list)
  466. FOREACH(arg ${ARGN})
  467. SET(larg_names ${arg_names})
  468. LIST(FIND larg_names "${arg}" is_arg_name)
  469. IF (is_arg_name GREATER -1)
  470. SET(${prefix}_${current_arg_name} ${current_arg_list})
  471. SET(current_arg_name ${arg})
  472. SET(current_arg_list)
  473. ELSE (is_arg_name GREATER -1)
  474. SET(loption_names ${option_names})
  475. LIST(FIND loption_names "${arg}" is_option)
  476. IF (is_option GREATER -1)
  477. SET(${prefix}_${arg} TRUE)
  478. ELSE (is_option GREATER -1)
  479. SET(current_arg_list ${current_arg_list} ${arg})
  480. ENDIF (is_option GREATER -1)
  481. ENDIF (is_arg_name GREATER -1)
  482. ENDFOREACH(arg)
  483. SET(${prefix}_${current_arg_name} ${current_arg_list})
  484. ENDMACRO(PARSE_ARGUMENTS)
  485. # This macro allows for disabling a directory based on the value of a variable passed to the macro.
  486. #
  487. # ex. HPCC_ADD_SUBDIRECORY(roxie ${CLIENTTOOLS_ONLY})
  488. #
  489. # This call will disable the roxie dir if -DCLIENTTOOLS_ONLY=ON is set at config time.
  490. #
  491. macro(HPCC_ADD_SUBDIRECTORY)
  492. set(adddir OFF)
  493. PARSE_ARGUMENTS(_HPCC_SUB "" "" ${ARGN})
  494. LIST(GET _HPCC_SUB_DEFAULT_ARGS 0 subdir)
  495. set(flags ${_HPCC_SUB_DEFAULT_ARGS})
  496. LIST(REMOVE_AT flags 0)
  497. LIST(LENGTH flags length)
  498. if(NOT length)
  499. set(adddir ON)
  500. else()
  501. foreach(f ${flags})
  502. if(${f})
  503. set(adddir ON)
  504. endif()
  505. endforeach()
  506. endif()
  507. if ( adddir )
  508. add_subdirectory(${subdir})
  509. endif()
  510. endmacro(HPCC_ADD_SUBDIRECTORY)
  511. set ( SCM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated )
  512. ###############################################################
  513. # Macro for Logging Plugin build in CMake
  514. macro(LOG_PLUGIN)
  515. PARSE_ARGUMENTS(pLOG
  516. "OPTION;MDEPS"
  517. ""
  518. ${ARGN})
  519. LIST(GET pLOG_DEFAULT_ARGS 0 PLUGIN_NAME)
  520. if(${pLOG_OPTION})
  521. message(STATUS "Building Plugin: ${PLUGIN_NAME}" )
  522. else()
  523. message(WARNING "Not Building Plugin: ${PLUGIN_NAME}")
  524. foreach (dep ${pLOG_MDEPS})
  525. message(WARNING "Missing dependency: ${dep}")
  526. endforeach()
  527. if(NOT USE_OPTIONAL)
  528. message(FATAL_ERROR "Optional dependencies missing and USE_OPTIONAL OFF")
  529. endif()
  530. endif()
  531. endmacro()
  532. ###############################################################
  533. # Macro for adding an optional plugin to the CMake build.
  534. macro(ADD_PLUGIN)
  535. PARSE_ARGUMENTS(PLUGIN
  536. "PACKAGES;MINVERSION;MAXVERSION"
  537. ""
  538. ${ARGN})
  539. LIST(GET PLUGIN_DEFAULT_ARGS 0 PLUGIN_NAME)
  540. string(TOUPPER ${PLUGIN_NAME} name)
  541. set(ALL_PLUGINS_FOUND 1)
  542. set(PLUGIN_MDEPS ${PLUGIN_NAME}_mdeps)
  543. set(${PLUGIN_MDEPS} "")
  544. foreach(package ${PLUGIN_PACKAGES})
  545. set(findvar ${package}_FOUND)
  546. string(TOUPPER ${findvar} PACKAGE_FOUND)
  547. if("${PLUGIN_MINVERSION}" STREQUAL "")
  548. find_package(${package})
  549. else()
  550. set(findvar ${package}_VERSION_STRING)
  551. string(TOUPPER ${findvar} PACKAGE_VERSION_STRING)
  552. find_package(${package} ${PLUGIN_MINVERSION} )
  553. if ("${${PACKAGE_VERSION_STRING}}" VERSION_GREATER "${PLUGIN_MAXVERSION}")
  554. set(${ALL_PLUGINS_FOUND} 0)
  555. endif()
  556. endif()
  557. if(NOT ${PACKAGE_FOUND})
  558. set(ALL_PLUGINS_FOUND 0)
  559. set(${PLUGIN_MDEPS} ${${PLUGIN_MDEPS}} ${package})
  560. endif()
  561. endforeach()
  562. set(MAKE_${name} ${ALL_PLUGINS_FOUND})
  563. LOG_PLUGIN(${PLUGIN_NAME} OPTION ${ALL_PLUGINS_FOUND} MDEPS ${${PLUGIN_MDEPS}})
  564. if(${ALL_PLUGINS_FOUND})
  565. set(bPLUGINS ${bPLUGINS} ${PLUGIN_NAME})
  566. else()
  567. set(nbPLUGINS ${nbPLUGINS} ${PLUGIN_NAME})
  568. endif()
  569. endmacro()
  570. ##################################################################
  571. # Build tag generation
  572. set(projname ${HPCC_PROJECT})
  573. set(majorver ${HPCC_MAJOR})
  574. set(minorver ${HPCC_MINOR})
  575. set(point ${HPCC_POINT})
  576. if ( "${HPCC_MATURITY}" STREQUAL "release" )
  577. set(stagever "${HPCC_SEQUENCE}")
  578. else()
  579. set(stagever "${HPCC_MATURITY}${HPCC_SEQUENCE}")
  580. endif()
  581. set(version ${majorver}.${minorver}.${point})
  582. IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  583. set( stagever "${stagever}Debug" )
  584. ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  585. ###########################################################################
  586. if(USE_OPTIONAL)
  587. message(WARNING "USE_OPTIONAL set - missing dependencies for optional features will automatically disable them")
  588. endif()
  589. if(NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  590. message(STATUS "Using externals directory at ${EXTERNALS_DIRECTORY}")
  591. endif()
  592. IF ( NOT MAKE_DOCS_ONLY )
  593. IF ("${EXTERNALS_DIRECTORY}" STREQUAL "")
  594. SET(bisoncmd "bison")
  595. SET(flexcmd "flex")
  596. ELSE()
  597. IF (WIN32)
  598. SET(bisoncmdprefix "call")
  599. SET(flexcmdprefix "call")
  600. SET(bisoncmd "${EXTERNALS_DIRECTORY}\\bison\\bison.bat")
  601. SET(flexcmd "${EXTERNALS_DIRECTORY}\\bison\\flex.bat")
  602. ELSE ()
  603. SET(bisoncmd "${EXTERNALS_DIRECTORY}/bison/bison")
  604. SET(flexcmd "${EXTERNALS_DIRECTORY}/bison/flex")
  605. ENDIF()
  606. ENDIF()
  607. IF ("${BISON_VERSION}" STREQUAL "")
  608. IF (WIN32)
  609. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  610. STRING(REPLACE "/" "\\" BISON_exename "${bisoncmd}")
  611. ELSE()
  612. SET(BISON_exename "${bisoncmd}")
  613. ENDIF()
  614. EXECUTE_PROCESS(COMMAND ${BISON_exename} --version
  615. OUTPUT_VARIABLE BISON_version_output
  616. ERROR_VARIABLE BISON_version_error
  617. RESULT_VARIABLE BISON_version_result
  618. OUTPUT_STRIP_TRAILING_WHITESPACE)
  619. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" BISON_VERSION "${BISON_version_output}")
  620. ENDIF()
  621. IF ("${FLEX_VERSION}" STREQUAL "")
  622. IF (WIN32)
  623. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  624. STRING(REPLACE "/" "\\" FLEX_exename "${flexcmd}")
  625. ELSE()
  626. SET(FLEX_exename "${flexcmd}")
  627. ENDIF()
  628. EXECUTE_PROCESS(COMMAND ${FLEX_exename} --version
  629. OUTPUT_VARIABLE FLEX_version_output
  630. ERROR_VARIABLE FLEX_version_error
  631. RESULT_VARIABLE FLEX_version_result
  632. OUTPUT_STRIP_TRAILING_WHITESPACE)
  633. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" FLEX_VERSION "${FLEX_version_output}")
  634. ENDIF()
  635. IF ("${BISON_VERSION}" VERSION_LESS "2.4.1")
  636. MESSAGE(FATAL_ERROR "You need bison version 2.4.1 or later to build this project (version ${BISON_VERSION} detected)")
  637. ENDIF()
  638. message(STATUS "Found Bison v${BISON_VERSION}")
  639. IF ("${BISON_VERSION}" VERSION_LESS "2.7.0")
  640. #Ignore all warnings - not recommend to develope on this version!
  641. SET(bisonopt "-Wnone")
  642. ELSE()
  643. SET(bisonopt -Werror -Wno-other)
  644. ENDIF()
  645. IF ("${BISON_VERSION}" VERSION_LESS "3.0.0")
  646. SET(bisonopt ${bisonopt} --name-prefix=eclyy)
  647. SET(ENV{BISON_MAJOR_VER} "2")
  648. ELSE()
  649. SET(bisonopt ${bisonopt} -Dapi.prefix={eclyy})
  650. SET(ENV{BISON_MAJOR_VER} "3")
  651. ENDIF()
  652. IF ("${FLEX_VERSION}" VERSION_LESS "2.5.35")
  653. MESSAGE(FATAL_ERROR "You need flex version 2.5.35 or later to build this project (version ${FLEX_VERSION} detected)")
  654. ENDIF()
  655. IF (CMAKE_COMPILER_IS_GNUCXX)
  656. IF ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.7.3")
  657. MESSAGE(FATAL_ERROR "You need Gnu c++ version 4.7.3 or later to build this project (version ${CMAKE_CXX_COMPILER_VERSION} detected)")
  658. ENDIF()
  659. ENDIF()
  660. ENDIF()
  661. ###########################################################################
  662. # External library setup - some can be optionally selected based on USE_xxx flags, some are required
  663. IF (MAKE_DOCS)
  664. find_package(XSLTPROC)
  665. IF (XSLTPROC_FOUND)
  666. add_definitions (-D_USE_XSLTPROC)
  667. ELSE()
  668. message(FATAL_ERROR "XSLTPROC requested but package not found")
  669. ENDIF()
  670. find_package(FOP)
  671. IF (FOP_FOUND)
  672. add_definitions (-D_USE_FOP)
  673. ELSE()
  674. message(FATAL_ERROR "FOP requested but package not found")
  675. ENDIF()
  676. IF ( DOCS_AUTO )
  677. find_package(SAXON)
  678. IF (SAXON_FOUND)
  679. add_definitions (-D_USE_SAXON)
  680. ELSE()
  681. message(FATAL_ERROR "SAXON, a XSLT and XQuery processor, is required for documentation build but not found.")
  682. ENDIF()
  683. ENDIF()
  684. ENDIF(MAKE_DOCS)
  685. IF ( NOT MAKE_DOCS_ONLY )
  686. IF (USE_OPENLDAP)
  687. find_package(OPENLDAP)
  688. IF (OPENLDAP_FOUND)
  689. add_definitions (-D_USE_OPENLDAP)
  690. ELSE()
  691. message(FATAL_ERROR "OPENLDAP requested but package not found")
  692. ENDIF()
  693. ELSE()
  694. add_definitions (-D_NO_LDAP)
  695. ENDIF(USE_OPENLDAP)
  696. IF (USE_CPPUNIT)
  697. find_package(CPPUNIT)
  698. IF (CPPUNIT_FOUND)
  699. add_definitions (-D_USE_CPPUNIT)
  700. include_directories(${CPPUNIT_INCLUDE_DIR})
  701. ELSE()
  702. message(FATAL_ERROR "CPPUNIT requested but package not found")
  703. ENDIF()
  704. ELSE()
  705. SET(CPPUNIT_INCLUDE_DIR "")
  706. SET(CPPUNIT_LIBRARIES "")
  707. ENDIF(USE_CPPUNIT)
  708. IF (USE_AERON)
  709. add_definitions (-D_USE_AERON)
  710. ENDIF(USE_AERON)
  711. IF (USE_ICU)
  712. find_package(ICU)
  713. IF (ICU_FOUND)
  714. add_definitions (-D_USE_ICU)
  715. IF (NOT WIN32)
  716. add_definitions (-DUCHAR_TYPE=uint16_t)
  717. ENDIF()
  718. include_directories(${ICU_INCLUDE_DIR})
  719. ELSE()
  720. message(FATAL_ERROR "ICU requested but package not found")
  721. ENDIF()
  722. ENDIF(USE_ICU)
  723. if(USE_XALAN)
  724. find_package(XALAN)
  725. if (XALAN_FOUND)
  726. add_definitions (-D_USE_XALAN)
  727. else()
  728. message(FATAL_ERROR "XALAN requested but package not found")
  729. endif()
  730. endif(USE_XALAN)
  731. if(USE_LIBXSLT)
  732. find_package(LIBXSLT)
  733. if (LIBXSLT_FOUND)
  734. add_definitions (-D_USE_LIBXSLT)
  735. else()
  736. message(FATAL_ERROR "LIBXSLT requested but package not found")
  737. endif()
  738. endif(USE_LIBXSLT)
  739. if(USE_XERCES)
  740. find_package(XERCES)
  741. if (XERCES_FOUND)
  742. add_definitions (-D_USE_XERCES)
  743. else()
  744. message(FATAL_ERROR "XERCES requested but package not found")
  745. endif()
  746. endif(USE_XERCES)
  747. if(USE_LIBXML2)
  748. find_package(LIBXML2)
  749. if (LIBXML2_FOUND)
  750. add_definitions (-D_USE_LIBXML2)
  751. else()
  752. message(FATAL_ERROR "LIBXML2 requested but package not found")
  753. endif()
  754. endif(USE_LIBXML2)
  755. if(USE_CBLAS)
  756. find_package(CBLAS)
  757. if(CBLAS_FOUND)
  758. add_definitions(-D_USE_CBLAS)
  759. else()
  760. message(FATAL_ERROR "CBLAS requested but package not found")
  761. endif()
  762. endif(USE_CBLAS)
  763. if(USE_ZLIB)
  764. find_package(ZLIB)
  765. if (ZLIB_FOUND)
  766. add_definitions (-D_USE_ZLIB)
  767. else()
  768. message(FATAL_ERROR "ZLIB requested but package not found")
  769. endif()
  770. endif(USE_ZLIB)
  771. if(USE_LIBARCHIVE)
  772. if (WIN32)
  773. if(NOT USE_ZLIB)
  774. message(FATAL ERROR "LIBARCHIVE requires ZLIB")
  775. endif(NOT USE_ZLIB)
  776. find_package(BZip2)
  777. if (BZIP2_FOUND)
  778. add_definitions (-D_USE_BZIP2)
  779. else()
  780. message(FATAL_ERROR "LIBARCHIVE requires BZIP2 but package not found")
  781. endif()
  782. endif (WIN32)
  783. find_package(LIBARCHIVE)
  784. if (LIBARCHIVE_FOUND)
  785. add_definitions (-D_USE_LIBARCHIVE)
  786. else()
  787. message(FATAL_ERROR "LIBARCHIVE requested but package not found")
  788. endif()
  789. endif(USE_LIBARCHIVE)
  790. if(USE_URIPARSER)
  791. find_package(Uriparser)
  792. if (URIPARSER_FOUND)
  793. add_definitions (-D_USE_URIPARSER)
  794. else()
  795. message(FATAL_ERROR "URIPARSER requested but package not found")
  796. endif()
  797. endif(USE_URIPARSER)
  798. if(USE_BOOST_REGEX)
  799. if(CENTOS_6_BOOST)
  800. include(${CMAKE_MODULE_PATH}/buildBOOST_REGEX.cmake)
  801. else()
  802. find_package(BOOST_REGEX)
  803. if (BOOST_REGEX_FOUND)
  804. message(STATUS "BOOST_REGEX enabled")
  805. add_definitions (-D_USE_BOOST_REGEX)
  806. else()
  807. message(FATAL_ERROR "BOOST_REGEX requested but package not found")
  808. endif()
  809. endif()
  810. else(USE_BOOST_REGEX)
  811. if (USE_C11_REGEX)
  812. if ((NOT CMAKE_COMPILER_IS_GNUCC) OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9.0))
  813. message(STATUS "C11_REGEX enabled")
  814. add_definitions (-D_USE_C11_REGEX)
  815. else()
  816. message(STATUS "C11_REGEX requested but not supported on this platform")
  817. endif()
  818. else(USE_C11_REGEX)
  819. message(STATUS "NO REGEX requested")
  820. endif(USE_C11_REGEX)
  821. endif(USE_BOOST_REGEX)
  822. if(USE_OPENSSL)
  823. find_package(OPENSSL)
  824. if (OPENSSL_FOUND)
  825. add_definitions (-D_USE_OPENSSL)
  826. include_directories(${OPENSSL_INCLUDE_DIR})
  827. link_directories(${OPENSSL_LIBRARY_DIR})
  828. else()
  829. message(FATAL_ERROR "OPENSSL requested but package not found")
  830. endif()
  831. endif(USE_OPENSSL)
  832. if(USE_MYSQL_REPOSITORY)
  833. find_package(MYSQL)
  834. if (MYSQL_FOUND)
  835. add_definitions (-D_USE_MYSQL_REPOSITORY)
  836. else()
  837. message(FATAL_ERROR "MYSQL requested but package not found")
  838. endif()
  839. else()
  840. add_definitions (-D_NO_MYSQL_REPOSITORY)
  841. endif(USE_MYSQL_REPOSITORY)
  842. if(USE_APR)
  843. find_package(APR)
  844. if (APR_FOUND)
  845. add_definitions (-D_USE_APR)
  846. include_directories(${APR_INCLUDE_DIR})
  847. link_directories(${APR_LIBRARY_DIR})
  848. else()
  849. message(FATAL_ERROR "APR requested but package not found")
  850. endif()
  851. if (APRUTIL_FOUND)
  852. include_directories(${APRUTIL_INCLUDE_DIR})
  853. link_directories(${APRUTIL_LIBRARY_DIR})
  854. else()
  855. message(FATAL_ERROR "APRUTIL requested but package not found")
  856. endif()
  857. else()
  858. add_definitions (-D_NO_APR)
  859. endif(USE_APR)
  860. if (USE_NUMA)
  861. find_package(NUMA)
  862. add_definitions (-D_USE_NUMA)
  863. if (NOT NUMA_FOUND)
  864. message(FATAL_ERROR "NUMA requested but package not found")
  865. endif()
  866. endif()
  867. if(USE_TBB)
  868. message(STATUS "Enabled use of TBB")
  869. add_definitions (-D_USE_TBB)
  870. endif(USE_TBB)
  871. if(USE_TBBMALLOC)
  872. message(STATUS "Enabled use of TBBMALLOC")
  873. add_definitions (-D_USE_TBBMALLOC)
  874. if(USE_TBBMALLOC_ROXIE)
  875. message(STATUS "Enabled use of TBBMALLOC_ROXIE")
  876. endif(USE_TBBMALLOC_ROXIE)
  877. endif(USE_TBBMALLOC)
  878. ENDIF()
  879. ###########################################################################
  880. ###
  881. ## The following sets the install directories and names.
  882. ###
  883. if ( PLATFORM OR PLUGIN )
  884. set ( CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" )
  885. else ( )
  886. set ( CMAKE_INSTALL_PREFIX "${INSTALL_DIR}/${version}/clienttools" )
  887. endif ( PLATFORM OR PLUGIN )
  888. if(APPLE)
  889. set(CMAKE_MACOSX_RPATH ON)
  890. endif()
  891. set (CMAKE_SKIP_BUILD_RPATH FALSE)
  892. set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  893. set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR};${CMAKE_INSTALL_PREFIX}/${PLUGINS_DIR};${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/external")
  894. set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  895. MACRO (FETCH_GIT_TAG workdir edition result)
  896. execute_process(COMMAND "${GIT_COMMAND}" describe --tags --dirty --abbrev=6 --match ${edition}*
  897. WORKING_DIRECTORY "${workdir}"
  898. OUTPUT_VARIABLE ${result}
  899. ERROR_QUIET
  900. OUTPUT_STRIP_TRAILING_WHITESPACE)
  901. if ("${${result}}" STREQUAL "")
  902. execute_process(COMMAND "${GIT_COMMAND}" describe --always --tags --all --abbrev=6 --dirty --long
  903. WORKING_DIRECTORY "${workdir}"
  904. OUTPUT_VARIABLE ${result}
  905. ERROR_QUIET
  906. OUTPUT_STRIP_TRAILING_WHITESPACE)
  907. endif()
  908. ENDMACRO()
  909. function(LIST_TO_STRING separator outvar)
  910. set ( tmp_str "" )
  911. list (LENGTH ARGN list_length)
  912. if ( ${list_length} LESS 2 )
  913. set ( tmp_str "${ARGN}" )
  914. else()
  915. math(EXPR last_index "${list_length} - 1")
  916. foreach( index RANGE ${last_index} )
  917. if ( ${index} GREATER 0 )
  918. list( GET ARGN ${index} element )
  919. set( tmp_str "${tmp_str}${separator}${element}")
  920. else()
  921. list( GET ARGN 0 element )
  922. set( tmp_str "${element}")
  923. endif()
  924. endforeach()
  925. endif()
  926. set ( ${outvar} "${tmp_str}" PARENT_SCOPE )
  927. endfunction()
  928. function(STRING_TO_LIST separator outvar stringvar)
  929. set( tmp_list "" )
  930. string(REPLACE "${separator}" ";" tmp_list ${stringvar})
  931. string(STRIP "${tmp_list}" tmp_list)
  932. set( ${outvar} "${tmp_list}" PARENT_SCOPE)
  933. endfunction()
  934. ###########################################################################
  935. ###
  936. ## The following sets the dependency list for a package
  937. ###
  938. ###########################################################################
  939. function(SET_DEPENDENCIES cpackvar)
  940. set(_tmp "")
  941. if(${cpackvar})
  942. STRING_TO_LIST(", " _tmp ${${cpackvar}})
  943. endif()
  944. foreach(element ${ARGN})
  945. list(APPEND _tmp ${element})
  946. endforeach()
  947. list(REMOVE_DUPLICATES _tmp)
  948. LIST_TO_STRING(", " _tmp "${_tmp}")
  949. set(${cpackvar} "${_tmp}" CACHE STRING "" FORCE)
  950. message(STATUS "Updated ${cpackvar} to ${${cpackvar}}")
  951. endfunction()
  952. MACRO(SIGN_MODULE module)
  953. if(SIGN_MODULES)
  954. set(GPG_COMMAND_STR "gpg")
  955. if(DEFINED SIGN_MODULES_PASSPHRASE)
  956. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --passphrase ${SIGN_MODULES_PASSPHRASE}")
  957. endif()
  958. if(DEFINED SIGN_MODULES_KEYID)
  959. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --default-key ${SIGN_MODULES_KEYID}")
  960. endif()
  961. if("${GPG_VERSION}" VERSION_GREATER "2.1")
  962. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --pinentry-mode loopback")
  963. endif()
  964. set(GPG_COMMAND_STR "${GPG_COMMAND_STR} --batch --yes --no-tty --output ${CMAKE_CURRENT_BINARY_DIR}/${module} --clearsign ${module}")
  965. add_custom_command(
  966. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module}
  967. COMMAND bash "-c" "${GPG_COMMAND_STR}"
  968. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module}
  969. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  970. COMMENT "Adding signed ${module} to project"
  971. )
  972. else()
  973. add_custom_command(
  974. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module}
  975. COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${module} ${CMAKE_CURRENT_BINARY_DIR}/${module}
  976. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module}
  977. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  978. COMMENT "Adding unsigned ${module} to project"
  979. VERBATIM
  980. )
  981. endif()
  982. # Use custom target to cause build to fail if dependency file isn't generated by gpg or cp commands
  983. get_filename_component(module_without_extension ${module} NAME_WE)
  984. add_custom_target(
  985. ${module_without_extension}-ecl ALL
  986. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${module}
  987. )
  988. if(SIGN_MODULES)
  989. add_dependencies(${module_without_extension}-ecl export-stdlib-pubkey)
  990. endif()
  991. ENDMACRO()
  992. endif ("${COMMONSETUP_DONE}" STREQUAL "")