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