1
0
mirror of https://github.com/anope/anope.git synced 2026-07-01 11:46:37 +02:00

Rip out calculate_depends().

This code is incredibly error prone and it just duplicates behaviour
that CMake already implements with depend.make files.
This commit is contained in:
Sadie Powell
2022-01-13 01:36:45 +00:00
parent 40ce51a1a9
commit eaaabd8de0
4 changed files with 0 additions and 222 deletions
-183
View File
@@ -1,186 +1,3 @@
###############################################################################
# extract_include_filename(<line> <output variable> [<optional output variable of quote type>])
#
# This macro will take a #include line and extract the filename.
###############################################################################
macro(extract_include_filename INCLUDE FILENAME)
# Strip the leading and trailing spaces from the include line
string(STRIP ${INCLUDE} INCLUDE_STRIPPED)
# Make sure to only do the following if there is a string
if(INCLUDE_STRIPPED STREQUAL "")
set(FILE "")
else()
# 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)
if(QUOTE STREQUAL "<")
set(${ARGV2} "angle brackets")
else()
set(${ARGV2} "quotes")
endif()
endif()
# Now remove the quotes or angle brackets
string(REGEX REPLACE "^[\"<](.*)[\">]$" "\\1" FILE "${FILE}")
endif()
# Set the filename to the the given variable
set(${FILENAME} "${FILE}")
endmacro()
###############################################################################
# find_includes(<source filename> <output variable>)
#
# 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 #
file(STRINGS ${SRC} LINES REGEX "^[ \t]*#.*$")
# 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()
# 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()
set(VALID_LINE FALSE)
endif()
else()
# If we found a #ifndef on the line, the same thing as #ifdef is done, except with the checks in the opposite direction
if(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()
# 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(${DEFINE})
set(VALID_LINE FALSE)
else()
set(VALUE_LINE TRUE)
endif()
else()
# If we found a #else on the line, we check the last define in the opposite direction
if(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(${LAST_DEF})
set(VALID_LINE FALSE)
else()
set(VALID_LINE TRUE)
endif()
# 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()
if(${LAST_DEF})
set(VALID_LINE TRUE)
else()
set(VALID_LINE FALSE)
endif()
endif()
else()
# 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
if(FOUND_ENDIF)
set(VALID_LINE TRUE)
else()
# If we found a #include on the line, add the entire line to the list of includes unless the line isn't valid
if(FOUND_INCLUDE)
if(VALID_LINE)
list(APPEND INCLUDES_LIST "${LINE}")
endif()
endif()
endif()
endif()
endif()
endif()
endforeach()
set(${INCLUDES} ${INCLUDES_LIST})
endmacro()
###############################################################################
# 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)
# 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 1)
set(CHECK_ANGLE_INCLUDES TRUE)
endif()
# 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 QUOTE_TYPE)
if(QUOTE_TYPE STREQUAL "angle brackets")
# 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 OR DEFINED $ENV{VCINSTALLDIR})
find_path(FOUND_${FILENAME}_INCLUDE NAMES ${FILENAME} PATHS ${DEFAULT_INCLUDE_DIRS} ${WSDK_PATH}/include $ENV{VCINSTALLDIR}/include ${EXTRA_INCLUDE})
else()
find_path(FOUND_${FILENAME}_INCLUDE NAMES ${FILENAME} ${EXTRA_INCLUDE})
endif()
# 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)
# This used to be list(FIND), but it was changed to this loop to do a find on each default include directory, this fixes Mac OS X trying to get it's framework directories in here
set(FOUND_IN_DEFAULTS -1)
foreach(DEFAULT_INCLUDE_DIR ${DEFAULT_INCLUDE_DIRS})
string(REGEX REPLACE "\\+" "\\\\+" DEFAULT_INCLUDE_DIR ${DEFAULT_INCLUDE_DIR})
string(REGEX MATCH ${DEFAULT_INCLUDE_DIR} FOUND_DEFAULT ${FOUND_${FILENAME}_INCLUDE})
if(FOUND_DEFAULT)
set(FOUND_IN_DEFAULTS 0)
endif()
endforeach()
if(FOUND_IN_DEFAULTS EQUAL -1)
if("${FOUND_${FILENAME}_INCLUDE}" IN_LIST ARGV1)
list(APPEND ${ARGV1} "${FOUND_${FILENAME}_INCLUDE}")
endif()
endif()
else()
# 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()
endif()
endif()
endif()
endforeach()
endmacro()
###############################################################################
# calculate_libraries(<source filename> <output variable for linker flags> <output variable for extra depends>)
#
-18
View File
@@ -23,15 +23,6 @@ macro(build_modules SRC)
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)
list(APPEND EXTRA_INCLUDES ${TEMP_INCLUDES})
endif()
# Reset linker flags
set(TEMP_LDFLAGS)
# Reset extra dependencies
@@ -95,15 +86,6 @@ macro(build_subdir)
# 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()
# Reset linker flags
set(TEMP_LDFLAGS)
# Reset extra dependencies
-19
View File
@@ -26,25 +26,6 @@ list(SORT SRC_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(${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} TEMP_INCLUDES)
# If there were some extra include directories, add them to the list
if(TEMP_INCLUDES)
list(APPEND EXTRA_INCLUDES ${TEMP_INCLUDES})
endif()
endforeach()
# If there were extra include directories, remove the duplicates and add the directories to the include path
if(EXTRA_INCLUDES)
list(REMOVE_DUPLICATES EXTRA_INCLUDES)
include_directories(${EXTRA_INCLUDES})
endif()
# Under Windows, we also include a resource file to the build
if(WIN32)
# Make sure that the resource file is seen as an RC file to be compiled with a resource compiler, not a C++ compiler
-2
View File
@@ -9,8 +9,6 @@ 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})
# Calculate the header file dependencies for the given source file
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