commonSetup.cmake 37 KB

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