diff options
-rw-r--r-- | cmake/Anope.cmake | 88 | ||||
-rw-r--r-- | modules/CMakeLists.txt | 342 | ||||
-rw-r--r-- | modules/commands/os_dns.cpp | 2 | ||||
-rw-r--r-- | modules/dns.h (renamed from modules/extra/dns.h) | 0 | ||||
-rw-r--r-- | modules/extra/CMakeLists.txt | 3 | ||||
-rw-r--r-- | modules/extra/webcpanel/CMakeLists.txt | 1 | ||||
-rw-r--r-- | modules/m_dns.cpp (renamed from modules/extra/m_dns.cpp) | 0 | ||||
-rw-r--r-- | modules/m_dnsbl.cpp | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/tools/CMakeLists.txt | 5 |
10 files changed, 187 insertions, 261 deletions
diff --git a/cmake/Anope.cmake b/cmake/Anope.cmake index 90dff5b72..b4eadf279 100644 --- a/cmake/Anope.cmake +++ b/cmake/Anope.cmake @@ -359,24 +359,22 @@ macro(find_includes SRC INCLUDES) endmacro(find_includes) ############################################################################### -# calculate_depends(<source filename> <output variable set to TRUE on fail> <TRUE if the source file is a module> [<optional output variable for includes>]) +# calculate_depends(<source filename> [<optional output variable for includes>]) # # This macro is used in most of the src (sub)directories to calculate the # header file dependencies for the given source file. ############################################################################### -macro(calculate_depends SRC SKIP MODULE) +macro(calculate_depends SRC) # Temporarily set that we didn't get a 3rd argument before we actually check if we did get one or not set(CHECK_ANGLE_INCLUDES FALSE) # Check for a third argument - if(${ARGC} GREATER 3) + if(${ARGC} GREATER 1) set(CHECK_ANGLE_INCLUDES TRUE) - endif(${ARGC} GREATER 3) + endif(${ARGC} GREATER 1) # Find all the lines in the given source file that have any form of #include on them, regardless of whitespace, but only if they are valid for the platform we are on find_includes(${SRC} INCLUDES) # Reset the list of headers to empty set(HEADERS) - # Reset skip - set(${SKIP} FALSE) # Iterate through the strings containing #include (if any) foreach(INCLUDE ${INCLUDES}) # Extract the filename from the #include line @@ -402,22 +400,16 @@ macro(calculate_depends SRC SKIP MODULE) endif(FOUND_DEFAULT) endforeach(DEFAULT_INCLUDE_DIR) if(FOUND_IN_DEFAULTS EQUAL -1) - find_in_list(${ARGV3} "${FOUND_${FILENAME}_INCLUDE}" FOUND_IN_INCLUDES) + find_in_list(${ARGV1} "${FOUND_${FILENAME}_INCLUDE}" FOUND_IN_INCLUDES) if(FOUND_IN_INCLUDES EQUAL -1) - append_to_list(${ARGV3} "${FOUND_${FILENAME}_INCLUDE}") + append_to_list(${ARGV1} "${FOUND_${FILENAME}_INCLUDE}") endif(FOUND_IN_INCLUDES EQUAL -1) endif(FOUND_IN_DEFAULTS EQUAL -1) else(FOUND_${FILENAME}_INCLUDE) - if(${FILENAME} STREQUAL "libintl.h") - # XXX - else(${FILENAME} STREQUAL "libintl.h") - set(${SKIP} TRUE) - if(NOT ${MODULE}) - message(FATAL_ERROR "${SRC} needs header file ${FILENAME} but we were unable to locate that header file! Check that the header file is within the search path of your OS.") - else(NOT ${MODULE}) - message(" ${SRC} can not be built due to missing dependencies - requires header file ${FILENAME}") - endif(NOT ${MODULE}) - endif(${FILENAME} STREQUAL "libintl.h") + # XXX + if(NOT ${FILENAME} STREQUAL "libintl.h") + message(FATAL_ERROR "${SRC} needs header file ${FILENAME} but we were unable to locate that header file! Check that the header file is within the search path of your OS.") + endif(NOT ${FILENAME} STREQUAL "libintl.h") endif(FOUND_${FILENAME}_INCLUDE) endif(CHECK_ANGLE_INCLUDES) endif(QUOTE_TYPE STREQUAL "angle brackets") @@ -425,12 +417,12 @@ macro(calculate_depends SRC SKIP MODULE) endmacro(calculate_depends) ############################################################################### -# calculate_libraries(<source filename> <output variable set to TRUE on fail> <TRUE if the source file is a module> <output variable for linker flags> <output variable for extra depends>) +# calculate_libraries(<source filename> <output variable for linker flags> <output variable for extra depends>) # # This macro is used in most of the module (sub)directories to calculate the # library dependencies for the given source file. ############################################################################### -macro(calculate_libraries SRC SKIP MODULE SRC_LDFLAGS EXTRA_DEPENDS) +macro(calculate_libraries SRC SRC_LDFLAGS EXTRA_DEPENDS) # Set up a temporary LDFLAGS for this file set(THIS_LDFLAGS "${LDFLAGS}") # Reset extra dependencies @@ -439,8 +431,6 @@ macro(calculate_libraries SRC SKIP MODULE SRC_LDFLAGS EXTRA_DEPENDS) set(LIBRARY_PATHS) # Reset libraries set(LIBRARIES) - # Default to not skipping this file - set(${SKIP} FALSE) # Check to see if there are any lines matching: /* RequiredLibraries: [something] */ read_from_file(${SRC} "/\\\\*[ \t]*RequiredLibraries:[ \t]*.*[ \t]*\\\\*/" REQUIRED_LIBRARIES) # Iterate through those lines @@ -470,40 +460,32 @@ macro(calculate_libraries SRC SKIP MODULE SRC_LDFLAGS EXTRA_DEPENDS) append_to_list(LIBRARIES "${LIBRARY}") endif(MSVC) else(FOUND_${LIBRARY}_LIBRARY) - # Skip this file - set(${SKIP} TRUE) - if(NOT ${MODULE}) - # In the case of the library not being found, we fatally error so CMake stops trying to generate - message(FATAL_ERROR "${SRC} needs library ${LIBRARY} but we were unable to locate that library! Check that the library is within the search path of your OS.") - else(NOT ${MODULE}) - message(" ${SRC} can not be built due to missing dependencies - requires library ${LIBRARY}") - endif(NOT ${MODULE}) + # In the case of the library not being found, we fatally error so CMake stops trying to generate + message(FATAL_ERROR "${SRC} needs library ${LIBRARY} but we were unable to locate that library! Check that the library is within the search path of your OS.") endif(FOUND_${LIBRARY}_LIBRARY) endforeach(LIBRARY) endforeach(REQUIRED_LIBRARY) - if(NOT ${SKIP}) - # Remove duplicates from the library paths - if(LIBRARY_PATHS) - remove_list_duplicates(LIBRARY_PATHS) - endif(LIBRARY_PATHS) - # Remove diplicates from the libraries - if(LIBRARIES) - remove_list_duplicates(LIBRARIES) - endif(LIBRARIES) - # Iterate through library paths and add them to the linker flags - foreach(LIBRARY_PATH ${LIBRARY_PATHS}) - find_in_list(DEFAULT_LIBRARY_DIRS "${LIBRARY_PATH}" FOUND_IN_DEFAULTS) - if(FOUND_IN_DEFAULTS EQUAL -1) - set(THIS_LDFLAGS "${THIS_LDFLAGS} -L${LIBRARY_PATH}") - endif(FOUND_IN_DEFAULTS EQUAL -1) - endforeach(LIBRARY_PATH) - # Iterate through libraries and add them to the linker flags - foreach(LIBRARY ${LIBRARIES}) - append_to_list(EXTRA_DEPENDENCIES "${LIBRARY}") - endforeach(LIBRARY) - set(${SRC_LDFLAGS} "${THIS_LDFLAGS}") - set(${EXTRA_DEPENDS} "${EXTRA_DEPENDENCIES}") - endif(NOT ${SKIP}) + # Remove duplicates from the library paths + if(LIBRARY_PATHS) + remove_list_duplicates(LIBRARY_PATHS) + endif(LIBRARY_PATHS) + # Remove diplicates from the libraries + if(LIBRARIES) + remove_list_duplicates(LIBRARIES) + endif(LIBRARIES) + # Iterate through library paths and add them to the linker flags + foreach(LIBRARY_PATH ${LIBRARY_PATHS}) + find_in_list(DEFAULT_LIBRARY_DIRS "${LIBRARY_PATH}" FOUND_IN_DEFAULTS) + if(FOUND_IN_DEFAULTS EQUAL -1) + set(THIS_LDFLAGS "${THIS_LDFLAGS} -L${LIBRARY_PATH}") + endif(FOUND_IN_DEFAULTS EQUAL -1) + endforeach(LIBRARY_PATH) + # Iterate through libraries and add them to the linker flags + foreach(LIBRARY ${LIBRARIES}) + append_to_list(EXTRA_DEPENDENCIES "${LIBRARY}") + endforeach(LIBRARY) + set(${SRC_LDFLAGS} "${THIS_LDFLAGS}") + set(${EXTRA_DEPENDS} "${EXTRA_DEPENDENCIES}") endmacro(calculate_libraries) ############################################################################### diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 1ec4e1087..bce14a6ff 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,217 +1,163 @@ -add_subdirectory("third/language") - -# Get a list of ALL files and directories within the current directory -file(GLOB MODULES_FOLDERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*") -remove_item_from_list(MODULES_FOLDERS "CMakeFiles") -append_to_list(MODULES_FOLDERS ".") - # If using Windows, add the MODULE_COMPILE define if(WIN32) add_definitions(-DMODULE_COMPILE) endif(WIN32) -# Iterate through the directories -foreach(MODULE_FOLDER ${MODULES_FOLDERS}) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_FOLDER}") - # Get a list of all .cpp files in this directory - file(GLOB MODULES_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${MODULE_FOLDER}/*.cpp") - sort_list(MODULES_SRCS) - - # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though) - set_source_files_properties(${MODULES_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") - - # Create an empty list to store extra include directories - set(EXTRA_INCLUDES) - - set(MODULE TRUE) - - # Get the length of the folder name - string(LENGTH ${MODULE_FOLDER} FOLDER_LEN) - # Add one (the /) - math(EXPR FOLDER_LEN "${FOLDER_LEN} + 1") - - # Iterate through all the source files - foreach(SRC ${MODULES_SRCS}) - # Get the length of the new source file - string(LENGTH ${SRC} SRC_LEN) - # Set FILE_LEN to the length of the source file minus folder length - math(EXPR FILE_LEN "${SRC_LEN} - ${FOLDER_LEN}") - # Get the real name of the source file now - string(SUBSTRING ${SRC} ${FOLDER_LEN} ${FILE_LEN} SRC_REALNAME) - # Convert the real source file extension to have a .so extension - string(REGEX REPLACE "\\.cpp$" ".so" SO ${SRC_REALNAME}) - # Reset skip_depends - set(SKIP_DEPENDS) - # Temporary variable for the current source's include directories - set(TEMP_INCLUDES) - # Calculate the header file dependencies for the given source file - calculate_depends(${SRC} SKIP_DEPENDS MODULE TEMP_INCLUDES) - # If there were some extra include directories, add them to the list - if(TEMP_INCLUDES) - append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES}) - endif(TEMP_INCLUDES) - # Reset linker flags - set(TEMP_LDFLAGS) - # Reset extra dependencies - set(TEMP_DEPENDENCIES) - # Reset skip_libraries - set(SKIP_LIBRARIES) - # Calculate the library dependencies for the given source file - calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES) - if(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES) - # Reset has_function - set(HAS_FUNCTION) - # Check the function dependencies for the given source file - check_functions(${SRC} HAS_FUNCTION) - # Only continue if this module has all of the required functions - if(HAS_FUNCTION) - # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators - if(MSVC) - set(WIN32_MEMORY win32_memory) - else(MSVC) - set(WIN32_MEMORY) - endif(MSVC) - # Generate the module and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand - add_library(${SO} MODULE ${SRC}) - # Windows requires this because it's weird - if(WIN32) - set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\"") - else(WIN32) - set(WIN32_NO_LIBS) - endif(WIN32) - set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) - add_dependencies(${SO} ${PROGRAM_NAME}) - if(GETTEXT_FOUND) - add_dependencies(${SO} module_language) - endif(GETTEXT_FOUND) - target_link_libraries(${SO} ${TEMP_DEPENDENCIES}) - # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set it's version - if(WIN32) - target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY}) - set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}") - else(WIN32) - if(APPLE) - target_link_libraries(${SO} ${PROGRAM_NAME}) - endif(APPLE) - endif(WIN32) - # Set the module to be installed to the module directory under the data directory - install(TARGETS ${SO} - DESTINATION ${LIB_DIR}/modules - ) - endif(HAS_FUNCTION) - endif(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES) - endforeach(SRC) - - if(NOT MODULE_FOLDER STREQUAL ".") - # Get a list of ALL files and directories within this modules directory - file(GLOB SUBMODULE_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${MODULE_FOLDER}/*") - remove_item_from_list(SUBMODULE_DIRS "CMakeFiles") - remove_item_from_list(SUBMODULE_DIRS "third/language") - - foreach(SUBDIR ${SUBMODULE_DIRS}) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") - file(GLOB_RECURSE MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIR}/*.cpp") - sort_list(MODULES_SUBDIR_SRCS) - - # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though) - set_source_files_properties(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") - - # Get the length of this subdir - string(LENGTH ${SUBDIR} SUBDIR_LEN) - # Calculate the length of the folder - math(EXPR FILE_LEN "${SUBDIR_LEN} - ${FOLDER_LEN}") - # Extract this subfolders name to use to generate the .so file - string(SUBSTRING ${SUBDIR} ${FOLDER_LEN} ${FILE_LEN} SUBDIR_REALNAME) - # Add .so to the end of the directory name, this will be the module's name - set(SO "${SUBDIR_REALNAME}.so") - - # Temporary linker flags for this subdirectory - set(SUBDIR_LDFLAGS "${LDFLAGS}") - # Temporary extra dependencies for this subdirectory - set(SUBDIR_EXTRA_DEPENDS) - # Reset skip_depends - set(SKIP_DEPENDS) - # Reset skip_libraries - set(SKIP_LIBRARIES) +function(build_modules SRC) + if(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt") + add_subdirectory("${SRC}") + else(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt") + file(GLOB MODULES_SRCS "${SRC}/*") + foreach(MODULE_SRC ${MODULES_SRCS}) + if(IS_DIRECTORY "${MODULE_SRC}") + build_modules("${MODULE_SRC}") + else(IS_DIRECTORY "${MODULE_SRC}") + string(REGEX MATCH "\\.cpp$" CPP ${MODULE_SRC}) + if(CPP) + file(RELATIVE_PATH FNAME ${SRC} ${MODULE_SRC}) + # Convert the real source file extension to have a .so extension + string(REGEX REPLACE "\\.cpp$" ".so" SO ${FNAME}) + # Temporary variable for the current source's include directories + set(TEMP_INCLUDES) + # Calculate the header file dependencies for the given source file + calculate_depends(${MODULE_SRC} TEMP_INCLUDES) + # If there were some extra include directories, add them to the list + if(TEMP_INCLUDES) + append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES}) + endif(TEMP_INCLUDES) + + # Reset linker flags + set(TEMP_LDFLAGS) + # Reset extra dependencies + set(TEMP_DEPENDENCIES) + # Calculate the library dependencies for the given source file + calculate_libraries(${MODULE_SRC} TEMP_LDFLAGS TEMP_DEPENDENCIES) # Reset has_function - set(HAS_FUNCTION TRUE) - - # Iterate through the source files in the subdirectory - foreach(SRC ${MODULES_SUBDIR_SRCS}) - if(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES AND HAS_FUNCTION) - # Temporary variable for the current source's include directories - set(TEMP_INCLUDES) - # Calculate the header file dependencies for the given source file - calculate_depends(${SRC} SKIP_DEPENDS MODULE TEMP_INCLUDES) - # If there were some extra include directories, add them to the list - if(TEMP_INCLUDES) - append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES}) - endif(TEMP_INCLUDES) - # Reset linker flags - set(TEMP_LDFLAGS) - # Reset extra dependencies - set(TEMP_DEPENDENCIES) - # Calculate the library dependencies for the given source file - calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES) - # Check the function dependencies for the given source file - check_functions(${SRC} HAS_FUNCTION) - - # Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append - if(TEMP_DEPENDENCIES) - append_to_list(SUBDIR_EXTRA_DEPENDS ${TEMP_DEPDENCIES}) - endif(TEMP_DEPENDENCIES) - endif(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES AND HAS_FUNCTION) - endforeach(SRC) - - # Continue if library and function requirements are met - if(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES AND HAS_FUNCTION) - # Remove duplicates from the linker flags - if(SUBDIR_LDFLAGS) - remove_list_duplicates(SUBDIR_LDFLAGS) - endif(SUBDIR_LDFLAGS) - # Remove duplicates from the extra dependencies - if(SUBDIR_EXTRA_DEPENDS) - remove_list_duplicates(SUBDIR_EXTRA_DEPENDS) - endif(SUBDIR_EXTRA_DEPENDS) - + set(HAS_FUNCTION) + # Check the function dependencies for the given source file + check_functions(${MODULE_SRC} HAS_FUNCTION) + # Only continue if this module has all of the required functions + if(HAS_FUNCTION) # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators if(MSVC) set(WIN32_MEMORY win32_memory) else(MSVC) set(WIN32_MEMORY) endif(MSVC) - - # Generate the module and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand - add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS}) - set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) + # Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand + add_library(${SO} MODULE ${MODULE_SRC}) + # Windows requires this because it's weird + if(WIN32) + set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\"") + else(WIN32) + set(WIN32_NO_LIBS) + endif(WIN32) + set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) add_dependencies(${SO} ${PROGRAM_NAME}) - target_link_libraries(${SO} ${PROGRAM_NAME}) if(GETTEXT_FOUND) add_dependencies(${SO} module_language) endif(GETTEXT_FOUND) - # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set it's version + target_link_libraries(${SO} ${TEMP_DEPENDENCIES}) + # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set its version if(WIN32) - target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY} ${SUBDIR_EXTRA_DEPENDS}) - set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}") + target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY}) + set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}") + else(WIN32) + if(APPLE) + target_link_libraries(${SO} ${PROGRAM_NAME}) + endif(APPLE) endif(WIN32) # Set the module to be installed to the module directory under the data directory - install(TARGETS ${SO} - DESTINATION ${LIB_DIR}/modules - ) - endif(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES AND HAS_FUNCTION) - - # Run the directories CMakeLists.txt if there is one - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/CMakeLists.txt") - add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") - endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/CMakeLists.txt") - endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") - endforeach(SUBDIR) - endif(NOT MODULE_FOLDER STREQUAL ".") - endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_FOLDER}") -endforeach(MODULE_FOLDER) - -# If there were extra include directories, remove the duplicates and add the directories to the include path -if(EXTRA_INCLUDES) - remove_list_duplicates(EXTRA_INCLUDES) - include_directories(${EXTRA_INCLUDES}) -endif(EXTRA_INCLUDES) + install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules) + endif(HAS_FUNCTION) + endif(CPP) + endif(IS_DIRECTORY "${MODULE_SRC}") + endforeach(MODULE_SRC ${MODULES_SRCS}) + endif(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt") +endfunction(build_modules) + +function(build_subdir) + file(GLOB_RECURSE MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") + sort_list(MODULES_SUBDIR_SRCS) + + GET_FILENAME_COMPONENT(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + set(SO "${FOLDER_NAME}.so") + + # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though) + set_source_files_properties(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") + + set(HAS_FUNCTION TRUE) + + # Iterate through the source files in the subdirectory + foreach(SRC ${MODULES_SUBDIR_SRCS}) + if(HAS_FUNCTION) + # Temporary variable for the current source's include directories + set(TEMP_INCLUDES) + # Calculate the header file dependencies for the given source file + calculate_depends(${SRC} TEMP_INCLUDES) + # If there were some extra include directories, add them to the list + if(TEMP_INCLUDES) + include_directories(${TEMP_INCLUDES}) + endif(TEMP_INCLUDES) + + # Reset linker flags + set(TEMP_LDFLAGS) + # Reset extra dependencies + set(TEMP_DEPENDENCIES) + # Calculate the library dependencies for the given source file + calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES) + # Check the function dependencies for the given source file + check_functions(${SRC} HAS_FUNCTION) + + # Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append + if(TEMP_DEPENDENCIES) + append_to_list(SUBDIR_EXTRA_DEPENDS ${TEMP_DEPDENCIES}) + endif(TEMP_DEPENDENCIES) + endif(HAS_FUNCTION) + endforeach(SRC ${MODULES_SUBDIR_SRCS}) + + # Continue if library and function requirements are met + if(HAS_FUNCTION) + # Remove duplicates from the linker flags + if(SUBDIR_LDFLAGS) + remove_list_duplicates(SUBDIR_LDFLAGS) + endif(SUBDIR_LDFLAGS) + + # Remove duplicates from the extra dependencies + if(SUBDIR_EXTRA_DEPENDS) + remove_list_duplicates(SUBDIR_EXTRA_DEPENDS) + endif(SUBDIR_EXTRA_DEPENDS) + + # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators + if(MSVC) + set(WIN32_MEMORY win32_memory) + else(MSVC) + set(WIN32_MEMORY) + endif(MSVC) + + # Generate the module and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand + add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS}) + set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) + add_dependencies(${SO} ${PROGRAM_NAME}) + if(GETTEXT_FOUND) + add_dependencies(${SO} module_language) + endif(GETTEXT_FOUND) + target_link_libraries(${SO} ${SUBDIR_EXTRA_DEPENDS}) + # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set it's version + if(WIN32) + target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY}) + set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}") + else(WIN32) + if(APPLE) + target_link_libraries(${SO} ${PROGRAM_NAME}) + endif(APPLE) + endif(WIN32) + + # Set the module to be installed to the module directory under the data directory + install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules) + + endif(HAS_FUNCTION) +endfunction(build_subdir) + +build_modules(${CMAKE_CURRENT_SOURCE_DIR}) + diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index 04971e89a..346ff4727 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -6,7 +6,7 @@ */ #include "module.h" -#include "../extra/dns.h" +#include "../dns.h" static ServiceReference<DNS::Manager> dnsmanager("DNS::Manager", "dns/manager"); diff --git a/modules/extra/dns.h b/modules/dns.h index 469bb0e82..469bb0e82 100644 --- a/modules/extra/dns.h +++ b/modules/dns.h diff --git a/modules/extra/CMakeLists.txt b/modules/extra/CMakeLists.txt new file mode 100644 index 000000000..6c50f8605 --- /dev/null +++ b/modules/extra/CMakeLists.txt @@ -0,0 +1,3 @@ +# This file is here to prevent the building of the extras directory. +# Users who want to build the contents of this directory should copy +# or symlink files out of it. diff --git a/modules/extra/webcpanel/CMakeLists.txt b/modules/extra/webcpanel/CMakeLists.txt index 4437156ad..247973f61 100644 --- a/modules/extra/webcpanel/CMakeLists.txt +++ b/modules/extra/webcpanel/CMakeLists.txt @@ -1,3 +1,4 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) install(DIRECTORY templates DESTINATION "${DB_DIR}/modules/webcpanel" diff --git a/modules/extra/m_dns.cpp b/modules/m_dns.cpp index e8f3bd758..e8f3bd758 100644 --- a/modules/extra/m_dns.cpp +++ b/modules/m_dns.cpp diff --git a/modules/m_dnsbl.cpp b/modules/m_dnsbl.cpp index 27aaff794..bf7c02fa0 100644 --- a/modules/m_dnsbl.cpp +++ b/modules/m_dnsbl.cpp @@ -6,7 +6,7 @@ */ #include "module.h" -#include "extra/dns.h" +#include "dns.h" using namespace DNS; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2dbb6c71..be3f1010f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,11 +36,8 @@ set(EXTRA_INCLUDES) foreach(SRC ${SRC_SRCS}) # Temporary variable for the current source's include directories set(TEMP_INCLUDES) - # Create unused skip variable - set(SKIP) - set(MODULE FALSE) # Calculate the header file dependencies for the given source file - calculate_depends(${SRC} SKIP MODULE TEMP_INCLUDES) + calculate_depends(${SRC} TEMP_INCLUDES) # If there were some extra include directories, add them to the list if(TEMP_INCLUDES) append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES}) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 88e03f615..8d66e577f 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -9,11 +9,8 @@ set_source_files_properties(${TOOLS_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS foreach(SRC ${TOOLS_SRCS}) # Convert the source file extension to have no extension string(REGEX REPLACE "\\.cpp$" "" EXE ${SRC}) - # Create skip variable - set(SKIP) - set(MODULE FALSE) # Calculate the header file dependencies for the given source file - calculate_depends(${SRC} SKIP MODULE) + calculate_depends(${SRC}) # Only continue if this file isn't skipped if(NOT SKIP) # Generate the executable and set its linker flags, also set it to depend on the main Anope executable to be built beforehand |