commonSetup.cmake 29 KB

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