supernets anope source code & configuration https://www.anope.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. # This usage of CMake requires at least version 2.4 (checks are made to determine what to use when certain versions lack functions)
  2. cmake_minimum_required(VERSION 2.4 FATAL_ERROR)
  3. if(COMMAND cmake_policy)
  4. cmake_policy(SET CMP0003 NEW)
  5. if(POLICY CMP0026)
  6. cmake_policy(SET CMP0026 OLD)
  7. endif(POLICY CMP0026)
  8. if(POLICY CMP0007)
  9. cmake_policy(SET CMP0007 OLD)
  10. endif(POLICY CMP0007)
  11. endif(COMMAND cmake_policy)
  12. # Set the project as C++ primarily, but have C enabled for the checks required later
  13. project(Anope CXX)
  14. enable_language(C)
  15. # Detect the version of CMake for the later conditional checks
  16. execute_process(COMMAND ${CMAKE_COMMAND} --version OUTPUT_VARIABLE VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  17. string(REGEX REPLACE "cmake version 2\\.(.*)" "\\1" ONLY_VERSION "${VERSION}")
  18. string(REGEX MATCH "-patch .*$" HAS_PATCH "${ONLY_VERSION}")
  19. if(HAS_PATCH)
  20. string(REGEX REPLACE "(.*)-patch .*" "\\1" MINOR_VERSION "${ONLY_VERSION}")
  21. string(REGEX REPLACE ".*-patch (.*)" "\\1" PATCH_VERSION "${ONLY_VERSION}")
  22. else(HAS_PATCH)
  23. string(REGEX MATCH "\\." HAS_DOT "${ONLY_VERSION}")
  24. if(HAS_DOT)
  25. string(REGEX REPLACE "(.*)\\..*" "\\1" MINOR_VERSION "${ONLY_VERSION}")
  26. string(REGEX REPLACE ".*\\.(.*)" "\\1" PATCH_VERSION "${ONLY_VERSION}")
  27. else(HAS_DOT)
  28. string(REGEX REPLACE "(.*)-beta" "\\1" MINOR_VERSION "${ONLY_VERSION}")
  29. if(MINOR_VERSION STREQUAL "4-1\n")
  30. set(PATCH_VERSION 1)
  31. else(MINOR_VERSION STREQUAL "4-1\n")
  32. set(PATCH_VERSION 0)
  33. endif(MINOR_VERSION STREQUAL "4-1\n")
  34. set(MINOR_VERSION 4)
  35. endif(HAS_DOT)
  36. endif(HAS_PATCH)
  37. # Detect is we are using CMake 2.6 or better, these versions include functions that require less work than CMake 2.4 does
  38. if(MINOR_VERSION GREATER 5)
  39. set(CMAKE26_OR_BETTER TRUE)
  40. set(CMAKE248_OR_BETTER TRUE)
  41. set(CMAKE244_OR_BETTER TRUE)
  42. set(CMAKE242_OR_BETTER TRUE)
  43. else(MINOR_VERSION GREATER 5)
  44. set(CMAKE26_OR_BETTER FALSE)
  45. # Also detect if we are using CMake 2.4.8 or better, the FIND sub-command of list() is nonexistent in earlier versions
  46. if(PATCH_VERSION GREATER 7)
  47. set(CMAKE248_OR_BETTER TRUE)
  48. set(CMAKE244_OR_BETTER TRUE)
  49. set(CMAKE242_OR_BETTER TRUE)
  50. else(PATCH_VERSION GREATER 7)
  51. set(CMAKE248_OR_BETTER FALSE)
  52. # Also detect if we are using CMake 2.4.4 or better, the CheckCXXCompilerFlag module and SORT sub-command of list() are nonexistent in earlier versions
  53. if(PATCH_VERSION GREATER 3)
  54. set(CMAKE244_OR_BETTER TRUE)
  55. set(CMAKE242_OR_BETTER TRUE)
  56. else(PATCH_VERSION GREATER 3)
  57. set(CMAKE244_OR_BETTER FALSE)
  58. # ALSO detect if we are using CMake 2.4.2 or better, the APPEND sub-command of list() is nonexistent in earlier versions
  59. if(PATCH_VERSION GREATER 1)
  60. set(CMAKE242_OR_BETTER TRUE)
  61. else(PATCH_VERSION GREATER 1)
  62. set(CMAKE242_OR_BETTER FALSE)
  63. endif(PATCH_VERSION GREATER 1)
  64. endif(PATCH_VERSION GREATER 3)
  65. endif(PATCH_VERSION GREATER 7)
  66. endif(MINOR_VERSION GREATER 5)
  67. # Override the module include path to include our directory, for our Anope.cmake, as well as we are using our own version of the NSIS template
  68. set(CMAKE_MODULE_PATH ${Anope_SOURCE_DIR}/cmake)
  69. include(Anope)
  70. # Force the locale to C for later uses of things like gcc so the messages come up in English, not the user's default language
  71. set(ENV{LC_ALL} C)
  72. # Start with empty defaults for library and include directories, to be used by GNU compilers only
  73. set(DEFAULT_LIBRARY_DIRS)
  74. set(DEFAULT_INCLUDE_DIRS)
  75. # Check that we aren't running on an ancient broken GCC
  76. if(CMAKE_COMPILER_IS_GNUCXX)
  77. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_FULL_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  78. string(REGEX REPLACE "^(\\d+\\.\\d+)" "\\1" GCC_VERSION ${GCC_FULL_VERSION})
  79. if(GCC_VERSION LESS 4.2)
  80. message(FATAL_ERROR "Your compiler is too old to build Anope. Upgrade to GCC 4.2 or newer!")
  81. endif(GCC_VERSION LESS 4.2)
  82. if(GCC_VERSION GREATER 6.0 OR GCC_VERSION EQUAL 6.0)
  83. set(CXXFLAGS "${CXXFLAGS} -fno-delete-null-pointer-checks")
  84. endif(GCC_VERSION GREATER 6.0 OR GCC_VERSION EQUAL 6.0)
  85. endif(CMAKE_COMPILER_IS_GNUCXX)
  86. # If we are using a GNU compiler (have to use CXX because it seems to fail on C), we will be able to determine it's default paths for libraries and includes
  87. if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang$")
  88. # First look for the compiler's default library directories
  89. execute_process(COMMAND ${CMAKE_C_COMPILER} -print-search-dirs OUTPUT_VARIABLE LINES OUTPUT_STRIP_TRAILING_WHITESPACE)
  90. # Find only the part after "libraries: "
  91. string(REGEX REPLACE ".*\nlibraries: (.*)$" "\\1" LINE "${LINES}")
  92. # Replace the colons in the list with semicolons (only when not on MinGW, which uses semicolons already), and if on MinGW, just copy the line
  93. if(NOT MINGW)
  94. string(REGEX REPLACE ":" ";" LIBRARIES ${LINE})
  95. else(NOT MINGW)
  96. set(LIBRARIES "${LINE}")
  97. endif(NOT MINGW)
  98. # Iterate through the libraries
  99. foreach(LIBRARY ${LIBRARIES})
  100. # Check if the first character is an equal sign, and skip that library directory as it is (I believe) the primary default and shows up later in the list anyways
  101. string(SUBSTRING ${LIBRARY} 0 1 FIRST_CHAR)
  102. if(NOT FIRST_CHAR STREQUAL "=")
  103. # If the directory had no = in front of it, make sure it's absolute and add it to the list of default library directories
  104. get_filename_component(LIBRARY ${LIBRARY} ABSOLUTE)
  105. append_to_list(DEFAULT_LIBRARY_DIRS ${LIBRARY})
  106. endif(NOT FIRST_CHAR STREQUAL "=")
  107. endforeach(LIBRARY)
  108. # Remove duplicate entries from the list
  109. if(DEFAULT_LIBRARY_DIRS)
  110. remove_list_duplicates(DEFAULT_LIBRARY_DIRS)
  111. endif(DEFAULT_LIBRARY_DIRS)
  112. # Create a temporary file to test for the default include directories
  113. FILE(WRITE empty.cpp "")
  114. # Next, we look for the compiler's default include directories
  115. # Run the command to find the default include directories
  116. execute_process(COMMAND ${CMAKE_C_COMPILER} -v -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp ERROR_VARIABLE LINES OUTPUT_QUIET ERROR_STRIP_TRAILING_WHITESPACE)
  117. # Remove the empty file, it is no longer needed
  118. FILE(REMOVE empty.cpp)
  119. # Convert the new lines to semicolons
  120. string(REGEX REPLACE "\n" ";" LINES ${LINES})
  121. # Temporary variable saying if we are in the search list or not
  122. set(IN_SEARCH_LIST FALSE)
  123. # Iterate through the lines
  124. foreach(LINE ${LINES})
  125. # If the line has the following on it, the next lines will contain directory names
  126. if(LINE STREQUAL "#include <...> search starts here:")
  127. set(IN_SEARCH TRUE)
  128. else(LINE STREQUAL "#include <...> search starts here:")
  129. # If the line has the following on it, we hit the end of the list
  130. if(LINE STREQUAL "End of search list.")
  131. set(IN_SEARCH FALSE)
  132. else(LINE STREQUAL "End of search list.")
  133. # If we are within the block between the above two lines...
  134. if(IN_SEARCH)
  135. # Get everything but the first character of the line
  136. string(LENGTH ${LINE} LINE_LENGTH)
  137. math(EXPR LINE_LENGTH "${LINE_LENGTH} - 1")
  138. string(SUBSTRING ${LINE} 1 ${LINE_LENGTH} INCLUDE)
  139. # For systems like Mac OS X, look for include paths that say " (framework directory)" at the end of them and strip that off
  140. string(REGEX REPLACE " \\(framework directory\\)$" "" INCLUDE ${INCLUDE})
  141. # Convert the path to an absolute one, just in case it wasn't
  142. get_filename_component(INCLUDE ${INCLUDE} ABSOLUTE)
  143. # Add that directory to the list of default include directories
  144. append_to_list(DEFAULT_INCLUDE_DIRS ${INCLUDE})
  145. endif(IN_SEARCH)
  146. endif(LINE STREQUAL "End of search list.")
  147. endif(LINE STREQUAL "#include <...> search starts here:")
  148. endforeach(LINE)
  149. # Remove duplicate entries from the list
  150. if(DEFAULT_INCLUDE_DIRS)
  151. remove_list_duplicates(DEFAULT_INCLUDE_DIRS)
  152. endif(DEFAULT_INCLUDE_DIRS)
  153. endif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang$")
  154. # If we are using Visual Studio, locate the path of the Windows Server 2008 SDK or Windows Server 2003 Platform SDK, depending on which is installed
  155. if(MSVC)
  156. # If the path comes up as "/registry" from any of these, the path wasn't found, otherwise, we'll set WSDK_PATH to the corresponding path
  157. # Look for the 2008 SDK under HKLM first
  158. get_filename_component(WSDK2008_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" ABSOLUTE CACHE)
  159. if(WSDK2008_PATH STREQUAL "/registry")
  160. # If not found, look for the 2003 SDK under HKLM
  161. get_filename_component(WSDK2003_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1;Install Dir]" ABSOLUTE CACHE)
  162. if(WSDK2003_PATH STREQUAL "/registry")
  163. # If not found, look for the 2008 SDK under HKCU
  164. get_filename_component(WSDK2008_PATH "[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" ABSOLUTE CACHE)
  165. if(WSDK2008_PATH STREQUAL "/registry")
  166. # If not found, look for the 2003 SDK under HKCU
  167. get_filename_component(WSDK2003_PATH "[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1;Install Dir]" ABSOLUTE CACHE)
  168. if(WSDK2003_PATH STREQUAL "/registry")
  169. # The SDK was never found, set the path to nothing
  170. set(WSDK_PATH "")
  171. else(WSDK2003_PATH STREQUAL "/registry")
  172. set(WSDK_PATH "${WSDK2003_PATH}")
  173. endif(WSDK2003_PATH STREQUAL "/registry")
  174. else(WSDK2008_PATH STREQUAL "/registry")
  175. set(WSDK_PATH "${WSDK2008_PATH}")
  176. endif(WSDK2008_PATH STREQUAL "/registry")
  177. else(WSDK2003_PATH STREQUAL "/registry")
  178. set(WSDK_PATH "${WSDK2003_PATH}")
  179. endif(WSDK2003_PATH STREQUAL "/registry")
  180. else(WSDK2008_PATH STREQUAL "/registry")
  181. set(WSDK_PATH "${WSDK2008_PATH}")
  182. endif(WSDK2008_PATH STREQUAL "/registry")
  183. endif(MSVC)
  184. # If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition
  185. # and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE
  186. # to Debug
  187. # Only do this if not using Visual Studio
  188. if(NOT MSVC)
  189. if(CMAKE_BUILD_TYPE)
  190. set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
  191. else(CMAKE_BUILD_TYPE)
  192. set(CMAKE_BUILD_TYPE DEBUG CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
  193. endif(CMAKE_BUILD_TYPE)
  194. endif(NOT MSVC)
  195. # If running under MinGW, we have to force the resource compiler settings (hopefully this will be fixed in a later version of CMake)
  196. if(MINGW)
  197. set(CMAKE_RC_COMPILER_INIT windres)
  198. enable_language(RC)
  199. set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> <SOURCE>")
  200. endif(MINGW)
  201. # Include the checking functions used later in this CMakeLists.txt
  202. include(CheckFunctionExists)
  203. include(CheckIncludeFile)
  204. include(CheckTypeSize)
  205. include(CheckLibraryExists)
  206. if(CMAKE244_OR_BETTER)
  207. include(CheckCXXCompilerFlag)
  208. else(CMAKE244_OR_BETTER)
  209. include(TestCXXAcceptsFlag)
  210. endif(CMAKE244_OR_BETTER)
  211. # If extra include directories were specified, tell cmake about them.
  212. if(EXTRA_INCLUDE)
  213. include_directories(${EXTRA_INCLUDE})
  214. endif(EXTRA_INCLUDE)
  215. # If extra library directories were specified, tell cmake about them.
  216. if(EXTRA_LIBS)
  217. link_directories(${EXTRA_LIBS})
  218. endif(EXTRA_LIBS)
  219. # Find gettext
  220. find_package(Gettext)
  221. option(USE_PCH "Use precompiled headers" OFF)
  222. # Use the following directories as includes
  223. # Note that it is important the binary include directory comes before the
  224. # source include directory so the precompiled headers work correctly.
  225. include_directories(${Anope_BINARY_DIR}/include ${Anope_SOURCE_DIR}/include ${Anope_BINARY_DIR}/language ${Anope_SOURCE_DIR}/modules/pseudoclients)
  226. # Pass on REPRODUCIBLE_BUILD
  227. if(REPRODUCIBLE_BUILD)
  228. add_definitions(-DREPRODUCIBLE_BUILD)
  229. endif(REPRODUCIBLE_BUILD)
  230. # If using Windows, always add the _WIN32 define
  231. if(WIN32)
  232. add_definitions(-D_WIN32)
  233. # And include the windows specific folder for our anope_windows.h
  234. include_directories(${Anope_SOURCE_DIR}/src/win32)
  235. endif(WIN32)
  236. # If using Visual Studio, set the C++ flags accordingly
  237. if(MSVC)
  238. # Remove the default exception handling flags, also remove default warning level flag
  239. string(REPLACE "/EHsc " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  240. string(REPLACE "/GX " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  241. string(REPLACE "/W3 " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  242. # Set the compile flags to have warnings on the max setting (but disable a few annoying ones), exception handling turned on, the proper defines
  243. set(CXXFLAGS "${CXXFLAGS} /W4 /wd4100 /wd4127 /wd4250 /wd4251 /wd4355 /wd4706 /wd4800 /wd4996 /EHs")
  244. add_definitions(-DMSVCPP -D_CRT_SECURE_NO_WARNINGS)
  245. # Otherwise, we're not using Visual Studio
  246. else(MSVC)
  247. # Set the compile flags to have all warnings on (including shadowed variables)
  248. set(CXXFLAGS "${CXXFLAGS} -Wall -Wshadow")
  249. # If on a *nix system, also set the compile flags to remove GNU extensions (favor ISO C++) as well as reject non-ISO C++ code, also remove all leading underscores in exported symbols (only on GNU compiler)
  250. if(UNIX)
  251. set(CXXFLAGS "${CXXFLAGS} -ansi -pedantic ${CMAKE_CXX_FLAGS}")
  252. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  253. set(CXXFLAGS "${CXXFLAGS} -Wno-long-long -fno-leading-underscore")
  254. endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  255. # If we aren't on a *nix system, we are using MinGW
  256. else(UNIX)
  257. # Also, if we are building under MinGW, add another define for MinGW
  258. if(MINGW)
  259. add_definitions(-DMINGW)
  260. endif(MINGW)
  261. endif(UNIX)
  262. endif(MSVC)
  263. # If CMake has found that the given system requires a special library for dl* calls, include it with the linker flags
  264. if(CMAKE_DL_LIBS)
  265. append_to_list(LINK_LIBS ${CMAKE_DL_LIBS})
  266. endif(CMAKE_DL_LIBS)
  267. # Under MinGW, the -shared flag isn't properly set in the module-specific linker flags, add it from the C flags for shared libraries
  268. if(MINGW)
  269. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
  270. endif(MINGW)
  271. if(NOT PROGRAM_NAME)
  272. # Under Windows, we set the executable name for Anope to be anope
  273. if(WIN32)
  274. set(PROGRAM_NAME anope)
  275. # Under *nix, we set the executable name for Anope to be services
  276. else(WIN32)
  277. set(PROGRAM_NAME services)
  278. endif(WIN32)
  279. endif(NOT PROGRAM_NAME)
  280. # If we are not using Visual Studio, we'll run the following checks
  281. if(NOT MSVC)
  282. # Check if the C++ compiler can accept the -pipe flag, and add it to the compile flags if it works
  283. if(CMAKE244_OR_BETTER)
  284. # If using CMake 2.4.4 or better, we can use check_cxx_compiler_flag
  285. check_cxx_compiler_flag(-pipe HAVE_PIPE_FLAG)
  286. else(CMAKE244_OR_BETTER)
  287. # If using CMake 2.4.3 or older, we will use check_cxx_accepts_flags instead
  288. check_cxx_accepts_flag(-pipe HAVE_PIPE_FLAG)
  289. endif(CMAKE244_OR_BETTER)
  290. # If the flag was accepted, add it to the list of flags
  291. if(HAVE_PIPE_FLAG)
  292. set(CXXFLAGS "${CXXFLAGS} -pipe")
  293. endif(HAVE_PIPE_FLAG)
  294. # The following are additional library checks, they are not required for Windows
  295. if(NOT WIN32)
  296. # Check if socket is within the socket library (if the library exists), and add it to the linker flags if needed
  297. check_library_exists(socket socket "" HAVE_SOCKET_LIB)
  298. if(HAVE_SOCKET_LIB)
  299. append_to_list(LINK_LIBS socket)
  300. endif(HAVE_SOCKET_LIB)
  301. # Check if inet_addr is within the nsl library (if the library exists), and add it to the linker flags if needed
  302. check_library_exists(nsl inet_addr "" HAVE_NSL_LIB)
  303. if(HAVE_NSL_LIB)
  304. append_to_list(LINK_LIBS nsl)
  305. endif(HAVE_NSL_LIB)
  306. # Check if pthread_create is within the pthread library (if the library exists), and add it to the linker flags if needed
  307. check_library_exists(pthread pthread_create "" HAVE_PTHREAD)
  308. if(HAVE_PTHREAD)
  309. if(NOT APPLE)
  310. set(LDFLAGS "${LDFLAGS} -pthread")
  311. endif(NOT APPLE)
  312. else(HAVE_PTHREAD)
  313. message(FATAL_ERROR "The pthread library is required to build Anope")
  314. endif(HAVE_PTHREAD)
  315. endif(NOT WIN32)
  316. endif(NOT MSVC)
  317. # If DEFUMASK wasn't passed to CMake, set a default depending on if RUNGROUP was passed in or not
  318. if(NOT DEFUMASK)
  319. if(RUNGROUP)
  320. set(DEFUMASK "007")
  321. else(RUNGROUP)
  322. set(DEFUMASK "077")
  323. endif(RUNGROUP)
  324. endif(NOT DEFUMASK)
  325. # Set the DEBUG_BUILD for sysconf.h
  326. if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
  327. set(DEBUG_BUILD TRUE)
  328. endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
  329. # Check for the existence of the following include files
  330. check_include_file(cstdint HAVE_CSTDINT)
  331. check_include_file(stdint.h HAVE_STDINT_H)
  332. check_include_file(strings.h HAVE_STRINGS_H)
  333. # Check for the existence of the following functions
  334. check_function_exists(strcasecmp HAVE_STRCASECMP)
  335. check_function_exists(stricmp HAVE_STRICMP)
  336. check_function_exists(umask HAVE_UMASK)
  337. check_function_exists(epoll_wait HAVE_EPOLL)
  338. check_function_exists(poll HAVE_POLL)
  339. check_function_exists(kqueue HAVE_KQUEUE)
  340. # Strip the leading and trailing spaces from the compile flags
  341. if(CXXFLAGS)
  342. strip_string(${CXXFLAGS} CXXFLAGS)
  343. endif(CXXFLAGS)
  344. # Strip the leading and trailing spaces from the linker flags
  345. if(LDFLAGS)
  346. strip_string(${LDFLAGS} LDFLAGS)
  347. endif(LDFLAGS)
  348. # Search for the following programs
  349. find_program(GREP grep)
  350. find_program(SH sh)
  351. find_program(CHGRP chgrp)
  352. find_program(CHMOD chmod)
  353. # If a INSTDIR was passed in to CMake, use it as the install prefix, otherwise set the default install prefix to the services directory under the user's home directory
  354. if(INSTDIR)
  355. set(CMAKE_INSTALL_PREFIX "${INSTDIR}")
  356. elseif(NOT CMAKE_INSTALL_PREFIX)
  357. set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/services")
  358. endif(INSTDIR)
  359. # Set default paths for various directories if not already defined
  360. if(NOT BIN_DIR)
  361. set(BIN_DIR "bin")
  362. endif(NOT BIN_DIR)
  363. if(NOT DB_DIR)
  364. set(DB_DIR "data")
  365. endif(NOT DB_DIR)
  366. if(NOT DOC_DIR)
  367. set(DOC_DIR "doc")
  368. endif(NOT DOC_DIR)
  369. if(NOT CONF_DIR)
  370. set(CONF_DIR "conf")
  371. endif(NOT CONF_DIR)
  372. if(NOT LIB_DIR)
  373. set(LIB_DIR "lib")
  374. endif(NOT LIB_DIR)
  375. if(NOT LOCALE_DIR)
  376. set(LOCALE_DIR "locale")
  377. endif(NOT LOCALE_DIR)
  378. if(NOT LOGS_DIR)
  379. set(LOGS_DIR "logs")
  380. endif(NOT LOGS_DIR)
  381. # Version number processing
  382. # Find all lines in src/version.sh that start with VERSION_
  383. read_from_file(${Anope_SOURCE_DIR}/src/version.sh "^VERSION_" VERSIONS)
  384. # Iterate through the strings found
  385. foreach(VERSION_STR ${VERSIONS})
  386. string(REGEX REPLACE "^VERSION_([A-Z]+)=\"?([^\"]*)\"?$" "\\1;\\2" VERSION_OUT ${VERSION_STR})
  387. # Depends on CMP0007 OLD
  388. list(LENGTH VERSION_OUT VERSION_LEN)
  389. list(GET VERSION_OUT 0 VERSION_TYPE)
  390. if(${VERSION_LEN} GREATER 1)
  391. list(GET VERSION_OUT 1 VERSION_DATA)
  392. set(VERSION_${VERSION_TYPE} ${VERSION_DATA})
  393. endif(${VERSION_LEN} GREATER 1)
  394. endforeach(VERSION_STR ${VERSIONS})
  395. # Default build version to 0
  396. set(VERSION_BUILD 0)
  397. # Only change the build number if version.h exists
  398. if(EXISTS "${Anope_SOURCE_DIR}/include/version.h")
  399. # Attempt to read the build number from include/version.h
  400. read_from_file(${Anope_SOURCE_DIR}/include/version.h "^#define VERSION_BUILD" VERSIONS)
  401. foreach(VERSION_STR ${VERSIONS})
  402. # Get the length of the string
  403. string(LENGTH ${VERSION_STR} VERSION_LEN)
  404. # Subtract 22 from the string's length
  405. math(EXPR VERSION_NUM_LEN "${VERSION_LEN} - 22")
  406. # Extract the value from the string
  407. string(SUBSTRING ${VERSION_STR} 22 ${VERSION_NUM_LEN} VERSION)
  408. # Set VERSION_BUILD correctly
  409. set(VERSION_BUILD ${VERSION})
  410. endforeach(VERSION_STR ${VERSIONS})
  411. endif(EXISTS "${Anope_SOURCE_DIR}/include/version.h")
  412. # Set the version variables based on what was found above
  413. set(VERSION_COMMA "${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_BUILD}")
  414. set(VERSION_DOTTED_NOBUILD "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
  415. set(VERSION_DOTTED "${VERSION_DOTTED_NOBUILD}.${VERSION_BUILD}")
  416. set(VERSION_FULL "${VERSION_DOTTED}${VERSION_EXTRA}")
  417. set(VERSION_FULL_NOBUILD "${VERSION_DOTTED_NOBUILD}${VERSION_EXTRA}")
  418. # Only do the following for Windows
  419. if(WIN32)
  420. # Generate the win32.rc file using the above variables
  421. configure_file(${Anope_SOURCE_DIR}/src/win32/win32.rc.cmake ${Anope_BINARY_DIR}/src/win32/win32.rc)
  422. endif(WIN32)
  423. # Add the initial files to ignore which will be ignored regardless of if you are building in-source or out-of-source
  424. add_to_cpack_ignored_files(".git\;config.cache\;CMakeFiles\;sysconf.h$\;build" TRUE)
  425. # Add the files we don't want the periods converted for
  426. add_to_cpack_ignored_files(".\\\\\\\\.so$;.\\\\\\\\.o$;.\\\\\\\\.s$;${Anope_SOURCE_DIR}/Makefile$")
  427. # If the two directories are the same, we are building in-source, thus we need to ignore more files from the build
  428. if(${Anope_SOURCE_DIR} STREQUAL ${Anope_BINARY_DIR})
  429. # Add the files that need their periods converted
  430. add_to_cpack_ignored_files("Makefile\;cmake_install.cmake\;sysconf.h$\;CMakeCache.txt\;install_manifest.txt" TRUE)
  431. # Add the files we don't want the periods converted for
  432. add_to_cpack_ignored_files(".\\\\\\\\.so$;CPack.;anope-${VERSION_FULL_NOBUILD}-source\\\\\\\\..")
  433. # If using Visual Studio, add these files as well
  434. if(MSVC)
  435. add_to_cpack_ignored_files(".vcproj$\;.sln$\;.ncb$\;.suo$\;.dir$\;.ilk$\;.exp$\;.pdb$\;.lib$\;/debug$;/release$;/relwithdebinfo$;/minsizerel$" TRUE)
  436. endif(MSVC)
  437. endif(${Anope_SOURCE_DIR} STREQUAL ${Anope_BINARY_DIR})
  438. # Go into the following directories and run their CMakeLists.txt as well
  439. add_subdirectory(data)
  440. add_subdirectory(docs)
  441. add_subdirectory(language)
  442. add_subdirectory(src)
  443. add_subdirectory(modules)
  444. add_subdirectory(include)
  445. # Get the filename of the Anope binary, to use later
  446. get_target_property(SERVICES_BINARY ${PROGRAM_NAME} LOCATION)
  447. get_filename_component(SERVICES_BINARY ${SERVICES_BINARY} NAME)
  448. # At install time, create the following additional directories
  449. install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${DB_DIR}/backups\")")
  450. install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${LOGS_DIR}\")")
  451. if(WIN32)
  452. install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${DB_DIR}/runtime\")")
  453. endif(WIN32)
  454. # On non-Windows platforms, if RUNGROUP is set, change the permissions of the below directories, as well as the group of the data directory
  455. if(NOT WIN32 AND RUNGROUP)
  456. install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${DB_DIR}/backups\")")
  457. install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${LOGS_DIR}\")")
  458. install(CODE "execute_process(COMMAND ${CHGRP} -R ${RUNGROUP} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}\")")
  459. endif(NOT WIN32 AND RUNGROUP)
  460. # On Windows platforms, install extra files
  461. if(WIN32)
  462. install(FILES ${Anope_SOURCE_DIR}/src/win32/anope.bat
  463. DESTINATION ${BIN_DIR}
  464. )
  465. # Package any DLLs in src/win/
  466. file(GLOB EXTRA_DLLS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${Anope_SOURCE_DIR}/src/win32/*.dll")
  467. install(FILES ${EXTRA_DLLS} DESTINATION ${BIN_DIR})
  468. endif(WIN32)
  469. install(CODE "file(REMOVE_RECURSE \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/modules\")")
  470. # Only process the CPack section if we have CPack
  471. if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
  472. # Various options for CPack
  473. set(CPACK_PACKAGE_NAME "Anope IRC Services")
  474. set(CPACK_PACKAGE_VENDOR "Anope Team")
  475. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  476. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  477. set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}${VERSION_EXTRA}")
  478. set(CPACK_PACKAGE_FILE_NAME "anope-${VERSION_FULL_NOBUILD}")
  479. set(CPACK_RESOURCE_FILE_LICENSE "${Anope_SOURCE_DIR}/docs/COPYING")
  480. # The following doesn't actually do anything. :(
  481. #set(CPACK_RESOURCE_FILE_README "${Anope_SOURCE_DIR}/docs/README")
  482. # The following is primarily for NSIS
  483. if(WIN32)
  484. # By default, do not warn when built on machines using only VS Express:
  485. IF(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
  486. SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
  487. ENDIF(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
  488. # Also for Windows, include installing the MSVCRT library
  489. include(InstallRequiredSystemLibraries)
  490. set(CPACK_GENERATOR "NSIS")
  491. set(CPACK_PACKAGE_INSTALL_DIRECTORY "Anope")
  492. set(CPACK_PACKAGE_EXECUTABLES "")
  493. set(CPACK_NSIS_MENU_LINKS
  494. "bin\\\\${SERVICES_BINARY}" "Anope IRC Services"
  495. "bin\\\\anope.bat\\\" \\\"-debug -nofork" "Anope IRC Services (Debug and Window Logging)"
  496. "bin\\\\anope.bat\\\" \\\"-nofork" "Anope IRC Services (Window Logging)"
  497. "bin\\\\anope.bat\\\" \\\"-nothird" "Anope IRC Services (No Third Party Modules)"
  498. "http://www.anope.org/" "Anope Web Site"
  499. )
  500. # The following doesn't work, but a bug report has been filed about it
  501. #set(CPACK_CREATE_DESKTOP_LINK_${SERVICES_BINARY} TRUE)
  502. set(CPACK_NSIS_MUI_ICON "${Anope_SOURCE_DIR}/src\\\\win32\\\\anope-icon.ico")
  503. set(CPACK_NSIS_MUI_UNIICON "${Anope_SOURCE_DIR}/src\\\\win32\\\\anope-icon.ico")
  504. set(CPACK_NSIS_INSTALLED_ICON_NAME "${SERVICES_BINARY}")
  505. set(CPACK_NSIS_URL_INFO_ABOUT "http://www.anope.org/")
  506. set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  507. endif(WIN32)
  508. set(CPACK_SOURCE_PACKAGE_FILE_NAME "anope-${VERSION_FULL_NOBUILD}-source")
  509. set(CPACK_SOURCE_GENERATOR "TGZ")
  510. set(CPACK_SOURCE_IGNORE_FILES "$ENV{CPACK_IGNORED_FILES}")
  511. set(CPACK_MONOLITHIC_INSTALL TRUE)
  512. include(CPack)
  513. endif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")