anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

CMakeLists.txt (5409B)

      1 # Find all the *.cpp files within the current source directory, and sort the list
      2 file(GLOB SRC_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
      3 
      4 if(WIN32)
      5   append_to_list(SRC_SRCS win32/dir/dir.cpp)
      6   append_to_list(SRC_SRCS win32/socket.cpp)
      7   append_to_list(SRC_SRCS win32/windows.cpp)
      8   append_to_list(SRC_SRCS win32/dl/dl.cpp)
      9   append_to_list(SRC_SRCS win32/pipe/pipe.cpp)
     10   append_to_list(SRC_SRCS win32/pthread/pthread.cpp)
     11   append_to_list(SRC_SRCS win32/sigaction/sigaction.cpp)
     12 endif(WIN32)
     13 
     14 if(HAVE_EPOLL)
     15   append_to_list(SRC_SRCS socketengines/socketengine_epoll.cpp)
     16 else(HAVE_EPOLL)
     17   if(HAVE_KQUEUE)
     18     append_to_list(SRC_SRCS socketengines/socketengine_kqueue.cpp)
     19   else(HAVE_KQUEUE)
     20     if(HAVE_POLL)
     21       append_to_list(SRC_SRCS socketengines/socketengine_poll.cpp)
     22     else(HAVE_POLL)
     23       append_to_list(SRC_SRCS socketengines/socketengine_select.cpp)
     24     endif(HAVE_POLL)
     25   endif(HAVE_KQUEUE)
     26 endif(HAVE_EPOLL)
     27 
     28 sort_list(SRC_SRCS)
     29 
     30 # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though)
     31 set_source_files_properties(${SRC_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
     32 
     33 # Create an empty list to store extra include directories
     34 set(EXTRA_INCLUDES)
     35 # Iterate through all the source files
     36 foreach(SRC ${SRC_SRCS})
     37   # Temporary variable for the current source's include directories
     38   set(TEMP_INCLUDES)
     39   # Calculate the header file dependencies for the given source file
     40   calculate_depends(${SRC} TEMP_INCLUDES)
     41   # If there were some extra include directories, add them to the list
     42   if(TEMP_INCLUDES)
     43     append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES})
     44   endif(TEMP_INCLUDES)
     45 endforeach(SRC)
     46 # If there were extra include directories, remove the duplicates and add the directories to the include path
     47 if(EXTRA_INCLUDES)
     48   remove_list_duplicates(EXTRA_INCLUDES)
     49   include_directories(${EXTRA_INCLUDES})
     50 endif(EXTRA_INCLUDES)
     51 
     52 # Under Windows, we also include a resource file to the build
     53 if(WIN32)
     54   # Make sure that the resource file is seen as an RC file to be compiled with a resource compiler, not a C++ compiler
     55   set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc LANGUAGE RC)
     56   # Add the resource file to the list of sources
     57   append_to_list(SRC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc)
     58   # For MinGW, we have to change the compile flags
     59   if(MINGW)
     60     set(RC_CFLAGS "-DMINGW -Ocoff -I${Anope_SOURCE_DIR}/include")
     61     # If any sort of debugging is being enabled, add a _DEBUG define to the flags for the resource compiler
     62     if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
     63       set(RC_CFLAGS "${RC_CFLAGS} -D_DEBUG")
     64     endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
     65     set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc COMPILE_FLAGS "${RC_CFLAGS}")
     66   # For anything else, assumingly Visual Studio at this point, use a different set of compile flags
     67   else(MINGW)
     68     set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc COMPILE_FLAGS "/i\"${Anope_SOURCE_DIR}/include\"")
     69   endif(MINGW)
     70 endif(WIN32)
     71 
     72 # If compiling with Visual Studio, create a static library out of win32/win32_memory.cpp to be included with everything else, needed to override its override of new/delete operators
     73 if(MSVC)
     74   set_source_files_properties(win32/win32_memory.cpp PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
     75   add_library(win32_memory STATIC win32/win32_memory.cpp)
     76   set(WIN32_MEMORY win32_memory)
     77   set(EXTRA_LDFLAGS "/OPT:NOREF") # https://sourceware.org/bugzilla/show_bug.cgi?id=12633
     78 else(MSVC)
     79   set(WIN32_MEMORY)
     80 endif(MSVC)
     81 
     82 # Generate the Anope executable and set it's linker flags, also set it to export it's symbols even though it's not a module
     83 add_executable(${PROGRAM_NAME} ${SRC_SRCS})
     84 set_target_properties(${PROGRAM_NAME} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS} ${EXTRA_LDFLAGS}" ENABLE_EXPORTS ON INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON)
     85 # On Windows, also link Anope to the wsock32 and Ws2_32 library, as well as set the version
     86 if(WIN32)
     87   target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${LINK_LIBS} ${GETTEXT_LIBRARIES} ${WIN32_MEMORY})
     88   set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
     89 else(WIN32)
     90   target_link_libraries(${PROGRAM_NAME} ${LINK_LIBS} ${GETTEXT_LIBRARIES})
     91 endif(WIN32)
     92 # Building the Anope executable requires the version.h header to be generated
     93 add_dependencies(${PROGRAM_NAME} headers)
     94 # Also require the language files if we have gettext
     95 if(GETTEXT_FOUND)
     96   add_dependencies(${PROGRAM_NAME} language)
     97 endif(GETTEXT_FOUND)
     98 
     99 # Get the filename of the Anope executable as it is in on this system
    100 get_target_property(SERVICES_BINARY ${PROGRAM_NAME} LOCATION)
    101 get_filename_component(SERVICES_BINARY ${SERVICES_BINARY} NAME)
    102 # Add the Anope executable to the list of files for CPack to ignore
    103 add_to_cpack_ignored_files("${SERVICES_BINARY}$" TRUE)
    104 
    105 # Generate sysconf.h from the earlier configuration
    106 configure_file(${Anope_SOURCE_DIR}/include/sysconf.h.cmake ${Anope_BINARY_DIR}/include/sysconf.h)
    107 
    108 # Go into the following directories and run their CMakeLists.txt as well
    109 if(NOT DISABLE_TOOLS)
    110   add_subdirectory(tools)
    111 endif(NOT DISABLE_TOOLS)
    112 
    113 # Set Anope to be installed to the bin directory
    114 install(TARGETS ${PROGRAM_NAME}
    115   DESTINATION ${BIN_DIR}
    116 )