commonSetup.cmake 37 KB

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