commonSetup.cmake 38 KB

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