diff options
author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-03-02 01:33:47 +0000 |
---|---|---|
committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-03-02 01:33:47 +0000 |
commit | c6f4b951317ad3c78844359742de66ce63210ef0 (patch) | |
tree | a990f1aea84132625830d3cca72c454dd7fb0dae | |
parent | 6794273f7d44987b061f038bc3c7909fa64a86d5 (diff) |
Added a strip_string function to Anope.cmake, cleaned up other parts of Anope.cmake, added better find function for #include lines, added functionality for CMake to auto-detect includes in non-standard locations.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2139 5417fbe8-f217-4b02-8779-1006273d7864
-rw-r--r-- | Anope.cmake | 231 | ||||
-rw-r--r-- | CMakeLists.txt | 29 | ||||
-rw-r--r-- | src/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/core/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/modules/CMakeLists.txt | 29 | ||||
-rw-r--r-- | src/protocol/CMakeLists.txt | 17 |
6 files changed, 272 insertions, 66 deletions
diff --git a/Anope.cmake b/Anope.cmake index 6ea65a7e7..68eae0453 100644 --- a/Anope.cmake +++ b/Anope.cmake @@ -1,4 +1,36 @@ ############################################################################### +# strip_string(<input string> <output string>) +# +# A macro to handle stripping the leading and trailing spaces from a string, +# uses string(STRIP) if using CMake 2.6.x or better, otherwise uses +# string(REGEX REPLACE). +############################################################################### +macro(strip_string INPUT_STRING OUTPUT_STRING) + if(CMAKE26_OR_BETTER) + # For CMake 2.6.x or better, we can just use the STRIP sub-command of string() + string(STRIP ${INPUT_STRING} ${OUTPUT_STRING}) + else(CMAKE26_OR_BETTER) + # For CMake 2.4.x, we will have to use the REGEX REPLACE sub-command of string() instead + # First we detect if there is any leading whitespace and remove any if there is + string(SUBSTRING "${INPUT_STRING}" 0 1 FIRST_CHAR) + if(FIRST_CHAR STREQUAL " " OR FIRST_CHAR STREQUAL "\t") + string(REGEX REPLACE "^[ \t]*" "" TEMP_STRING "${INPUT_STRING}") + else(FIRST_CHAR STREQUAL " " OR FIRST_CHAR STREQUAL "\t") + set(TEMP_STRING "${INPUT_STRING}") + endif(FIRST_CHAR STREQUAL " " OR FIRST_CHAR STREQUAL "\t") + # Next we detect if there is any trailing whitespace and remove any if there is + string(LENGTH "${TEMP_STRING}" STRING_LEN) + math(EXPR STRING_LEN "${STRING_LEN} - 1") + string(SUBSTRING "${TEMP_STRING}" ${STRING_LEN} 1 LAST_CHAR) + if(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") + string(REGEX REPLACE "[ \t]*$" "" ${OUTPUT_STRING} "${TEMP_STRING}") + else(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") + set(${OUTPUT_STRING} "${TEMP_STRING}") + endif(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") + endif(CMAKE26_OR_BETTER) +endmacro(strip_string) + +############################################################################### # append_to_list(<list> <args>...) # # A macro to handle appending to lists, uses list(APPEND) if using CMake 2.4.2 @@ -79,28 +111,39 @@ endmacro(remove_list_duplicates) # # A macro to handle reading specific lines from a file, uses file(STRINGS) if # using CMake 2.6.x or better, otherwise we read in the entire file and -# perform a string(REGEX MATCH) on each line of the file instead. +# perform a string(REGEX MATCH) on each line of the file instead. This +# macro can also be used to read in all the lines of a file if REGEX is set +# to "". ############################################################################### macro(read_from_file FILE REGEX STRINGS) if(CMAKE26_OR_BETTER) - # For CMake 2.6.x or better, we can just use this function to get the lines that match the given regular expression - file(STRINGS ${FILE} RESULT REGEX ${REGEX}) + # For CMake 2.6.x or better, we can just use the STRINGS sub-command to get the lines that match the given regular expression (if one is given, otherwise get all lines) + if(REGEX STREQUAL "") + file(STRINGS ${FILE} RESULT) + else(REGEX STREQUAL "") + file(STRINGS ${FILE} RESULT REGEX ${REGEX}) + endif(REGEX STREQUAL "") else(CMAKE26_OR_BETTER) # For CMake 2.4.x, we need to do this manually, firstly we read the file in file(READ ${FILE} ALL_STRINGS) # Next we replace all newlines with semicolons string(REGEX REPLACE "\n" ";" ALL_STRINGS ${ALL_STRINGS}) - # Clear the result list - set(RESULT) - # Iterate through all the lines of the file - foreach(STRING ${ALL_STRINGS}) - # Check for a match against the given regular expression - string(REGEX MATCH ${REGEX} STRING_MATCH ${STRING}) - # If we had a match, append the match to the list - if(STRING_MATCH) - append_to_list(RESULT ${STRING}) - endif(STRING_MATCH) - endforeach(STRING) + if(REGEX STREQUAL "") + # For no regular expression, just set the result to all the lines + set(RESULT ${ALL_STRINGS}) + else(REGEX STREQUAL "") + # Clear the result list + set(RESULT) + # Iterate through all the lines of the file + foreach(STRING ${ALL_STRINGS}) + # Check for a match against the given regular expression + string(REGEX MATCH ${REGEX} STRING_MATCH ${STRING}) + # If we had a match, append the match to the list + if(STRING_MATCH) + append_to_list(RESULT ${STRING}) + endif(STRING_MATCH) + endforeach(STRING) + endif(REGEX STREQUAL "") endif(CMAKE26_OR_BETTER) # Set the given STRINGS variable to the result set(${STRINGS} ${RESULT}) @@ -109,23 +152,13 @@ endmacro(read_from_file) ############################################################################### # extract_include_filename(<line> <output variable> [<optional output variable of quote type>]) # -# This function will take a #include line and extract the filename. +# This macro will take a #include line and extract the filename. ############################################################################### macro(extract_include_filename INCLUDE FILENAME) - # Detect if there is any trailing whitespace (basically see if the last character is a space or a tab) - string(LENGTH ${INCLUDE} INCLUDE_LEN) - math(EXPR LAST_CHAR_POS "${INCLUDE_LEN} - 1") - string(SUBSTRING ${INCLUDE} ${LAST_CHAR_POS} 1 LAST_CHAR) - # Only strip if the last character was a space or a tab - if(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") - # Strip away trailing whitespace from the line - string(REGEX REPLACE "[ \t]*$" "" INCLUDE_STRIPPED ${INCLUDE}) - else(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") - # Just copy INCLUDE to INCLUDE_STRIPPED so the below code doesn't complain about a lack of INCLUDE_STRIPPED - set(INCLUDE_STRIPPED ${INCLUDE}) - endif(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") - # Find the filename including the quotes or angle brackets, it should be at the end of the line after whitespace was stripped - string(REGEX MATCH "[\"<].*[\">]$" FILE ${INCLUDE_STRIPPED}) + # Strip the leading and trailing spaces from the include line + strip_string(${INCLUDE} INCLUDE_STRIPPED) + # Extract the filename including the quotes or angle brackets + string(REGEX REPLACE "^.*([\"<].*[\">]).*$" "\\1" FILE "${INCLUDE_STRIPPED}") # If an optional 3rd argument is given, we'll store if the quote style was quoted or angle bracketed if(${ARGC} GREATER 2) string(SUBSTRING ${FILE} 0 1 QUOTE) @@ -135,33 +168,147 @@ macro(extract_include_filename INCLUDE FILENAME) set(${ARGV2} "quotes") endif(QUOTE STREQUAL "<") endif(${ARGC} GREATER 2) - # Get the length of the filename with quotes or angle brackets - string(LENGTH ${FILE} FILENAME_LEN) - # Subtract 2 from this length, for the quotes or angle brackets - math(EXPR FILENAME_LEN "${FILENAME_LEN} - 2") - # Overwrite the filename with a version sans quotes or angle brackets - string(SUBSTRING ${FILE} 1 ${FILENAME_LEN} FILE) + # Now remove the quotes or angle brackets + string(REGEX REPLACE "^[\"<](.*)[\">]$" "\\1" FILE "${FILE}") # Set the filename to the the given variable set(${FILENAME} "${FILE}") endmacro(extract_include_filename) ############################################################################### -# calculate_depends(<source filename>) +# find_includes(<source filename> <output variable>) # -# This function is used in most of the src (sub)directories to calculate the +# This macro will search through a file for #include lines, regardless of +# whitespace, but only returns the lines that are valid for the current +# platform CMake is running on. +############################################################################### +macro(find_includes SRC INCLUDES) + # Read all lines from the file that start with #, regardless of whitespace before the # + read_from_file(${SRC} "^[ \t]*#.*$" LINES) + # Set that any #include lines found are valid, and create temporary variables for the last found #ifdef/#ifndef + set(VALID_LINE TRUE) + set(LAST_DEF) + set(LAST_CHECK) + # Create an empty include list + set(INCLUDES_LIST) + # Iterate through all the # lines + foreach(LINE ${LINES}) + # Search for #ifdef, #ifndef, #else, #endif, and #include + string(REGEX MATCH "^[ \t]*#[ \t]*ifdef[ \t]*.*$" FOUND_IFDEF ${LINE}) + string(REGEX MATCH "^[ \t]*#[ \t]*ifndef[ \t]*.*$" FOUND_IFNDEF ${LINE}) + string(REGEX MATCH "^[ \t]*#[ \t]*else.*$" FOUND_ELSE ${LINE}) + string(REGEX MATCH "^[ \t]*#[ \t]*endif.*$" FOUND_ENDIF ${LINE}) + string(REGEX MATCH "^[ \t]*#[ \t]*include[ \t]*[\"<].*[\">][\ t]*.*$" FOUND_INCLUDE ${LINE}) + # If we found a #ifdef on the line, extract the data after the #ifdef and set if the lines after it are valid based on the variables in CMake + if(FOUND_IFDEF) + # Extract the define + string(REGEX REPLACE "^[ \t]*#[ \t]*ifdef[ \t]*(.*)$" "\\1" DEFINE ${LINE}) + # Replace _WIN32 with WIN32, so we can check if the WIN32 variable of CMake is set instead of _WIN32 + if(DEFINE STREQUAL "_WIN32") + set(DEFINE WIN32) + endif(DEFINE STREQUAL "_WIN32") + # Set the last define to this one, and set the last check to true, so when #else is encountered, we can do an opposing check + set(LAST_DEF ${DEFINE}) + set(LAST_CHECK TRUE) + # If the define is true (it either exists or is a non-false result), the lines following will be checked, otherwise they will be skipped + if(${DEFINE}) + set(VALID_LINE TRUE) + else(${DEFINE}) + set(VALID_LINE FALSE) + endif(${DEFINE}) + # If we found a #ifndef on the line, the same thing as #ifdef is done, except with the checks in the opposite direction + elseif(FOUND_IFNDEF) + # Extract the define + string(REGEX REPLACE "^[ \t]*#[ \t]*ifndef[ \t]*(.*)$" "\\1" DEFINE ${LINE}) + # Replace _WIN32 with WIN32, so we can check if the WIN32 variable of CMake is set instead of _WIN32 + if(DEFINE STREQUAL "_WIN32") + set(DEFINE WIN32) + endif(DEFINE STREQUAL "_WIN32") + # Set the last define to this one, and set the last check to false, so when #else is encountered, we can do an opposing check + set(LAST_DEF ${DEFINE}) + set(LAST_CHECK FALSE) + # If the define is not true (it either doesn't exists or is a false result), the lines following will be checked, otherwise they will be skipped + if(NOT ${DEFINE}) + set(VALID_LINE TRUE) + else(NOT ${DEFINE}) + set(VALUE_LINE FALSE) + endif(NOT ${DEFINE}) + # If we found a #else on the line, we check the last define in the opposite direction + elseif(FOUND_ELSE) + # When LAST_CHECK is true, we were inside a #ifdef, now act as if we are entering a #ifndef section by doing an opposing check + if(LAST_CHECK) + if(NOT ${LAST_DEF}) + set(VALID_LINE TRUE) + else(NOT ${LAST_DEF}) + set(VALID_LINE FALSE) + endif(NOT ${LAST_DEF}) + # When LAST_CHECK is false, we were inside a #ifndef, now act as if we are entering a #ifdef section by doing an opposing check + else(LAST_CHECK) + if(${LAST_DEF}) + set(VALID_LINE TRUE) + else(${LAST_DEF}) + set(VALID_LINE FALSE) + endif(${LAST_DEF}) + endif(LAST_CHECK) + # If we found a #endif on the line, we'll assume everything following the line is valid until we meet another one of the above lines + elseif(FOUND_ENDIF) + set(VALID_LINE TRUE) + # If we found a #include on the line, add the entire line to the list of includes unless the line isn't valid + elseif(FOUND_INCLUDE) + if(VALID_LINE) + append_to_list(INCLUDES_LIST "${LINE}") + endif(VALID_LINE) + endif(FOUND_IFDEF) + endforeach(LINE) + set(${INCLUDES} ${INCLUDES_LIST}) +endmacro(find_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) - # Find all the lines in the given source file that have any form of #include on them, regardless of whitespace - read_from_file(${SRC} "^[ \t]*#[ \t]*include[ \t]*\".*\"[ \t]*$" INCLUDES) + # Temporarily set that we didn't get a 2nd argument before we actually check if we did get one or not + set(CHECK_ANGLE_INCLUDES FALSE) + # Check for a second argument + if(${ARGC} GREATER 1) + set(CHECK_ANGLE_INCLUDES TRUE) + 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) # Iterate through the strings containing #include (if any) foreach(INCLUDE ${INCLUDES}) # Extract the filename from the #include line - extract_include_filename(${INCLUDE} FILENAME) - # Append the filename to the list of headers - append_to_list(HEADERS ${FILENAME}) + extract_include_filename(${INCLUDE} FILENAME QUOTE_TYPE) + if(QUOTE_TYPE STREQUAL "quotes") + # Append the filename to the list of headers + append_to_list(HEADERS ${FILENAME}) + else(QUOTE_TYPE STREQUAL "quotes") + # The following checks will only be done if there was a request for angle includes to be checked + if(CHECK_ANGLE_INCLUDES) + # Find the path of the include file + if(DEFAULT_INCLUDE_DIRS OR WSDK_PATH) + find_path(FOUND_${FILENAME}_INCLUDE NAMES ${FILENAME} PATHS ${DEFAULT_INCLUDE_DIRS} ${WSDK_PATH}/include) + else(DEFAULT_INCLUDE_DIRS OR WSDK_PATH) + find_path(FOUND_${FILENAME}_INCLUDE NAMES ${FILENAME}) + endif(DEFAULT_INCLUDE_DIRS OR WSDK_PATH) + # If the include file was found, add it's path to the list of include paths, but only if it doesn't already exist and isn't in the defaults for the compiler + if(FOUND_${FILENAME}_INCLUDE) + find_in_list(DEFAULT_INCLUDE_DIRS "${FOUND_${FILENAME}_INCLUDE}" FOUND_IN_DEFAULTS) + if(FOUND_IN_DEFAULTS EQUAL -1) + find_in_list(${ARGV1} "${FOUND_${FILENAME}_INCLUDE}" FOUND_IN_INCLUDES) + if(FOUND_IN_INCLUDES EQUAL -1) + append_to_list(${ARGV1} "${FOUND_${FILENAME}_INCLUDE}") + endif(FOUND_IN_INCLUDES EQUAL -1) + endif(FOUND_IN_DEFAULTS EQUAL -1) + else(FOUND_${FILENAME}_INCLUDE) + 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(FOUND_${FILENAME}_INCLUDE) + endif(CHECK_ANGLE_INCLUDES) + endif(QUOTE_TYPE STREQUAL "quotes") endforeach(INCLUDE) # Set the list of new headers to empty (this will store all the headers that the above list depends on) set(NEW_HEADERS) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6bc6eb93..a035b9c93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,9 @@ if(CMAKE_COMPILER_IS_GNUCXX) endif(NOT FIRST_CHAR STREQUAL "=") endforeach(LIBRARY) # Remove duplicate entries from the list - remove_list_duplicates(DEFAULT_LIBRARY_DIRS) + if(DEFAULT_LIBRARY_DIRS) + remove_list_duplicates(DEFAULT_LIBRARY_DIRS) + endif(DEFAULT_LIBRARY_DIRS) # Next, we look for the compiler's default include directories # Run the command to find the default include directories execute_process(COMMAND ${CMAKE_C_COMPILER} -v -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/empty.c ERROR_VARIABLE LINES OUTPUT_QUIET ERROR_STRIP_TRAILING_WHITESPACE) @@ -96,7 +98,9 @@ if(CMAKE_COMPILER_IS_GNUCXX) endif(LINE STREQUAL "#include <...> search starts here:") endforeach(LINE) # Remove duplicate entries from the list - remove_list_duplicates(DEFAULT_INCLUDE_DIRS) + if(DEFAULT_INCLUDE_DIRS) + remove_list_duplicates(DEFAULT_INCLUDE_DIRS) + endif(DEFAULT_INCLUDE_DIRS) endif(CMAKE_COMPILER_IS_GNUCXX) # 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 @@ -132,7 +136,7 @@ endif(MSVC) # If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition # and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE -# to Debug prior to calling PROJECT() +# to Debug # Only do this if not using Visual Studio if(NOT MSVC) if(CMAKE_BUILD_TYPE) @@ -276,17 +280,14 @@ check_type_size(int32_t INT32_T) check_type_size(uint32_t UINT32_T) check_type_size(u_int32_t U_INT32_T) -# Only CMake 2.6.x and later contain the STRIP sub-command for string() -if(CMAKE26_OR_BETTER) - # Strip the leading and trailing spaces from the compile flags - if(CXXFLAGS) - string(STRIP ${CXXFLAGS} CXXFLAGS) - endif(CXXFLAGS) - # Strip the leading and trailing spaces from the linker flags - if(LDFLAGS) - string(STRIP ${LDFLAGS} LDFLAGS) - endif(LDFLAGS) -endif(CMAKE26_OR_BETTER) +# Strip the leading and trailing spaces from the compile flags +if(CXXFLAGS) + strip_string(STRIP ${CXXFLAGS} CXXFLAGS) +endif(CXXFLAGS) +# Strip the leading and trailing spaces from the linker flags +if(LDFLAGS) + strip_string(STRIP ${LDFLAGS} LDFLAGS) +endif(LDFLAGS) # Search for the following programs find_program(GREP grep) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e700db49..d1cc3d832 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,11 +17,24 @@ endif(CMAKE244_OR_BETTER) # 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(${SRC_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") +# Create an empty list to store extra include directories +set(EXTRA_INCLUDES) # Iterate through all the source files foreach(SRC ${SRC_SRCS}) + # 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}) + 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}) + endif(TEMP_INCLUDES) endforeach(SRC) +# 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) # Under Windows, we also include a resource file to the build if(WIN32) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 0a3655806..ba1032f72 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -14,12 +14,21 @@ endif(WIN32) # 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(${CORE_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") +# Create an empty list to store extra include directories +set(EXTRA_INCLUDES) + # Iterate through all the source files foreach(SRC ${CORE_SRCS}) # Convert the source file extension to have a .so extension string(REGEX REPLACE "\\.(c|cpp)$" ".so" SO ${SRC}) + # 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}) + 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}) + endif(TEMP_INCLUDES) # For Visual Studio only, include win32_memory.cpp to the list of sources, required to override Visual Studio's overrides of the new/delete operators if(MSVC) append_to_list(SRC ${Anope_SOURCE_DIR}/src/win32_memory.cpp) @@ -39,3 +48,9 @@ foreach(SRC ${CORE_SRCS}) DESTINATION data/modules ) endforeach(SRC) + +# 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) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 3f1144c6f..65959b174 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -14,12 +14,21 @@ endif(WIN32) # 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) + # Iterate through all the source files foreach(SRC ${MODULES_SRCS}) # Convert the source file extension to have a .so extension string(REGEX REPLACE "\\.(c|cpp)$" ".so" SO ${SRC}) + # 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}) + 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}) + endif(TEMP_INCLUDES) # Set up a temporary LDFLAGS for this file set(THIS_LDFLAGS "${LDFLAGS}") # Reset extra dependencies @@ -39,11 +48,11 @@ foreach(SRC ${MODULES_SRCS}) # Iterate through the libraries given foreach(LIBRARY ${REQUIRED_LIBRARY}) # Locate the library to see if it exists - if(MSVC AND WSDK_PATH) - find_library(FOUND_${LIBRARY}_LIBRARY NAMES ${LIBRARY} PATHS ${WSDK_PATH}/lib) - else(MSVC AND WSDK_PATH) + if(DEFAULT_LIBRARY_DIRS OR WSDK_PATH) + find_library(FOUND_${LIBRARY}_LIBRARY NAMES ${LIBRARY} PATHS ${DEFAULT_LIBRARY_DIRS} ${WSDK_PATH}/lib) + else(DEFAULT_LIBRARY_DIRS OR WSDK_PATH) find_library(FOUND_${LIBRARY}_LIBRARY NAMES ${LIBRARY}) - endif(MSVC AND WSDK_PATH) + endif(DEFAULT_LIBRARY_DIRS OR WSDK_PATH) # If the library was found, we will add it to the linker flags if(FOUND_${LIBRARY}_LIBRARY) # Get the path only of the library, to add it to linker flags @@ -58,7 +67,7 @@ foreach(SRC ${MODULES_SRCS}) endif(MSVC) else(FOUND_${LIBRARY}_LIBRARY) # In the case of the library not being found, we fatally error so CMake stops trying to generate - message(FATAL_ERROR "${SRC} need library ${LIBRARY} but we were unable to locate that library! Check that the library is within the search path of your OS.") + 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) @@ -77,7 +86,7 @@ foreach(SRC ${MODULES_SRCS}) 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) + 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) @@ -100,3 +109,9 @@ foreach(SRC ${MODULES_SRCS}) DESTINATION data/modules ) endforeach(SRC) + +# 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) diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt index dc8d40126..c903545c3 100644 --- a/src/protocol/CMakeLists.txt +++ b/src/protocol/CMakeLists.txt @@ -14,12 +14,21 @@ endif(WIN32) # 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(${PROTOCOL_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") +# Create an empty list to store extra include directories +set(EXTRA_INCLUDES) + # Iterate through all the source files foreach(SRC ${PROTOCOL_SRCS}) # Convert the source file extension to have a .so extension string(REGEX REPLACE "\\.(c|cpp)$" ".so" SO ${SRC}) + # 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}) + 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}) + endif(TEMP_INCLUDES) # For Visual Studio only, include win32_memory.cpp to the list of sources, required to override Visual Studio's overrides of the new/delete operators if(MSVC) append_to_list(SRC ${Anope_SOURCE_DIR}/src/win32_memory.cpp) @@ -39,3 +48,9 @@ foreach(SRC ${PROTOCOL_SRCS}) DESTINATION data/modules ) endforeach(SRC) + +# 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) |