commonSetup.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. # For options that we don't presently support setting to off, we have a SET() below rather than an option...
  38. option(USE_CPPUNIT "Enable unit tests (requires cppunit)" OFF)
  39. set (USE_OPENLDAP 1) # option(USE_OPENLDAP "Enable OpenLDAP support (requires OpenLDAP)" ON)
  40. set (USE_ICU 1) # option(USE_ICU "Enable unicode support (requires ICU)" ON)
  41. set (USE_XALAN 1) # option(USE_XALAN "Configure use of xalan" ON)
  42. set (USE_XERCES 1) # option(USE_XERCES "Configure use of xerces" ON)
  43. option(USE_BOOST_REGEX "Configure use of boost regex" ON)
  44. option(Boost_USE_STATIC_LIBS "Use boost_regex static library for RPM BUILD" OFF)
  45. set (USE_OPENSSL 1) # option(USE_OPENSSL "Configure use of OpenSSL" ON)
  46. option(USE_ZLIB "Configure use of zlib" ON)
  47. option(USE_NATIVE_LIBRARIES "Search standard OS locations for thirdparty libraries" ON)
  48. option(LEGACYTHOR "Turn on building of Legacy Thor" OFF)
  49. option(PORTALURL "Set url to hpccsystems portal download page")
  50. if ( NOT PORTALURL )
  51. set( PORTALURL "http://hpccsystems.com/download" )
  52. endif()
  53. ##########################################################
  54. # common compiler/linker flags
  55. if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
  56. set ( CMAKE_BUILD_TYPE "Release" )
  57. elseif (NOT "${CMAKE_BUILD_TYPE}" MATCHES "Debug|Release")
  58. message (FATAL_ERROR "Unknown build type $ENV{CMAKE_BUILD_TYPE}")
  59. endif ()
  60. message ("-- Making ${CMAKE_BUILD_TYPE} system")
  61. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  62. set ( ARCH64BIT 1 )
  63. else ()
  64. set ( ARCH64BIT 0 )
  65. endif ()
  66. message ("-- 64bit architecture is ${ARCH64BIT}")
  67. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DDEBUG")
  68. if (WIN32)
  69. # On windows, the vcproj generator generates both windows and debug build capabilities, and the release mode is appended to the directory later
  70. # This output location matches what our existing windows release scripts expect - might make sense to move out of tree sometime though
  71. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  72. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" )
  73. # Workaround CMake's odd decision to default windows stack size to 10000000
  74. STRING(REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  75. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
  76. if (${ARCH64BIT} EQUAL 0)
  77. add_definitions(/Zc:wchar_t-)
  78. endif ()
  79. if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
  80. add_definitions(/ZI)
  81. endif ()
  82. else ()
  83. set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin" )
  84. set ( LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/libs" )
  85. if (${CMAKE_COMPILER_IS_GNUCXX})
  86. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fPIC -fmessage-length=0")
  87. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --export-dynamic")
  88. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-default-inline -fno-inline-functions")
  89. endif ()
  90. # All of these are defined in platform.h too, but need to be defned before any system header is included
  91. ADD_DEFINITIONS (-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -D__USE_LARGEFILE64=1 -D__USE_FILE_OFFSET64=1)
  92. if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
  93. SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
  94. SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
  95. endif ()
  96. endif ()
  97. macro(HPCC_ADD_LIBRARY target)
  98. add_library(${target} ${ARGN})
  99. endmacro(HPCC_ADD_LIBRARY target)
  100. set ( SCM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated )
  101. include_directories (${SCM_GENERATED_DIR})
  102. ##################################################################
  103. # Build tag generation from svn info
  104. set(projname ${HPCC_PROJECT})
  105. set(majorver ${HPCC_MAJOR})
  106. set(minorver ${HPCC_MINOR})
  107. set(point ${HPCC_POINT})
  108. if ( "${HPCC_MATURITY}" STREQUAL "release" )
  109. set(stagever "")
  110. set(version ${majorver}.${minorver}.${point})
  111. else()
  112. set(stagever "${HPCC_MATURITY}${HPCC_SEQUENCE}")
  113. set(version ${majorver}.${minorver}.${point}_${stagever})
  114. endif()
  115. IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  116. set( version "${version}_Debug" )
  117. ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  118. ###########################################################################
  119. if (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  120. message ("-- Using externals directory at ${EXTERNALS_DIRECTORY}")
  121. endif()
  122. IF ("${EXTERNALS_DIRECTORY}" STREQUAL "")
  123. SET(bisoncmd "bison")
  124. SET(flexcmd "flex")
  125. ELSE()
  126. SET(bisoncmd "${EXTERNALS_DIRECTORY}/bison/bison")
  127. SET(flexcmd "${EXTERNALS_DIRECTORY}/bison/flex")
  128. ENDIF()
  129. IF ("${BISON_VERSION}" STREQUAL "")
  130. IF (WIN32)
  131. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  132. STRING(REPLACE "/" "\\" BISON_exename "${bisoncmd}")
  133. IF (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  134. set (BISON_exename "${BISON_exename}.bat")
  135. ENDIF()
  136. ELSE()
  137. SET(BISON_exename "${bisoncmd}")
  138. ENDIF()
  139. EXECUTE_PROCESS(COMMAND ${BISON_exename} --version
  140. OUTPUT_VARIABLE BISON_version_output
  141. ERROR_VARIABLE BISON_version_error
  142. RESULT_VARIABLE BISON_version_result
  143. OUTPUT_STRIP_TRAILING_WHITESPACE)
  144. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" BISON_VERSION "${BISON_version_output}")
  145. ENDIF()
  146. IF ("${FLEX_VERSION}" STREQUAL "")
  147. IF (WIN32)
  148. # cmake bug workaround - it converts path separators fine in add_custom_command but not here
  149. STRING(REPLACE "/" "\\" FLEX_exename "${flexcmd}")
  150. IF (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  151. set (FLEX_exename "${FLEX_exename}.bat")
  152. ENDIF()
  153. ELSE()
  154. SET(FLEX_exename "${flexcmd}")
  155. ENDIF()
  156. EXECUTE_PROCESS(COMMAND ${FLEX_exename} --version
  157. OUTPUT_VARIABLE FLEX_version_output
  158. ERROR_VARIABLE FLEX_version_error
  159. RESULT_VARIABLE FLEX_version_result
  160. OUTPUT_STRIP_TRAILING_WHITESPACE)
  161. STRING(REGEX REPLACE "^[^0-9]*([0-9.]+).*" "\\1" FLEX_VERSION "${FLEX_version_output}")
  162. ENDIF()
  163. IF ("${BISON_VERSION}" VERSION_LESS "2.4.1")
  164. MESSAGE(FATAL_ERROR "You need bison version 2.4.1 or later to build this project (version ${BISON_VERSION} detected)")
  165. ENDIF()
  166. IF ("${FLEX_VERSION}" VERSION_LESS "2.5.35")
  167. MESSAGE(FATAL_ERROR "You need flex version 2.5.35 or later to build this project (version ${FLEX_VERSION} detected)")
  168. ENDIF()
  169. IF (CMAKE_COMPILER_IS_GNUCXX)
  170. EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GNUCXX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  171. IF ("${GNUCXX_VERSION}" VERSION_LESS "4.1.1")
  172. MESSAGE(FATAL_ERROR "You need Gnu c++ version 4.1.1 or later to build this project (version ${GNUCXX_VERSION} detected)")
  173. ENDIF()
  174. ENDIF()
  175. ###########################################################################
  176. # External library setup - some can be optionally selected based on USE_xxx flags, some are required
  177. IF (NOT WIN32)
  178. find_package(BINUTILS)
  179. IF (NOT BINUTILS_FOUND)
  180. message(FATAL_ERROR "BINUTILS package not found")
  181. ENDIF()
  182. ENDIF()
  183. IF (USE_OPENLDAP)
  184. find_package(OPENLDAP)
  185. IF (OPENLDAP_FOUND)
  186. add_definitions (-D_USE_OPENLDAP)
  187. ELSE()
  188. message(FATAL_ERROR "OPENLDAP requested but package not found")
  189. ENDIF()
  190. ENDIF(USE_OPENLDAP)
  191. IF (USE_CPPUNIT)
  192. find_package(CPPUNIT)
  193. IF (CPPUNIT_FOUND)
  194. add_definitions (-D_USE_CPPUNIT)
  195. include_directories(${CPPUNIT_INCLUDE_DIR})
  196. ELSE()
  197. message(FATAL_ERROR "CPPUNIT requested but package not found")
  198. ENDIF()
  199. ENDIF(USE_CPPUNIT)
  200. IF (USE_ICU)
  201. find_package(ICU)
  202. IF (ICU_FOUND)
  203. add_definitions (-D_USE_ICU)
  204. include_directories(${ICU_INCLUDE_DIR})
  205. ELSE()
  206. message(FATAL_ERROR "ICU requested but package not found")
  207. ENDIF()
  208. ENDIF(USE_ICU)
  209. if(USE_XALAN)
  210. find_package(XALAN)
  211. if (XALAN_FOUND)
  212. add_definitions (-D_USE_XALAN)
  213. else()
  214. message(FATAL_ERROR "XALAN requested but package not found")
  215. endif()
  216. endif(USE_XALAN)
  217. if(USE_XERCES)
  218. find_package(XERCES)
  219. if (XERCES_FOUND)
  220. add_definitions (-D_USE_XERCES)
  221. else()
  222. message(FATAL_ERROR "XERCES requested but package not found")
  223. endif()
  224. endif(USE_XERCES)
  225. if(USE_ZLIB)
  226. find_package(ZLIB)
  227. if (ZLIB_FOUND)
  228. add_definitions (-D_USE_ZLIB)
  229. else()
  230. message(FATAL_ERROR "ZLIB requested but package not found")
  231. endif()
  232. endif(USE_ZLIB)
  233. if(USE_BOOST_REGEX)
  234. find_package(BOOST_REGEX)
  235. if (BOOST_REGEX_FOUND)
  236. add_definitions (-D_USE_BOOST_REGEX)
  237. else()
  238. message(FATAL_ERROR "BOOST_REGEX requested but package not found")
  239. endif()
  240. endif(USE_BOOST_REGEX)
  241. if(USE_OPENSSL)
  242. find_package(OPENSSL)
  243. if (OPENSSL_FOUND)
  244. add_definitions (-D_USE_OPENSSL)
  245. include_directories(${OPENSSL_INCLUDE_DIR})
  246. link_directories(${OPENSSL_LIBRARY_DIR})
  247. else()
  248. message(FATAL_ERROR "OPENSSL requested but package not found")
  249. endif()
  250. endif(USE_OPENSSL)
  251. if(USE_MYSQL)
  252. find_package(MYSQL)
  253. if (MYSQL_FOUND)
  254. add_definitions (-D_USE_MYSQL)
  255. else()
  256. message(FATAL_ERROR "MYSQL requested but package not found")
  257. endif()
  258. else()
  259. add_definitions (-D_NO_MYSQL)
  260. endif(USE_MYSQL)
  261. if(USE_SVN)
  262. find_package(SVN)
  263. if (SVN_FOUND)
  264. add_definitions (-D_USE_SVN)
  265. else()
  266. message(FATAL_ERROR "SVN requested but package not found")
  267. endif()
  268. endif(USE_SVN)
  269. ###########################################################################
  270. endif ("${COMMONSETUP_DONE}" STREQUAL "")