commonSetup.cmake 29 KB

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