commonSetup.cmake 29 KB

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