commonSetup.cmake 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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_NATIVE_LIBRARIES "Search standard OS locations for thirdparty libraries" ON)
  46. option(USE_GIT_DESCRIBE "Use git describe to generate build tag" ON)
  47. option(CHECK_GIT_TAG "Require git tag to match the generated build tag" OFF)
  48. option(USE_XALAN "Configure use of xalan" ON)
  49. option(USE_LIBXSLT "Configure use of libxslt" OFF)
  50. option(MAKE_DOCS "Create documentation at build time." OFF)
  51. option(MAKE_DOCS_ONLY "Create a base build with only docs." OFF)
  52. option(DOCS_DRUPAL "Create Drupal HTML Docs" OFF)
  53. option(DOCS_EPUB "Create EPUB Docs" OFF)
  54. option(DOCS_MOBI "Create Mobi Docs" OFF)
  55. if ( USE_XALAN AND USE_LIBXSLT )
  56. set(USE_XALAN OFF)
  57. endif()
  58. if ( USE_LIBXSLT )
  59. set(USE_LIBXML2 ON)
  60. endif()
  61. if ( USE_XALAN )
  62. set(USE_XERCES ON)
  63. endif()
  64. if ( MAKE_DOCS_ONLY )
  65. set( MAKE_DOCS ON )
  66. endif()
  67. option(PORTALURL "Set url to hpccsystems portal download page")
  68. if ( NOT PORTALURL )
  69. set( PORTALURL "http://hpccsystems.com/download" )
  70. endif()
  71. set(CMAKE_MODULE_PATH "${HPCC_SOURCE_DIR}/cmake_modules/")
  72. ##########################################################
  73. # common compiler/linker flags
  74. if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
  75. set ( CMAKE_BUILD_TYPE "Release" )
  76. elseif (NOT "${CMAKE_BUILD_TYPE}" MATCHES "Debug|Release")
  77. message (FATAL_ERROR "Unknown build type $ENV{CMAKE_BUILD_TYPE}")
  78. endif ()
  79. message ("-- Making ${CMAKE_BUILD_TYPE} system")
  80. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  81. set ( ARCH64BIT 1 )
  82. else ()
  83. set ( ARCH64BIT 0 )
  84. endif ()
  85. message ("-- 64bit architecture is ${ARCH64BIT}")
  86. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DDEBUG")
  87. set (CMAKE_THREAD_PREFER_PTHREAD 1)
  88. find_package(Threads)
  89. IF (NOT THREADS_FOUND)
  90. message(FATAL_ERROR "No threading support found")
  91. ENDIF()
  92. if (WIN32)
  93. # On windows, the vcproj generator generates both windows and debug build capabilities, and the release mode is appended to the directory later
  94. # This output location matches what our existing windows release scripts expect - might make sense to move out of tree sometime though
  95. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  96. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  97. # Workaround CMake's odd decision to default windows stack size to 10000000
  98. STRING(REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  99. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
  100. if (${ARCH64BIT} EQUAL 0)
  101. add_definitions(/Zc:wchar_t-)
  102. endif ()
  103. if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
  104. add_definitions(/ZI)
  105. endif ()
  106. if ("${GIT_COMMAND}" STREQUAL "")
  107. set ( GIT_COMMAND "git.cmd" )
  108. endif ()
  109. else ()
  110. if (NOT CMAKE_USE_PTHREADS_INIT)
  111. message (FATAL_ERROR "pthreads support not detected")
  112. endif ()
  113. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin" )
  114. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/libs" )
  115. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  116. set (CMAKE_COMPILER_IS_CLANGXX 1)
  117. endif()
  118. if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
  119. message ("${CMAKE_CXX_COMPILER_ID}")
  120. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fPIC -fmessage-length=0 -Wformat -Wformat-security -Wformat-nonliteral -pthread")
  121. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic")
  122. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-default-inline -fno-inline-functions")
  123. endif ()
  124. if (CMAKE_COMPILER_IS_CLANGXX)
  125. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=logical-op-parentheses -Werror=bool-conversions -Werror=return-type -Werror=comment")
  126. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=bitwise-op-parentheses -Werror=tautological-compare")
  127. endif()
  128. # All of these are defined in platform.h too, but need to be defned before any system header is included
  129. ADD_DEFINITIONS (-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -D__USE_LARGEFILE64=1 -D__USE_FILE_OFFSET64=1)
  130. if ("${GIT_COMMAND}" STREQUAL "")
  131. set ( GIT_COMMAND "git" )
  132. endif ()
  133. endif ()
  134. macro(HPCC_ADD_LIBRARY target)
  135. add_library(${target} ${ARGN})
  136. endmacro(HPCC_ADD_LIBRARY target)
  137. set ( SCM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated )
  138. include_directories (${SCM_GENERATED_DIR})
  139. ##################################################################
  140. # Build tag generation
  141. set(projname ${HPCC_PROJECT})
  142. set(majorver ${HPCC_MAJOR})
  143. set(minorver ${HPCC_MINOR})
  144. set(point ${HPCC_POINT})
  145. if ( "${HPCC_MATURITY}" STREQUAL "release" )
  146. set(stagever "${HPCC_SEQUENCE}")
  147. else()
  148. set(stagever "${HPCC_SEQUENCE}${HPCC_MATURITY}")
  149. endif()
  150. set(version ${majorver}.${minorver}.${point})
  151. IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  152. set( stagever "${stagever}-Debug" )
  153. ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  154. ###########################################################################
  155. if (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  156. message ("-- Using externals directory at ${EXTERNALS_DIRECTORY}")
  157. endif()
  158. IF ( NOT MAKE_DOCS_ONLY )
  159. IF ("${EXTERNALS_DIRECTORY}" STREQUAL "")
  160. SET(bisoncmd "bison")
  161. SET(flexcmd "flex")
  162. ELSE()
  163. IF (WIN32)
  164. SET(bisoncmdprefix "call")
  165. SET(flexcmdprefix "call")
  166. SET(bisoncmd "${EXTERNALS_DIRECTORY}\\bison\\bison.bat")
  167. SET(flexcmd "${EXTERNALS_DIRECTORY}\\bison\\flex.bat")
  168. ELSE ()
  169. SET(bisoncmd "${EXTERNALS_DIRECTORY}/bison/bison")
  170. SET(flexcmd "${EXTERNALS_DIRECTORY}/bison/flex")
  171. ENDIF()
  172. ENDIF()
  173. IF ("${BISON_VERSION}" STREQUAL "")
  174. IF (WIN32)
  175. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  176. STRING(REPLACE "/" "\\" BISON_exename "${bisoncmd}")
  177. ELSE()
  178. SET(BISON_exename "${bisoncmd}")
  179. ENDIF()
  180. EXECUTE_PROCESS(COMMAND ${BISON_exename} --version
  181. OUTPUT_VARIABLE BISON_version_output
  182. ERROR_VARIABLE BISON_version_error
  183. RESULT_VARIABLE BISON_version_result
  184. OUTPUT_STRIP_TRAILING_WHITESPACE)
  185. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" BISON_VERSION "${BISON_version_output}")
  186. ENDIF()
  187. IF ("${FLEX_VERSION}" STREQUAL "")
  188. IF (WIN32)
  189. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  190. STRING(REPLACE "/" "\\" FLEX_exename "${flexcmd}")
  191. ELSE()
  192. SET(FLEX_exename "${flexcmd}")
  193. ENDIF()
  194. EXECUTE_PROCESS(COMMAND ${FLEX_exename} --version
  195. OUTPUT_VARIABLE FLEX_version_output
  196. ERROR_VARIABLE FLEX_version_error
  197. RESULT_VARIABLE FLEX_version_result
  198. OUTPUT_STRIP_TRAILING_WHITESPACE)
  199. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" FLEX_VERSION "${FLEX_version_output}")
  200. ENDIF()
  201. IF ("${BISON_VERSION}" VERSION_LESS "2.4.1")
  202. MESSAGE(FATAL_ERROR "You need bison version 2.4.1 or later to build this project (version ${BISON_VERSION} detected)")
  203. ENDIF()
  204. IF ("${FLEX_VERSION}" VERSION_LESS "2.5.35")
  205. MESSAGE(FATAL_ERROR "You need flex version 2.5.35 or later to build this project (version ${FLEX_VERSION} detected)")
  206. ENDIF()
  207. IF (CMAKE_COMPILER_IS_GNUCXX)
  208. EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GNUCXX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  209. IF ("${GNUCXX_VERSION}" VERSION_LESS "4.1.1")
  210. MESSAGE(FATAL_ERROR "You need Gnu c++ version 4.1.1 or later to build this project (version ${GNUCXX_VERSION} detected)")
  211. ENDIF()
  212. ENDIF()
  213. ENDIF()
  214. ###########################################################################
  215. # External library setup - some can be optionally selected based on USE_xxx flags, some are required
  216. IF (MAKE_DOCS)
  217. find_package(XSLTPROC)
  218. IF (XSLTPROC_FOUND)
  219. add_definitions (-D_USE_XSLTPROC)
  220. ELSE()
  221. message(FATAL_ERROR "XSLTPROC requested but package not found")
  222. ENDIF()
  223. find_package(FOP)
  224. IF (FOP_FOUND)
  225. add_definitions (-D_USE_FOP)
  226. ELSE()
  227. message(FATAL_ERROR "FOP requested but package not found")
  228. ENDIF()
  229. ENDIF(MAKE_DOCS)
  230. IF ( NOT MAKE_DOCS_ONLY )
  231. IF (USE_BINUTILS AND NOT WIN32)
  232. find_package(BINUTILS)
  233. IF (BINUTILS_FOUND)
  234. add_definitions (-D_USE_BINUTILS)
  235. ELSE()
  236. message(FATAL_ERROR "BINUTILS requested but package not found")
  237. ENDIF()
  238. ENDIF()
  239. IF (USE_OPENLDAP)
  240. find_package(OPENLDAP)
  241. IF (OPENLDAP_FOUND)
  242. add_definitions (-D_USE_OPENLDAP)
  243. ELSE()
  244. message(FATAL_ERROR "OPENLDAP requested but package not found")
  245. ENDIF()
  246. ELSE()
  247. add_definitions (-D_NO_LDAP)
  248. ENDIF(USE_OPENLDAP)
  249. IF (USE_CPPUNIT)
  250. find_package(CPPUNIT)
  251. IF (CPPUNIT_FOUND)
  252. add_definitions (-D_USE_CPPUNIT)
  253. include_directories(${CPPUNIT_INCLUDE_DIR})
  254. ELSE()
  255. message(FATAL_ERROR "CPPUNIT requested but package not found")
  256. ENDIF()
  257. ENDIF(USE_CPPUNIT)
  258. IF (USE_ICU)
  259. find_package(ICU)
  260. IF (ICU_FOUND)
  261. add_definitions (-D_USE_ICU)
  262. include_directories(${ICU_INCLUDE_DIR})
  263. ELSE()
  264. message(FATAL_ERROR "ICU requested but package not found")
  265. ENDIF()
  266. ENDIF(USE_ICU)
  267. if(USE_XALAN)
  268. find_package(XALAN)
  269. if (XALAN_FOUND)
  270. add_definitions (-D_USE_XALAN)
  271. else()
  272. message(FATAL_ERROR "XALAN requested but package not found")
  273. endif()
  274. endif(USE_XALAN)
  275. if(USE_LIBXSLT)
  276. find_package(LIBXSLT)
  277. if (LIBXSLT_FOUND)
  278. add_definitions (-D_USE_LIBSLT)
  279. else()
  280. message(FATAL_ERROR "LIBXSLT requested but package not found")
  281. endif()
  282. endif(USE_LIBXSLT)
  283. if(USE_XERCES)
  284. find_package(XERCES)
  285. if (XERCES_FOUND)
  286. add_definitions (-D_USE_XERCES)
  287. else()
  288. message(FATAL_ERROR "XERCES requested but package not found")
  289. endif()
  290. endif(USE_XERCES)
  291. if(USE_LIBXML2)
  292. find_package(LIBXML2)
  293. if (LIBXML2_FOUND)
  294. add_definitions (-D_USE_LIBXML2)
  295. else()
  296. message(FATAL_ERROR "LIBXML2 requested but package not found")
  297. endif()
  298. endif(USE_LIBXML2)
  299. if(USE_ZLIB)
  300. find_package(ZLIB)
  301. if (ZLIB_FOUND)
  302. add_definitions (-D_USE_ZLIB)
  303. else()
  304. message(FATAL_ERROR "ZLIB requested but package not found")
  305. endif()
  306. endif(USE_ZLIB)
  307. if(USE_BOOST_REGEX)
  308. find_package(BOOST_REGEX)
  309. if (BOOST_REGEX_FOUND)
  310. add_definitions (-D_USE_BOOST_REGEX)
  311. else()
  312. message(FATAL_ERROR "BOOST_REGEX requested but package not found")
  313. endif()
  314. endif(USE_BOOST_REGEX)
  315. if(USE_OPENSSL)
  316. find_package(OPENSSL)
  317. if (OPENSSL_FOUND)
  318. add_definitions (-D_USE_OPENSSL)
  319. include_directories(${OPENSSL_INCLUDE_DIR})
  320. link_directories(${OPENSSL_LIBRARY_DIR})
  321. else()
  322. message(FATAL_ERROR "OPENSSL requested but package not found")
  323. endif()
  324. endif(USE_OPENSSL)
  325. if(USE_MYSQL)
  326. find_package(MYSQL)
  327. if (MYSQL_FOUND)
  328. add_definitions (-D_USE_MYSQL)
  329. else()
  330. message(FATAL_ERROR "MYSQL requested but package not found")
  331. endif()
  332. else()
  333. add_definitions (-D_NO_MYSQL)
  334. endif(USE_MYSQL)
  335. ENDIF()
  336. ###########################################################################
  337. ###
  338. ## The following sets the install directories and names.
  339. ###
  340. set ( OSSDIR "${DIR_NAME}" )
  341. set ( CPACK_INSTALL_PREFIX "${PREFIX}" )
  342. set ( CPACK_PACKAGING_INSTALL_PREFIX "${PREFIX}" )
  343. set ( CMAKE_INSTALL_PREFIX "${PREFIX}" )
  344. SET(CMAKE_SKIP_BUILD_RPATH FALSE)
  345. SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  346. SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OSSDIR}/lib")
  347. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  348. endif ("${COMMONSETUP_DONE}" STREQUAL "")