commonSetup.cmake 38 KB

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