commonSetup.cmake 29 KB

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