commonSetup.cmake 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  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. cmake_policy ( SET CMP0054 NEW )
  39. endif()
  40. option(CLIENTTOOLS "Enable the building/inclusion of a Client Tools component." ON)
  41. option(PLATFORM "Enable the building/inclusion of a Platform component." ON)
  42. option(DEVEL "Enable the building/inclusion of a Development component." OFF)
  43. option(CLIENTTOOLS_ONLY "Enable the building of Client Tools only." OFF)
  44. option(TEST_PLUGINS "Enable the building of platform and all plugins for testing purposes" OFF)
  45. option(PLUGIN "Enable building of a plugin" OFF)
  46. if (APPLE OR WIN32)
  47. option(USE_BINUTILS "Enable use of binutils to embed workunit info into shared objects" OFF)
  48. else()
  49. option(USE_BINUTILS "Enable use of binutils to embed workunit info into shared objects" ON)
  50. endif()
  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. option(Boost_USE_STATIC_LIBS "Use boost_regex static library for RPM BUILD" OFF)
  56. option(USE_OPENSSL "Configure use of OpenSSL" ON)
  57. option(USE_ZLIB "Configure use of zlib" ON)
  58. if (WIN32)
  59. option(USE_GIT "Configure use of GIT (Hooks)" OFF)
  60. else()
  61. option(USE_GIT "Configure use of GIT (Hooks)" ON)
  62. endif()
  63. option(USE_LIBARCHIVE "Configure use of libarchive" ON)
  64. option(USE_URIPARSER "Configure use of uriparser" OFF)
  65. option(USE_NATIVE_LIBRARIES "Search standard OS locations for thirdparty libraries" ON)
  66. option(USE_GIT_DESCRIBE "Use git describe to generate build tag" ON)
  67. option(CHECK_GIT_TAG "Require git tag to match the generated build tag" OFF)
  68. option(USE_XALAN "Configure use of xalan" OFF)
  69. option(USE_APR "Configure use of Apache Software Foundation (ASF) Portable Runtime (APR) libraries" ON)
  70. option(USE_LIBXSLT "Configure use of libxslt" ON)
  71. option(MAKE_DOCS "Create documentation at build time." OFF)
  72. option(MAKE_DOCS_ONLY "Create a base build with only docs." OFF)
  73. option(DOCS_DRUPAL "Create Drupal HTML Docs" OFF)
  74. option(DOCS_EPUB "Create EPUB Docs" OFF)
  75. option(DOCS_MOBI "Create Mobi Docs" OFF)
  76. option(DOCS_AUTO "DOCS automation" OFF)
  77. option(USE_RESOURCE "Use resource download in ECLWatch" OFF)
  78. option(GENERATE_COVERAGE_INFO "Generate coverage info for gcov" OFF)
  79. option(USE_SIGNED_CHAR "Build system with default char type is signed" OFF)
  80. option(USE_UNSIGNED_CHAR "Build system with default char type is unsigned" OFF)
  81. # Generates code that is more efficient, but will cause problems if target platforms do not support it.
  82. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  83. option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" ON)
  84. else()
  85. option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" OFF)
  86. endif()
  87. # Plugin options
  88. option(REMBED "Create a package with ONLY the R plugin" OFF)
  89. option(V8EMBED "Create a package with ONLY the v8embed plugin" OFF)
  90. option(MEMCACHED "Create a package with ONLY the memcached plugin" OFF)
  91. option(PYEMBED "Create a package with ONLY the pyembed plugin" OFF)
  92. option(REDIS "Create a package with ONLY the redis plugin" OFF)
  93. option(MYSQLEMBED "Create a package with ONLY the mysql plugin" OFF)
  94. option(JAVAEMBED "Create a package with ONLY the javaembed plugin" OFF)
  95. option(SQLITE3EMBED "Create a package with ONLY the sqlite3embed plugin" OFF)
  96. option(CASSANDRAEMBED "Create a package with ONLY the cassandraembed plugin" OFF)
  97. option(KAFKA "Create a package with ONLY the kafkaembed plugin" OFF)
  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. endif()
  103. option(LOGGING_SERVICE "Configure use of logging service" ON)
  104. option(USE_OPTIONAL "Automatically disable requested features with missing dependencies" ON)
  105. if(REMBED OR V8EMBED OR MEMCACHED OR PYEMBED OR REDIS OR JAVAEMBED OR MYSQLEMBED
  106. OR SQLITE3EMBED OR CASSANDRAEMBED OR KAFKA)
  107. set(PLUGIN ON)
  108. set(CLIENTTOOLS OFF)
  109. set(PLATFORM OFF)
  110. set(TEST_PLUGINS OFF)
  111. endif()
  112. if(REMBED)
  113. if(DEFINED pluginname)
  114. message(FATAL_ERROR "Cannot enable rembed, already declared ${pluginname}")
  115. else()
  116. set(pluginname "rembed")
  117. endif()
  118. endif()
  119. if(V8EMBED)
  120. if(DEFINED pluginname)
  121. message(FATAL_ERROR "Cannot enable v8embed, already declared ${pluginname}")
  122. else()
  123. set(pluginname "v8embed")
  124. endif()
  125. endif()
  126. if(MEMCACHED)
  127. if(DEFINED pluginname)
  128. message(FATAL_ERROR "Cannot enable memcached, already declared ${pluginname}")
  129. else()
  130. set(pluginname "memcached")
  131. endif()
  132. endif()
  133. if(PYEMBED)
  134. if(DEFINED pluginname)
  135. message(FATAL_ERROR "Cannot enable pyembed, already declared ${pluginname}")
  136. else()
  137. set(pluginname "pyembed")
  138. endif()
  139. endif()
  140. if(REDIS)
  141. if(DEFINED pluginname)
  142. message(FATAL_ERROR "Cannot enable redis, already declared ${pluginname}")
  143. else()
  144. set(pluginname "redis")
  145. endif()
  146. endif()
  147. if(JAVAEMBED)
  148. if(DEFINED pluginname)
  149. message(FATAL_ERROR "Cannot enable javaembed, already declared ${pluginname}")
  150. else()
  151. set(pluginname "javaembed")
  152. endif()
  153. endif()
  154. if(MYSQLEMBED)
  155. if(DEFINED pluginname)
  156. message(FATAL_ERROR "Cannot enable mysqlembed, already declared ${pluginname}")
  157. else()
  158. set(pluginname "mysqlembed")
  159. endif()
  160. endif()
  161. if(SQLITE3EMBED)
  162. if(DEFINED pluginname)
  163. message(FATAL_ERROR "Cannot enable sqlite3embed, already declared ${pluginname}")
  164. else()
  165. set(pluginname "sqlite3embed")
  166. endif()
  167. endif()
  168. if(CASSANDRAEMBED)
  169. if(DEFINED pluginname)
  170. message(FATAL_ERROR "Cannot enable cassandraembed, already declared ${pluginname}")
  171. else()
  172. set(pluginname "cassandraembed")
  173. endif()
  174. endif()
  175. if(KAFKA)
  176. if(DEFINED pluginname)
  177. message(FATAL_ERROR "Cannot enable kafka, already declared ${pluginname}")
  178. else()
  179. set(pluginname "kafka")
  180. endif()
  181. endif()
  182. if ( USE_XALAN AND USE_LIBXSLT )
  183. set(USE_LIBXSLT OFF)
  184. endif()
  185. if ( USE_LIBXSLT )
  186. set(USE_LIBXML2 ON)
  187. endif()
  188. if ( USE_XALAN )
  189. set(USE_XERCES ON)
  190. endif()
  191. if ( MAKE_DOCS AND CLIENTTOOLS_ONLY )
  192. set( MAKE_DOCS OFF )
  193. endif()
  194. if ( MAKE_DOCS_ONLY AND NOT CLIENTTOOLS_ONLY )
  195. set( MAKE_DOCS ON )
  196. if ( USE_DOCS_AUTO )
  197. set ( DOCS_AUTO ON)
  198. endif()
  199. endif()
  200. if ( CLIENTTOOLS_ONLY )
  201. set(PLATFORM OFF)
  202. set(DEVEL OFF)
  203. endif()
  204. # Leave REMBED OFF for compliance with licensing
  205. if(TEST_PLUGINS)
  206. set(V8EMBED ON)
  207. set(MEMCACHED ON)
  208. set(PYEMBED ON)
  209. set(REDIS ON)
  210. set(MYSQLEMBED ON)
  211. set(JAVAEMBED ON)
  212. set(SQLITE3EMBED ON)
  213. set(CASSANDRAEMBED ON)
  214. set(KAFKA ON)
  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. ##########################################################
  222. # common compiler/linker flags
  223. if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
  224. set ( CMAKE_BUILD_TYPE "Release" )
  225. elseif (NOT "${CMAKE_BUILD_TYPE}" MATCHES "Debug|Release|RelWithDebInfo")
  226. message (FATAL_ERROR "Unknown build type ${CMAKE_BUILD_TYPE}")
  227. endif ()
  228. message ("-- Making ${CMAKE_BUILD_TYPE} system")
  229. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  230. set ( ARCH64BIT 1 )
  231. else ()
  232. set ( ARCH64BIT 0 )
  233. endif ()
  234. message ("-- 64bit architecture is ${ARCH64BIT}")
  235. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DDEBUG")
  236. IF (USE_INLINE_TSC)
  237. add_definitions (-DINLINE_GET_CYCLES_NOW)
  238. ENDIF()
  239. set (CMAKE_THREAD_PREFER_PTHREAD 1)
  240. find_package(Threads)
  241. IF (NOT THREADS_FOUND)
  242. message(FATAL_ERROR "No threading support found")
  243. ENDIF()
  244. if (NOT APPLE AND NOT WIN32)
  245. find_package(NUMA)
  246. if (NOT NUMA_FOUND)
  247. message(FATAL_ERROR "Support for numa not found")
  248. endif()
  249. endif()
  250. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  251. set (CMAKE_COMPILER_IS_CLANGXX 1)
  252. endif()
  253. if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
  254. set (CMAKE_COMPILER_IS_CLANG 1)
  255. endif()
  256. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  257. execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_C_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  258. endif ()
  259. if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
  260. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  261. endif()
  262. if (CMAKE_COMPILER_IS_CLANGXX)
  263. execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
  264. if (${clang_full_version_string} MATCHES "Apple LLVM version ([0-9]+\\.[0-9]+\\.[0-9]+).*")
  265. string (REGEX REPLACE "Apple LLVM version ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" APPLE_CLANG_VERSION ${clang_full_version_string})
  266. endif()
  267. if (${clang_full_version_string} MATCHES ".*based on LLVM ([0-9]+\\.[0-9]+).*")
  268. string (REGEX REPLACE ".*based on LLVM ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION ${clang_full_version_string})
  269. else()
  270. if (${clang_full_version_string} MATCHES ".*clang version ([0-9]+\\.[0-9]+).*")
  271. string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION ${clang_full_version_string})
  272. endif()
  273. endif()
  274. endif ()
  275. if (WIN32)
  276. # On windows, the vcproj generator generates both windows and debug build capabilities, and the release mode is appended to the directory later
  277. # This output location matches what our existing windows release scripts expect - might make sense to move out of tree sometime though
  278. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  279. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  280. # Workaround CMake's odd decision to default windows stack size to 10000000
  281. STRING(REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  282. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
  283. if (${ARCH64BIT} EQUAL 1)
  284. add_definitions(/bigobj)
  285. endif ()
  286. if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
  287. if (${ARCH64BIT} EQUAL 0)
  288. add_definitions(/ZI)
  289. else()
  290. add_definitions(/Zi)
  291. endif ()
  292. endif ()
  293. if ("${GIT_COMMAND}" STREQUAL "")
  294. set ( GIT_COMMAND "git.cmd" )
  295. endif ()
  296. if (USE_SIGNED_CHAR AND USE_UNSIGNED_CHAR )
  297. message (FATAL_ERROR "Can't use USE_SIGNED_CHAR and USE_UNSIGNED_CHAR together!")
  298. else()
  299. if (USE_SIGNED_CHAR)
  300. message ("Build system with signed char type.")
  301. # This is default for MSVC
  302. endif ()
  303. if (USE_UNSIGNED_CHAR )
  304. message ("Build system with unsigned char type.")
  305. add_definitions(/J)
  306. endif ()
  307. endif ()
  308. else ()
  309. if (NOT CMAKE_USE_PTHREADS_INIT)
  310. message (FATAL_ERROR "pthreads support not detected")
  311. endif ()
  312. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin" )
  313. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/libs" )
  314. if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
  315. message ("Using compiler: ${CMAKE_CXX_COMPILER_ID} :: ${CMAKE_CXX_COMPILER_VERSION} :: ${CLANG_VERSION} :: ${APPLE_CLANG_VERSION}")
  316. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fPIC -fmessage-length=0 -Wformat -Wformat-security -Wformat-nonliteral -pthread -Wuninitialized")
  317. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic")
  318. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-inline-functions")
  319. if (CMAKE_COMPILER_IS_GNUCXX)
  320. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-default-inline")
  321. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.2.4 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.2.4)
  322. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -Werror=format-nonliteral")
  323. endif ()
  324. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.4.0)
  325. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
  326. endif ()
  327. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 2.95.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 2.95.3)
  328. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wparentheses")
  329. endif ()
  330. endif ()
  331. SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
  332. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  333. if (GENERATE_COVERAGE_INFO)
  334. message ("Build system with coverage.")
  335. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  336. endif()
  337. # Handle forced default char type
  338. if (USE_SIGNED_CHAR AND USE_UNSIGNED_CHAR )
  339. message (FATAL_ERROR "Can't use USE_SIGNED_CHAR and USE_UNSIGNED_CHAR together!")
  340. else()
  341. if (USE_SIGNED_CHAR)
  342. message ("Build system with signed char type.")
  343. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
  344. endif ()
  345. if (USE_UNSIGNED_CHAR )
  346. message ("Build system with unsigned char type.")
  347. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funsigned-char")
  348. endif ()
  349. endif ()
  350. endif ()
  351. if (CMAKE_COMPILER_IS_CLANGXX)
  352. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Werror=logical-op-parentheses -Werror=bool-conversions -Werror=return-type -Werror=comment")
  353. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=bitwise-op-parentheses -Werror=tautological-compare")
  354. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum -Wno-format-zero-length -Wno-switch")
  355. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") # Silence messages about pthread not being used when linking...
  356. if (CLANG_VERSION VERSION_GREATER 3.6 OR CLANG_VERSION VERSION_EQUAL 3.6 OR APPLE_CLANG_VERSION VERSION_GREATER 6.0)
  357. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pointer-bool-conversion")
  358. endif()
  359. endif()
  360. # All of these are defined in platform.h too, but need to be defned before any system header is included
  361. ADD_DEFINITIONS (-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -D__USE_LARGEFILE64=1 -D__USE_FILE_OFFSET64=1)
  362. if ("${GIT_COMMAND}" STREQUAL "")
  363. set ( GIT_COMMAND "git" )
  364. endif ()
  365. endif ()
  366. macro(HPCC_ADD_EXECUTABLE target)
  367. add_executable(${target} ${ARGN})
  368. endmacro(HPCC_ADD_EXECUTABLE target)
  369. macro(HPCC_ADD_LIBRARY target)
  370. add_library(${target} ${ARGN})
  371. endmacro(HPCC_ADD_LIBRARY target)
  372. # This Macro is provided as Public domain from
  373. # http://www.cmake.org/Wiki/CMakeMacroParseArguments
  374. MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
  375. SET(DEFAULT_ARGS)
  376. FOREACH(arg_name ${arg_names})
  377. SET(${prefix}_${arg_name})
  378. ENDFOREACH(arg_name)
  379. FOREACH(option ${option_names})
  380. SET(${prefix}_${option} FALSE)
  381. ENDFOREACH(option)
  382. SET(current_arg_name DEFAULT_ARGS)
  383. SET(current_arg_list)
  384. FOREACH(arg ${ARGN})
  385. SET(larg_names ${arg_names})
  386. LIST(FIND larg_names "${arg}" is_arg_name)
  387. IF (is_arg_name GREATER -1)
  388. SET(${prefix}_${current_arg_name} ${current_arg_list})
  389. SET(current_arg_name ${arg})
  390. SET(current_arg_list)
  391. ELSE (is_arg_name GREATER -1)
  392. SET(loption_names ${option_names})
  393. LIST(FIND loption_names "${arg}" is_option)
  394. IF (is_option GREATER -1)
  395. SET(${prefix}_${arg} TRUE)
  396. ELSE (is_option GREATER -1)
  397. SET(current_arg_list ${current_arg_list} ${arg})
  398. ENDIF (is_option GREATER -1)
  399. ENDIF (is_arg_name GREATER -1)
  400. ENDFOREACH(arg)
  401. SET(${prefix}_${current_arg_name} ${current_arg_list})
  402. ENDMACRO(PARSE_ARGUMENTS)
  403. # This macro allows for disabling a directory based on the value of a variable passed to the macro.
  404. #
  405. # ex. HPCC_ADD_SUBDIRECORY(roxie ${CLIENTTOOLS_ONLY})
  406. #
  407. # This call will disable the roxie dir if -DCLIENTTOOLS_ONLY=ON is set at config time.
  408. #
  409. macro(HPCC_ADD_SUBDIRECTORY)
  410. set(adddir OFF)
  411. PARSE_ARGUMENTS(_HPCC_SUB "" "" ${ARGN})
  412. LIST(GET _HPCC_SUB_DEFAULT_ARGS 0 subdir)
  413. set(flags ${_HPCC_SUB_DEFAULT_ARGS})
  414. LIST(REMOVE_AT flags 0)
  415. LIST(LENGTH flags length)
  416. if(NOT length)
  417. set(adddir ON)
  418. else()
  419. foreach(f ${flags})
  420. if(${f})
  421. set(adddir ON)
  422. endif()
  423. endforeach()
  424. endif()
  425. if ( adddir )
  426. add_subdirectory(${subdir})
  427. endif()
  428. endmacro(HPCC_ADD_SUBDIRECTORY)
  429. set ( SCM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated )
  430. ###############################################################
  431. # Macro for Logging Plugin build in CMake
  432. macro(LOG_PLUGIN)
  433. PARSE_ARGUMENTS(pLOG
  434. "OPTION;MDEPS"
  435. ""
  436. ${ARGN}
  437. )
  438. LIST(GET pLOG_DEFAULT_ARGS 0 PLUGIN_NAME)
  439. if ( ${pLOG_OPTION} )
  440. message(STATUS "Building Plugin: ${PLUGIN_NAME}" )
  441. else()
  442. message("---- WARNING -- Not Building Plugin: ${PLUGIN_NAME}")
  443. foreach (dep ${pLOG_MDEPS})
  444. MESSAGE("---- WARNING -- Missing dependency: ${dep}")
  445. endforeach()
  446. if (NOT USE_OPTIONAL)
  447. message(FATAL_ERROR "Optional dependencies missing and USE_OPTIONAL not set")
  448. endif()
  449. endif()
  450. endmacro()
  451. ###############################################################
  452. # Macro for adding an optional plugin to the CMake build.
  453. macro(ADD_PLUGIN)
  454. PARSE_ARGUMENTS(PLUGIN
  455. "PACKAGES;OPTION;MINVERSION;MAXVERSION"
  456. ""
  457. ${ARGN}
  458. )
  459. LIST(GET PLUGIN_DEFAULT_ARGS 0 PLUGIN_NAME)
  460. string(TOUPPER ${PLUGIN_NAME} name)
  461. set(ALL_PLUGINS_FOUND 1)
  462. set(PLUGIN_MDEPS ${PLUGIN_NAME}_mdeps)
  463. set(${PLUGIN_MDEPS} "")
  464. FOREACH(package ${PLUGIN_PACKAGES})
  465. set(findvar ${package}_FOUND)
  466. string(TOUPPER ${findvar} PACKAGE_FOUND)
  467. if ("${PLUGIN_MINVERSION}" STREQUAL "")
  468. find_package(${package})
  469. else()
  470. set(findvar ${package}_VERSION_STRING)
  471. string(TOUPPER ${findvar} PACKAGE_VERSION_STRING)
  472. find_package(${package} ${PLUGIN_MINVERSION} )
  473. if ("${${PACKAGE_VERSION_STRING}}" VERSION_GREATER "${PLUGIN_MAXVERSION}")
  474. set(${ALL_PLUGINS_FOUND} 0)
  475. endif()
  476. endif()
  477. if (NOT ${PACKAGE_FOUND})
  478. set(ALL_PLUGINS_FOUND 0)
  479. set(${PLUGIN_MDEPS} ${${PLUGIN_MDEPS}} ${package})
  480. endif()
  481. ENDFOREACH()
  482. option(${PLUGIN_OPTION} "Turn on optional plugin based on availability of dependencies" ${ALL_PLUGINS_FOUND})
  483. LOG_PLUGIN(${PLUGIN_NAME} OPTION ${PLUGIN_OPTION} MDEPS ${${PLUGIN_MDEPS}})
  484. if(${ALL_PLUGINS_FOUND})
  485. set(bPLUGINS ${bPLUGINS} ${PLUGIN_NAME})
  486. else()
  487. set(nbPLUGINS ${nbPLUGINS} ${PLUGIN_NAME})
  488. endif()
  489. endmacro()
  490. ##################################################################
  491. # Build tag generation
  492. set(projname ${HPCC_PROJECT})
  493. set(majorver ${HPCC_MAJOR})
  494. set(minorver ${HPCC_MINOR})
  495. set(point ${HPCC_POINT})
  496. if ( "${HPCC_MATURITY}" STREQUAL "release" )
  497. set(stagever "${HPCC_SEQUENCE}")
  498. else()
  499. set(stagever "${HPCC_MATURITY}${HPCC_SEQUENCE}")
  500. endif()
  501. set(version ${majorver}.${minorver}.${point})
  502. IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  503. set( stagever "${stagever}Debug" )
  504. ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  505. ###########################################################################
  506. if (USE_OPTIONAL)
  507. message ("-- USE_OPTIONAL set - missing dependencies for optional features will automatically disable them")
  508. endif()
  509. if (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  510. message ("-- Using externals directory at ${EXTERNALS_DIRECTORY}")
  511. endif()
  512. IF ( NOT MAKE_DOCS_ONLY )
  513. IF ("${EXTERNALS_DIRECTORY}" STREQUAL "")
  514. SET(bisoncmd "bison")
  515. SET(flexcmd "flex")
  516. ELSE()
  517. IF (WIN32)
  518. SET(bisoncmdprefix "call")
  519. SET(flexcmdprefix "call")
  520. SET(bisoncmd "${EXTERNALS_DIRECTORY}\\bison\\bison.bat")
  521. SET(flexcmd "${EXTERNALS_DIRECTORY}\\bison\\flex.bat")
  522. ELSE ()
  523. SET(bisoncmd "${EXTERNALS_DIRECTORY}/bison/bison")
  524. SET(flexcmd "${EXTERNALS_DIRECTORY}/bison/flex")
  525. ENDIF()
  526. ENDIF()
  527. IF ("${BISON_VERSION}" STREQUAL "")
  528. IF (WIN32)
  529. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  530. STRING(REPLACE "/" "\\" BISON_exename "${bisoncmd}")
  531. ELSE()
  532. SET(BISON_exename "${bisoncmd}")
  533. ENDIF()
  534. EXECUTE_PROCESS(COMMAND ${BISON_exename} --version
  535. OUTPUT_VARIABLE BISON_version_output
  536. ERROR_VARIABLE BISON_version_error
  537. RESULT_VARIABLE BISON_version_result
  538. OUTPUT_STRIP_TRAILING_WHITESPACE)
  539. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" BISON_VERSION "${BISON_version_output}")
  540. ENDIF()
  541. IF ("${FLEX_VERSION}" STREQUAL "")
  542. IF (WIN32)
  543. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  544. STRING(REPLACE "/" "\\" FLEX_exename "${flexcmd}")
  545. ELSE()
  546. SET(FLEX_exename "${flexcmd}")
  547. ENDIF()
  548. EXECUTE_PROCESS(COMMAND ${FLEX_exename} --version
  549. OUTPUT_VARIABLE FLEX_version_output
  550. ERROR_VARIABLE FLEX_version_error
  551. RESULT_VARIABLE FLEX_version_result
  552. OUTPUT_STRIP_TRAILING_WHITESPACE)
  553. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" FLEX_VERSION "${FLEX_version_output}")
  554. ENDIF()
  555. IF ("${BISON_VERSION}" VERSION_LESS "2.4.1")
  556. MESSAGE(FATAL_ERROR "You need bison version 2.4.1 or later to build this project (version ${BISON_VERSION} detected)")
  557. ENDIF()
  558. IF ("${FLEX_VERSION}" VERSION_LESS "2.5.35")
  559. MESSAGE(FATAL_ERROR "You need flex version 2.5.35 or later to build this project (version ${FLEX_VERSION} detected)")
  560. ENDIF()
  561. IF (CMAKE_COMPILER_IS_GNUCXX)
  562. IF ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.7.3")
  563. MESSAGE(FATAL_ERROR "You need Gnu c++ version 4.7.3 or later to build this project (version ${CMAKE_CXX_COMPILER_VERSION} detected)")
  564. ENDIF()
  565. ENDIF()
  566. ENDIF()
  567. ###########################################################################
  568. # External library setup - some can be optionally selected based on USE_xxx flags, some are required
  569. IF (MAKE_DOCS)
  570. find_package(XSLTPROC)
  571. IF (XSLTPROC_FOUND)
  572. add_definitions (-D_USE_XSLTPROC)
  573. ELSE()
  574. message(FATAL_ERROR "XSLTPROC requested but package not found")
  575. ENDIF()
  576. find_package(FOP)
  577. IF (FOP_FOUND)
  578. add_definitions (-D_USE_FOP)
  579. ELSE()
  580. message(FATAL_ERROR "FOP requested but package not found")
  581. ENDIF()
  582. if (DOCS_AUTO)
  583. if ("${CONFIGURATOR_DIRECTORY}" STREQUAL "")
  584. set(CONFIGURATOR_DIRECTORY ${HPCC_SOURCE_DIR}/../configurator)
  585. endif()
  586. endif()
  587. ENDIF(MAKE_DOCS)
  588. IF ( NOT MAKE_DOCS_ONLY )
  589. IF (USE_BINUTILS AND NOT WIN32 AND NOT APPLE)
  590. find_package(BINUTILS)
  591. IF (BINUTILS_FOUND)
  592. add_definitions (-D_USE_BINUTILS)
  593. ELSE()
  594. message(FATAL_ERROR "BINUTILS requested but package not found")
  595. ENDIF()
  596. ENDIF()
  597. IF (USE_OPENLDAP)
  598. find_package(OPENLDAP)
  599. IF (OPENLDAP_FOUND)
  600. add_definitions (-D_USE_OPENLDAP)
  601. ELSE()
  602. message(FATAL_ERROR "OPENLDAP requested but package not found")
  603. ENDIF()
  604. ELSE()
  605. add_definitions (-D_NO_LDAP)
  606. ENDIF(USE_OPENLDAP)
  607. IF (USE_CPPUNIT)
  608. find_package(CPPUNIT)
  609. IF (CPPUNIT_FOUND)
  610. add_definitions (-D_USE_CPPUNIT)
  611. include_directories(${CPPUNIT_INCLUDE_DIR})
  612. ELSE()
  613. message(FATAL_ERROR "CPPUNIT requested but package not found")
  614. ENDIF()
  615. ELSE()
  616. SET(CPPUNIT_INCLUDE_DIR "")
  617. SET(CPPUNIT_LIBRARIES "")
  618. ENDIF(USE_CPPUNIT)
  619. IF (USE_ICU)
  620. find_package(ICU)
  621. IF (ICU_FOUND)
  622. add_definitions (-D_USE_ICU)
  623. include_directories(${ICU_INCLUDE_DIR})
  624. ELSE()
  625. message(FATAL_ERROR "ICU requested but package not found")
  626. ENDIF()
  627. ENDIF(USE_ICU)
  628. if(USE_XALAN)
  629. find_package(XALAN)
  630. if (XALAN_FOUND)
  631. add_definitions (-D_USE_XALAN)
  632. else()
  633. message(FATAL_ERROR "XALAN requested but package not found")
  634. endif()
  635. endif(USE_XALAN)
  636. if(USE_LIBXSLT)
  637. find_package(LIBXSLT)
  638. if (LIBXSLT_FOUND)
  639. add_definitions (-D_USE_LIBXSLT)
  640. else()
  641. message(FATAL_ERROR "LIBXSLT requested but package not found")
  642. endif()
  643. endif(USE_LIBXSLT)
  644. if(USE_XERCES)
  645. find_package(XERCES)
  646. if (XERCES_FOUND)
  647. add_definitions (-D_USE_XERCES)
  648. else()
  649. message(FATAL_ERROR "XERCES requested but package not found")
  650. endif()
  651. endif(USE_XERCES)
  652. if(USE_LIBXML2)
  653. find_package(LIBXML2)
  654. if (LIBXML2_FOUND)
  655. add_definitions (-D_USE_LIBXML2)
  656. else()
  657. message(FATAL_ERROR "LIBXML2 requested but package not found")
  658. endif()
  659. endif(USE_LIBXML2)
  660. if(USE_ZLIB)
  661. find_package(ZLIB)
  662. if (ZLIB_FOUND)
  663. add_definitions (-D_USE_ZLIB)
  664. else()
  665. message(FATAL_ERROR "ZLIB requested but package not found")
  666. endif()
  667. endif(USE_ZLIB)
  668. if(USE_LIBARCHIVE)
  669. if (WIN32)
  670. if(NOT USE_ZLIB)
  671. message(FATAL ERROR "LIBARCHIVE requires ZLIB")
  672. endif(NOT USE_ZLIB)
  673. find_package(BZip2)
  674. if (BZIP2_FOUND)
  675. add_definitions (-D_USE_BZIP2)
  676. else()
  677. message(FATAL_ERROR "LIBARCHIVE requires BZIP2 but package not found")
  678. endif()
  679. endif (WIN32)
  680. find_package(LIBARCHIVE)
  681. if (LIBARCHIVE_FOUND)
  682. add_definitions (-D_USE_LIBARCHIVE)
  683. else()
  684. message(FATAL_ERROR "LIBARCHIVE requested but package not found")
  685. endif()
  686. endif(USE_LIBARCHIVE)
  687. if(USE_URIPARSER)
  688. find_package(Uriparser)
  689. if (URIPARSER_FOUND)
  690. add_definitions (-D_USE_URIPARSER)
  691. else()
  692. message(FATAL_ERROR "URIPARSER requested but package not found")
  693. endif()
  694. endif(USE_URIPARSER)
  695. if(USE_BOOST_REGEX)
  696. find_package(BOOST_REGEX)
  697. if (BOOST_REGEX_FOUND)
  698. add_definitions (-D_USE_BOOST_REGEX)
  699. else()
  700. message(FATAL_ERROR "BOOST_REGEX requested but package not found")
  701. endif()
  702. endif(USE_BOOST_REGEX)
  703. if(USE_OPENSSL)
  704. find_package(OPENSSL)
  705. if (OPENSSL_FOUND)
  706. add_definitions (-D_USE_OPENSSL)
  707. include_directories(${OPENSSL_INCLUDE_DIR})
  708. link_directories(${OPENSSL_LIBRARY_DIR})
  709. else()
  710. message(FATAL_ERROR "OPENSSL requested but package not found")
  711. endif()
  712. endif(USE_OPENSSL)
  713. if(USE_MYSQL_REPOSITORY)
  714. find_package(MYSQL)
  715. if (MYSQL_FOUND)
  716. add_definitions (-D_USE_MYSQL_REPOSITORY)
  717. else()
  718. message(FATAL_ERROR "MYSQL requested but package not found")
  719. endif()
  720. else()
  721. add_definitions (-D_NO_MYSQL_REPOSITORY)
  722. endif(USE_MYSQL_REPOSITORY)
  723. if(USE_APR)
  724. find_package(APR)
  725. if (APR_FOUND)
  726. add_definitions (-D_USE_APR)
  727. include_directories(${APR_INCLUDE_DIR})
  728. link_directories(${APR_LIBRARY_DIR})
  729. else()
  730. message(FATAL_ERROR "APR requested but package not found")
  731. endif()
  732. if (APRUTIL_FOUND)
  733. include_directories(${APRUTIL_INCLUDE_DIR})
  734. link_directories(${APRUTIL_LIBRARY_DIR})
  735. else()
  736. message(FATAL_ERROR "APRUTIL requested but package not found")
  737. endif()
  738. else()
  739. add_definitions (-D_NO_APR)
  740. endif(USE_APR)
  741. if(USE_TBB)
  742. find_package(TBB)
  743. if (TBB_FOUND)
  744. add_definitions (-D_USE_TBB)
  745. else()
  746. message(FATAL_ERROR "TBB requested but package not found")
  747. endif()
  748. else()
  749. set(TBB_INCLUDE_DIR "")
  750. endif(USE_TBB)
  751. ENDIF()
  752. ###########################################################################
  753. ###
  754. ## The following sets the install directories and names.
  755. ###
  756. if ( PLATFORM OR PLUGIN )
  757. set ( CMAKE_INSTALL_PREFIX "${PREFIX}/${DIR_NAME}" )
  758. else ( )
  759. set ( CMAKE_INSTALL_PREFIX "${PREFIX}/${DIR_NAME}/${version}/clienttools" )
  760. endif ( PLATFORM OR PLUGIN )
  761. set (CMAKE_SKIP_BUILD_RPATH FALSE)
  762. set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  763. set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  764. set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  765. if (APPLE)
  766. # used to locate libraries when compiling ECL
  767. set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  768. endif()
  769. MACRO (FETCH_GIT_TAG workdir edition result)
  770. execute_process(COMMAND "${GIT_COMMAND}" describe --tags --dirty --abbrev=6 --match ${edition}*
  771. WORKING_DIRECTORY "${workdir}"
  772. OUTPUT_VARIABLE ${result}
  773. ERROR_QUIET
  774. OUTPUT_STRIP_TRAILING_WHITESPACE)
  775. if ("${${result}}" STREQUAL "")
  776. execute_process(COMMAND "${GIT_COMMAND}" describe --always --tags --all --abbrev=6 --dirty --long
  777. WORKING_DIRECTORY "${workdir}"
  778. OUTPUT_VARIABLE ${result}
  779. ERROR_QUIET
  780. OUTPUT_STRIP_TRAILING_WHITESPACE)
  781. endif()
  782. ENDMACRO()
  783. function(LIST_TO_STRING separator outvar)
  784. set ( tmp_str "" )
  785. list (LENGTH ARGN list_length)
  786. if ( ${list_length} LESS 2 )
  787. set ( tmp_str "${ARGN}" )
  788. else()
  789. math(EXPR last_index "${list_length} - 1")
  790. foreach( index RANGE ${last_index} )
  791. if ( ${index} GREATER 0 )
  792. list( GET ARGN ${index} element )
  793. set( tmp_str "${tmp_str}${separator}${element}")
  794. else()
  795. list( GET ARGN 0 element )
  796. set( tmp_str "${element}")
  797. endif()
  798. endforeach()
  799. endif()
  800. set ( ${outvar} "${tmp_str}" PARENT_SCOPE )
  801. endfunction()
  802. function(STRING_TO_LIST separator outvar stringvar)
  803. set( tmp_list "" )
  804. string(REPLACE "${separator}" ";" tmp_list ${stringvar})
  805. string(STRIP "${tmp_list}" tmp_list)
  806. set( ${outvar} "${tmp_list}" PARENT_SCOPE)
  807. endfunction()
  808. ###########################################################################
  809. ###
  810. ## The following sets the dependency list for a package
  811. ###
  812. ###########################################################################
  813. function(SET_DEPENDENCIES cpackvar)
  814. set(_tmp "")
  815. if(${cpackvar})
  816. STRING_TO_LIST(", " _tmp ${${cpackvar}})
  817. endif()
  818. foreach(element ${ARGN})
  819. list(APPEND _tmp ${element})
  820. endforeach()
  821. list(REMOVE_DUPLICATES _tmp)
  822. LIST_TO_STRING(", " _tmp "${_tmp}")
  823. set(${cpackvar} "${_tmp}" CACHE STRING "" FORCE)
  824. message(STATUS "Updated ${cpackvar} to ${${cpackvar}}")
  825. endfunction()
  826. endif ("${COMMONSETUP_DONE}" STREQUAL "")