commonSetup.cmake 14 KB

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