commonSetup.cmake 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. ################################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ################################################################################
  17. # File : commonSetup.cmake
  18. #
  19. #########################################################
  20. # Description:
  21. # ------------
  22. # sets up various cmake options.
  23. #########################################################
  24. IF ("${COMMONSETUP_DONE}" STREQUAL "")
  25. SET (COMMONSETUP_DONE 1)
  26. MACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
  27. STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
  28. IF (insource)
  29. MESSAGE(FATAL_ERROR "${_errorMessage}")
  30. ENDIF(insource)
  31. ENDMACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
  32. macro_ensure_out_of_source_build("The LexisNexis Hpcc requires an out of source build.
  33. Please remove the directory ${CMAKE_BINARY_DIR}/CMakeFiles
  34. and the file ${CMAKE_BINARY_DIR}/CMakeCache.txt,
  35. then create a separate build directory and run 'cmake path_to_source [options]' there.")
  36. cmake_policy ( SET CMP0011 NEW )
  37. option(USE_BINUTILS "Enable use of binutils to embed workunit info into dhard objects" ON)
  38. option(USE_CPPUNIT "Enable unit tests (requires cppunit)" OFF)
  39. option(USE_OPENLDAP "Enable OpenLDAP support (requires OpenLDAP)" ON)
  40. option(USE_ICU "Enable unicode support (requires ICU)" ON)
  41. option(USE_BOOST_REGEX "Configure use of boost regex" ON)
  42. option(Boost_USE_STATIC_LIBS "Use boost_regex static library for RPM BUILD" OFF)
  43. option(USE_OPENSSL "Configure use of OpenSSL" ON)
  44. option(USE_ZLIB "Configure use of zlib" ON)
  45. option(USE_LIBARCHIVE "Configure use of libarchive" ON)
  46. option(USE_NATIVE_LIBRARIES "Search standard OS locations for thirdparty libraries" ON)
  47. option(USE_GIT_DESCRIBE "Use git describe to generate build tag" ON)
  48. option(CHECK_GIT_TAG "Require git tag to match the generated build tag" OFF)
  49. option(USE_XALAN "Configure use of xalan" ON)
  50. option(USE_LIBXSLT "Configure use of libxslt" OFF)
  51. option(MAKE_DOCS "Create documentation at build time." OFF)
  52. option(MAKE_DOCS_ONLY "Create a base build with only docs." OFF)
  53. option(DOCS_DRUPAL "Create Drupal HTML Docs" OFF)
  54. option(DOCS_EPUB "Create EPUB Docs" OFF)
  55. option(DOCS_MOBI "Create Mobi Docs" OFF)
  56. if ( USE_XALAN AND USE_LIBXSLT )
  57. set(USE_XALAN OFF)
  58. endif()
  59. if ( USE_LIBXSLT )
  60. set(USE_LIBXML2 ON)
  61. endif()
  62. if ( USE_XALAN )
  63. set(USE_XERCES ON)
  64. endif()
  65. if ( MAKE_DOCS_ONLY )
  66. set( MAKE_DOCS ON )
  67. endif()
  68. option(PORTALURL "Set url to hpccsystems portal download page")
  69. if ( NOT PORTALURL )
  70. set( PORTALURL "http://hpccsystems.com/download" )
  71. endif()
  72. set(CMAKE_MODULE_PATH "${HPCC_SOURCE_DIR}/cmake_modules/")
  73. ##########################################################
  74. # common compiler/linker flags
  75. if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
  76. set ( CMAKE_BUILD_TYPE "Release" )
  77. elseif (NOT "${CMAKE_BUILD_TYPE}" MATCHES "Debug|Release")
  78. message (FATAL_ERROR "Unknown build type $ENV{CMAKE_BUILD_TYPE}")
  79. endif ()
  80. message ("-- Making ${CMAKE_BUILD_TYPE} system")
  81. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  82. set ( ARCH64BIT 1 )
  83. else ()
  84. set ( ARCH64BIT 0 )
  85. endif ()
  86. message ("-- 64bit architecture is ${ARCH64BIT}")
  87. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DDEBUG")
  88. set (CMAKE_THREAD_PREFER_PTHREAD 1)
  89. find_package(Threads)
  90. IF (NOT THREADS_FOUND)
  91. message(FATAL_ERROR "No threading support found")
  92. ENDIF()
  93. if (WIN32)
  94. # On windows, the vcproj generator generates both windows and debug build capabilities, and the release mode is appended to the directory later
  95. # This output location matches what our existing windows release scripts expect - might make sense to move out of tree sometime though
  96. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  97. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  98. # Workaround CMake's odd decision to default windows stack size to 10000000
  99. STRING(REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  100. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
  101. if (${ARCH64BIT} EQUAL 0)
  102. add_definitions(/Zc:wchar_t-)
  103. endif ()
  104. if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
  105. add_definitions(/ZI)
  106. endif ()
  107. if ("${GIT_COMMAND}" STREQUAL "")
  108. set ( GIT_COMMAND "git.cmd" )
  109. endif ()
  110. else ()
  111. if (NOT CMAKE_USE_PTHREADS_INIT)
  112. message (FATAL_ERROR "pthreads support not detected")
  113. endif ()
  114. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin" )
  115. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/libs" )
  116. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  117. set (CMAKE_COMPILER_IS_CLANGXX 1)
  118. endif()
  119. if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
  120. message ("${CMAKE_CXX_COMPILER_ID}")
  121. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fPIC -fmessage-length=0 -Wformat -Wformat-security -Wformat-nonliteral -pthread")
  122. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic")
  123. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-default-inline -fno-inline-functions")
  124. endif ()
  125. if (CMAKE_COMPILER_IS_CLANGXX)
  126. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=logical-op-parentheses -Werror=bool-conversions -Werror=return-type -Werror=comment")
  127. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=bitwise-op-parentheses -Werror=tautological-compare")
  128. endif()
  129. # All of these are defined in platform.h too, but need to be defned before any system header is included
  130. ADD_DEFINITIONS (-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -D__USE_LARGEFILE64=1 -D__USE_FILE_OFFSET64=1)
  131. if ("${GIT_COMMAND}" STREQUAL "")
  132. set ( GIT_COMMAND "git" )
  133. endif ()
  134. endif ()
  135. macro(HPCC_ADD_LIBRARY target)
  136. add_library(${target} ${ARGN})
  137. endmacro(HPCC_ADD_LIBRARY target)
  138. set ( SCM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated )
  139. include_directories (${SCM_GENERATED_DIR})
  140. ##################################################################
  141. # Build tag generation
  142. set(projname ${HPCC_PROJECT})
  143. set(majorver ${HPCC_MAJOR})
  144. set(minorver ${HPCC_MINOR})
  145. set(point ${HPCC_POINT})
  146. if ( "${HPCC_MATURITY}" STREQUAL "release" )
  147. set(stagever "${HPCC_SEQUENCE}")
  148. else()
  149. set(stagever "${HPCC_SEQUENCE}${HPCC_MATURITY}")
  150. endif()
  151. set(version ${majorver}.${minorver}.${point})
  152. IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  153. set( stagever "${stagever}-Debug" )
  154. ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  155. ###########################################################################
  156. if (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  157. message ("-- Using externals directory at ${EXTERNALS_DIRECTORY}")
  158. endif()
  159. IF ( NOT MAKE_DOCS_ONLY )
  160. IF ("${EXTERNALS_DIRECTORY}" STREQUAL "")
  161. SET(bisoncmd "bison")
  162. SET(flexcmd "flex")
  163. ELSE()
  164. IF (WIN32)
  165. SET(bisoncmdprefix "call")
  166. SET(flexcmdprefix "call")
  167. SET(bisoncmd "${EXTERNALS_DIRECTORY}\\bison\\bison.bat")
  168. SET(flexcmd "${EXTERNALS_DIRECTORY}\\bison\\flex.bat")
  169. ELSE ()
  170. SET(bisoncmd "${EXTERNALS_DIRECTORY}/bison/bison")
  171. SET(flexcmd "${EXTERNALS_DIRECTORY}/bison/flex")
  172. ENDIF()
  173. ENDIF()
  174. IF ("${BISON_VERSION}" STREQUAL "")
  175. IF (WIN32)
  176. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  177. STRING(REPLACE "/" "\\" BISON_exename "${bisoncmd}")
  178. ELSE()
  179. SET(BISON_exename "${bisoncmd}")
  180. ENDIF()
  181. EXECUTE_PROCESS(COMMAND ${BISON_exename} --version
  182. OUTPUT_VARIABLE BISON_version_output
  183. ERROR_VARIABLE BISON_version_error
  184. RESULT_VARIABLE BISON_version_result
  185. OUTPUT_STRIP_TRAILING_WHITESPACE)
  186. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" BISON_VERSION "${BISON_version_output}")
  187. ENDIF()
  188. IF ("${FLEX_VERSION}" STREQUAL "")
  189. IF (WIN32)
  190. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  191. STRING(REPLACE "/" "\\" FLEX_exename "${flexcmd}")
  192. ELSE()
  193. SET(FLEX_exename "${flexcmd}")
  194. ENDIF()
  195. EXECUTE_PROCESS(COMMAND ${FLEX_exename} --version
  196. OUTPUT_VARIABLE FLEX_version_output
  197. ERROR_VARIABLE FLEX_version_error
  198. RESULT_VARIABLE FLEX_version_result
  199. OUTPUT_STRIP_TRAILING_WHITESPACE)
  200. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" FLEX_VERSION "${FLEX_version_output}")
  201. ENDIF()
  202. IF ("${BISON_VERSION}" VERSION_LESS "2.4.1")
  203. MESSAGE(FATAL_ERROR "You need bison version 2.4.1 or later to build this project (version ${BISON_VERSION} detected)")
  204. ENDIF()
  205. IF ("${FLEX_VERSION}" VERSION_LESS "2.5.35")
  206. MESSAGE(FATAL_ERROR "You need flex version 2.5.35 or later to build this project (version ${FLEX_VERSION} detected)")
  207. ENDIF()
  208. IF (CMAKE_COMPILER_IS_GNUCXX)
  209. EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GNUCXX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  210. IF ("${GNUCXX_VERSION}" VERSION_LESS "4.1.1")
  211. MESSAGE(FATAL_ERROR "You need Gnu c++ version 4.1.1 or later to build this project (version ${GNUCXX_VERSION} detected)")
  212. ENDIF()
  213. ENDIF()
  214. ENDIF()
  215. ###########################################################################
  216. # External library setup - some can be optionally selected based on USE_xxx flags, some are required
  217. IF (MAKE_DOCS)
  218. find_package(XSLTPROC)
  219. IF (XSLTPROC_FOUND)
  220. add_definitions (-D_USE_XSLTPROC)
  221. ELSE()
  222. message(FATAL_ERROR "XSLTPROC requested but package not found")
  223. ENDIF()
  224. find_package(FOP)
  225. IF (FOP_FOUND)
  226. add_definitions (-D_USE_FOP)
  227. ELSE()
  228. message(FATAL_ERROR "FOP requested but package not found")
  229. ENDIF()
  230. ENDIF(MAKE_DOCS)
  231. IF ( NOT MAKE_DOCS_ONLY )
  232. IF (USE_BINUTILS AND NOT WIN32)
  233. find_package(BINUTILS)
  234. IF (BINUTILS_FOUND)
  235. add_definitions (-D_USE_BINUTILS)
  236. ELSE()
  237. message(FATAL_ERROR "BINUTILS requested but package not found")
  238. ENDIF()
  239. ENDIF()
  240. IF (USE_OPENLDAP)
  241. find_package(OPENLDAP)
  242. IF (OPENLDAP_FOUND)
  243. add_definitions (-D_USE_OPENLDAP)
  244. ELSE()
  245. message(FATAL_ERROR "OPENLDAP requested but package not found")
  246. ENDIF()
  247. ELSE()
  248. add_definitions (-D_NO_LDAP)
  249. ENDIF(USE_OPENLDAP)
  250. IF (USE_CPPUNIT)
  251. find_package(CPPUNIT)
  252. IF (CPPUNIT_FOUND)
  253. add_definitions (-D_USE_CPPUNIT)
  254. include_directories(${CPPUNIT_INCLUDE_DIR})
  255. ELSE()
  256. message(FATAL_ERROR "CPPUNIT requested but package not found")
  257. ENDIF()
  258. ENDIF(USE_CPPUNIT)
  259. IF (USE_ICU)
  260. find_package(ICU)
  261. IF (ICU_FOUND)
  262. add_definitions (-D_USE_ICU)
  263. include_directories(${ICU_INCLUDE_DIR})
  264. ELSE()
  265. message(FATAL_ERROR "ICU requested but package not found")
  266. ENDIF()
  267. ENDIF(USE_ICU)
  268. if(USE_XALAN)
  269. find_package(XALAN)
  270. if (XALAN_FOUND)
  271. add_definitions (-D_USE_XALAN)
  272. else()
  273. message(FATAL_ERROR "XALAN requested but package not found")
  274. endif()
  275. endif(USE_XALAN)
  276. if(USE_LIBXSLT)
  277. find_package(LIBXSLT)
  278. if (LIBXSLT_FOUND)
  279. add_definitions (-D_USE_LIBSLT)
  280. else()
  281. message(FATAL_ERROR "LIBXSLT requested but package not found")
  282. endif()
  283. endif(USE_LIBXSLT)
  284. if(USE_XERCES)
  285. find_package(XERCES)
  286. if (XERCES_FOUND)
  287. add_definitions (-D_USE_XERCES)
  288. else()
  289. message(FATAL_ERROR "XERCES requested but package not found")
  290. endif()
  291. endif(USE_XERCES)
  292. if(USE_LIBXML2)
  293. find_package(LIBXML2)
  294. if (LIBXML2_FOUND)
  295. add_definitions (-D_USE_LIBXML2)
  296. else()
  297. message(FATAL_ERROR "LIBXML2 requested but package not found")
  298. endif()
  299. endif(USE_LIBXML2)
  300. if(USE_ZLIB)
  301. find_package(ZLIB)
  302. if (ZLIB_FOUND)
  303. add_definitions (-D_USE_ZLIB)
  304. else()
  305. message(FATAL_ERROR "ZLIB requested but package not found")
  306. endif()
  307. endif(USE_ZLIB)
  308. if(USE_LIBARCHIVE)
  309. find_package(LIBARCHIVE)
  310. if (LIBARCHIVE_FOUND)
  311. add_definitions (-D_USE_LIBARCHIVE)
  312. else()
  313. message(FATAL_ERROR "LIBARCHIVE requested but package not found")
  314. endif()
  315. endif(USE_LIBARCHIVE)
  316. if(USE_BOOST_REGEX)
  317. find_package(BOOST_REGEX)
  318. if (BOOST_REGEX_FOUND)
  319. add_definitions (-D_USE_BOOST_REGEX)
  320. else()
  321. message(FATAL_ERROR "BOOST_REGEX requested but package not found")
  322. endif()
  323. endif(USE_BOOST_REGEX)
  324. if(USE_OPENSSL)
  325. find_package(OPENSSL)
  326. if (OPENSSL_FOUND)
  327. add_definitions (-D_USE_OPENSSL)
  328. include_directories(${OPENSSL_INCLUDE_DIR})
  329. link_directories(${OPENSSL_LIBRARY_DIR})
  330. else()
  331. message(FATAL_ERROR "OPENSSL requested but package not found")
  332. endif()
  333. endif(USE_OPENSSL)
  334. if(USE_MYSQL)
  335. find_package(MYSQL)
  336. if (MYSQL_FOUND)
  337. add_definitions (-D_USE_MYSQL)
  338. else()
  339. message(FATAL_ERROR "MYSQL requested but package not found")
  340. endif()
  341. else()
  342. add_definitions (-D_NO_MYSQL)
  343. endif(USE_MYSQL)
  344. ENDIF()
  345. ###########################################################################
  346. ###
  347. ## The following sets the install directories and names.
  348. ###
  349. set ( OSSDIR "${DIR_NAME}" )
  350. set ( CPACK_INSTALL_PREFIX "${PREFIX}" )
  351. set ( CPACK_PACKAGING_INSTALL_PREFIX "${PREFIX}" )
  352. set ( CMAKE_INSTALL_PREFIX "${PREFIX}" )
  353. SET(CMAKE_SKIP_BUILD_RPATH FALSE)
  354. SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  355. SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OSSDIR}/lib")
  356. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  357. MACRO (FETCH_GIT_TAG workdir edition result)
  358. execute_process(COMMAND "${GIT_COMMAND}" describe --tags --dirty --abbrev=6 --match ${edition}*
  359. WORKING_DIRECTORY "${workdir}"
  360. OUTPUT_VARIABLE ${result}
  361. ERROR_QUIET
  362. OUTPUT_STRIP_TRAILING_WHITESPACE)
  363. if ("${${result}}" STREQUAL "")
  364. execute_process(COMMAND "${GIT_COMMAND}" describe --always --tags --all --abbrev=6 --dirty --long
  365. WORKING_DIRECTORY "${workdir}"
  366. OUTPUT_VARIABLE ${result}
  367. ERROR_QUIET
  368. OUTPUT_STRIP_TRAILING_WHITESPACE)
  369. endif()
  370. ENDMACRO()
  371. endif ("${COMMONSETUP_DONE}" STREQUAL "")