commonSetup.cmake 42 KB

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