summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt116
-rw-r--r--include/CMakeLists.txt2
-rw-r--r--lang/CMakeLists.txt10
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/modules/CMakeLists.txt2
-rw-r--r--src/protocol/CMakeLists.txt2
-rw-r--r--src/protocol/inspircd11.c2
-rw-r--r--src/protocol/inspircd12.cpp2
-rw-r--r--src/tools/CMakeLists.txt2
10 files changed, 107 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4d3ea3c1f..09a40f8cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,16 @@
-# This usage of CMake requires at least version 2.6 (I don't know if it'll work with earlier versions)
-cmake_minimum_required(VERSION 2.6)
+# This usage of CMake requires at least version 2.4.4 (earlier versions lack the CheckCXXCompilerFlag module)
+cmake_minimum_required(VERSION 2.4.4 FATAL_ERROR)
+
+# Detect is we are using CMake 2.6 or better, these versions include functions that require less work than CMake 2.4 does
+if(CMAKE_MAJOR_VERSION GREATER 2)
+ set(CMAKE26_OR_BETTER TRUE)
+else(CMAKE_MAJOR_VERSION GREATER 2)
+ if(CMAKE_MINOR_VERSION GREATER 5)
+ set(CMAKE26_OR_BETTER TRUE)
+ else(CMAKE_MINOR_VERSION GREATER 5)
+ set(CMAKE26_OR_BETTER FALSE)
+ endif(CMAKE_MINOR_VERSION GREATER 5)
+endif(CMAKE_MAJOR_VERSION GREATER 2)
# 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
@@ -144,14 +155,65 @@ check_type_size(int32_t INT32_T)
check_type_size(uint32_t UINT32_T)
check_type_size(u_int32_t U_INT32_T)
-# 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)
+# 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)
+
+# A macro to handle reading specific lines from a file
+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})
+ else(CMAKE26_OR_BETTER)
+ # For CMake 2.4.x, we need to do this manually, firsly 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)
+ list(APPEND RESULT ${STRING})
+ endif(STRING_MATCH)
+ endforeach(STRING)
+ endif(CMAKE26_OR_BETTER)
+ # Set the given STRINGS variable to the result
+ set(${STRINGS} ${RESULT})
+endmacro(read_from_file)
+
+# A macro to handle removing duplicates from a list
+macro(remove_list_duplicates LIST)
+ if(CMAKE26_OR_BETTER)
+ # For CMake 2.6.x or better, this can be done automatically
+ list(REMOVE_DUPLICATES ${LIST})
+ else(CMAKE26_OR_BETTER)
+ # For CMake 2.4.x, we have to do this ourselves, firstly we'll clear a temporary list
+ set(NEW_LIST)
+ # Iterate through the old list
+ foreach(ITEM ${${LIST}})
+ # Check if the item is in the new list
+ list(FIND NEW_LIST ${ITEM} FOUND_ITEM)
+ if(FOUND_ITEM EQUAL -1)
+ # If the item was not found, append it to the list
+ list(APPEND NEW_LIST ${ITEM})
+ endif(FOUND_ITEM EQUAL -1)
+ endforeach(ITEM)
+ # replace the old list with the new list
+ set(${LIST} ${NEW_LIST})
+ endif(CMAKE26_OR_BETTER)
+endmacro(remove_list_duplicates)
# Search for the following programs
find_program(GREP grep)
@@ -178,7 +240,7 @@ set(DATADIR "${INSTDIR}/data")
# Only process Anope's version on Windows, it's needed for win32.rc as well as version branding at link time
if(WIN32)
# Find all lines in version.log that start with VERSION_
- file(STRINGS ${Anope_SOURCE_DIR}/version.log VERSIONS REGEX "^VERSION_")
+ read_from_file(${Anope_SOURCE_DIR}/version.log "^VERSION_" VERSIONS)
# Iterate through the strings found
foreach(VERSION_STR ${VERSIONS})
# Get the length of the string
@@ -222,9 +284,19 @@ set(ALL_HEADERS ${TMP_HEADERS})
list(SORT ALL_HEADERS)
# This function will take a #include line and extract the filename minus the quotes
-function(extract_include_filename INCLUDE FILENAME)
- # Strip away leading and trailing whitespace from the line
- string(STRIP ${INCLUDE} INCLUDE_STRIPPED)
+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, it should be at the end of the line after whitespace was stripped
string(REGEX MATCH "\".*\"$" FILE ${INCLUDE_STRIPPED})
# Get the length of the filename with quotes
@@ -234,14 +306,14 @@ function(extract_include_filename INCLUDE FILENAME)
# Overwrite the filename with a version sans quotes
string(SUBSTRING ${FILE} 1 ${FILENAME_LEN} FILE)
# Set the filename to the the given variable
- set(${FILENAME} "${FILE}" PARENT_SCOPE)
-endfunction(extract_include_filename)
+ set(${FILENAME} "${FILE}")
+endmacro(extract_include_filename)
# Preparse step 1: get filenames sans paths
# Iterate through the headers
foreach(HEADER ${ALL_HEADERS})
# Find all the lines in the current header that have any form of #include on them, regardless of whitespace
- file(STRINGS ${HEADER} INCLUDES REGEX "^[ \t]*#[ \t]*include[ \t]*\".*\"[ \t]*$")
+ read_from_file(${HEADER} "^[ \t]*#[ \t]*include[ \t]*\".*\"[ \t]*$" INCLUDES)
# Get the filename only of the header we just checked
get_filename_component(HEADER_FILENAME ${HEADER} NAME)
# Iterate through the strings containing #include (if any)
@@ -283,7 +355,7 @@ foreach(HEADER ${ALL_HEADERS})
set(NEW_HEADERS)
endwhile(HEADERS)
# OLD_HEADERS will now contain all headers that the current header relies on, remove duplicate headers from the list and sort the list
- list(REMOVE_DUPLICATES OLD_HEADERS)
+ remove_list_duplicates(OLD_HEADERS)
list(SORT OLD_HEADERS)
# Set the current header's list of headers to the cleaned up list from above
set(${HEADER_FILENAME}_HEADERS ${OLD_HEADERS})
@@ -297,9 +369,9 @@ set(sysconf.h_FULLPATH ${Anope_BINARY_DIR}/include/sysconf.h)
set(version.h_FULLPATH ${Anope_BINARY_DIR}/include/version.h)
# This function is used in most of the src (sub)directories to calculate the header file dependencies for the given source file
-function(calculate_depends SRC)
+macro(calculate_depends SRC)
# Find all the lines in the given source file that have any form of #include on them, regardless of whitespace
- file(STRINGS ${SRC} INCLUDES REGEX "^[ \t]*#[ \t]*include[ \t]*\".*\"[ \t]*$")
+ read_from_file(${SRC} "^[ \t]*#[ \t]*include[ \t]*\".*\"[ \t]*$" INCLUDES)
# Reset the list of headers to empty
set(HEADERS)
# Iterate through the strings containing #include (if any)
@@ -325,7 +397,7 @@ function(calculate_depends SRC)
# If after all the above there is a list of header, we'll process them, converting them to full paths
if(HEADERS)
# Remove duplicate headers from the list and sort the list
- list(REMOVE_DUPLICATES HEADERS)
+ remove_list_duplicates(HEADERS)
list(SORT HEADERS)
# Set the list of full path headers to empty
set(HEADERS_FULL)
@@ -337,7 +409,7 @@ function(calculate_depends SRC)
# Set the given source file to depend on the headers given
set_source_files_properties(${SRC} PROPERTIES OBJECT_DEPENDS "${HEADERS_FULL}")
endif(HEADERS)
-endfunction(calculate_depends)
+endmacro(calculate_depends)
# Go into the following directories and run their CMakeLists.txt as well
add_subdirectory(data)
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index cc0ffc614..121bc852a 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -4,7 +4,7 @@ if(MSVC OR NOT SH)
set_source_files_properties(version.sh.c PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
# Generate version_sh executable to create version.h from the contents of version.sh, setting it's linker flags as well
add_executable(version_sh version.sh.c)
- set_target_properties(version_sh PROPERTIES LINK_FLAGS "${LDFLAGS}")
+ set_target_properties(version_sh PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
# Generate version.h from the above executable and the version.log file from the main source directory, with dependencies to the given headers and all source files in the main Anope build
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
COMMAND version_sh ${Anope_SOURCE_DIR}/version.log ${CMAKE_CURRENT_SOURCE_DIR}/version.sh ${CMAKE_CURRENT_BINARY_DIR}/version.h
diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt
index 05e7becce..d38320d93 100644
--- a/lang/CMakeLists.txt
+++ b/lang/CMakeLists.txt
@@ -2,7 +2,7 @@
set_source_files_properties(langcomp.c PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
# Generate langcomp and set it's linker flags
add_executable(langcomp langcomp.c)
-set_target_properties(langcomp PROPERTIES LINK_FLAGS "${LDFLAGS}")
+set_target_properties(langcomp PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
# If grep or perl don't exist on the system, build langtool to generate index and language.h
if(NOT GREP OR NOT PERL)
@@ -10,7 +10,7 @@ if(NOT GREP OR NOT PERL)
set_source_files_properties(langtool.c PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
# Generate langtool and set it's linker flags
add_executable(langtool langtool.c)
- set_target_properties(langtool PROPERTIES LINK_FLAGS "${LDFLAGS}")
+ set_target_properties(langtool PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
endif(NOT GREP OR NOT PERL)
# If grep exists, use it to generate the index file
@@ -22,7 +22,7 @@ if(GREP)
# Otherwise, use langtool to generate the index file
else(GREP)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index
- COMMAND langtool index ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l ${CMAKE_CURRENT_BINARY_DIR}/index
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/langtool index ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l ${CMAKE_CURRENT_BINARY_DIR}/index
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l DEPENDS langtool
)
endif(GREP)
@@ -39,7 +39,7 @@ foreach(LANG_L ${LANG_SRCS})
list(APPEND LANGS ${CMAKE_CURRENT_BINARY_DIR}/${LANG})
# Generate a compiled language file using langcomp, as well as having a dependency on the index file being generated
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LANG}
- COMMAND langcomp ${CMAKE_CURRENT_SOURCE_DIR}/${LANG_L} ${CMAKE_CURRENT_BINARY_DIR}/${LANG}
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/langcomp ${CMAKE_CURRENT_SOURCE_DIR}/${LANG_L} ${CMAKE_CURRENT_BINARY_DIR}/${LANG}
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${LANG_L} DEPENDS langcomp ${CMAKE_CURRENT_BINARY_DIR}/index
)
endforeach(LANG_L)
@@ -53,7 +53,7 @@ if(NOT MSVC AND PERL)
# Otherwise, use langtool to generate language.h
else(NOT MSVC AND PERL)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/language.h
- COMMAND langtool language.h ${CMAKE_CURRENT_BINARY_DIR}/index ${CMAKE_CURRENT_BINARY_DIR}/language.h
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/langtool language.h ${CMAKE_CURRENT_BINARY_DIR}/index ${CMAKE_CURRENT_BINARY_DIR}/language.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/index DEPENDS langtool
)
endif(NOT MSVC AND PERL)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4872e46f2..8b072a55d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -39,7 +39,7 @@ endif(WIN32)
# 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
add_executable(${PROGRAM_NAME} ${SRC_SRCS})
-set_target_properties(${PROGRAM_NAME} PROPERTIES LINK_FLAGS "${LDFLAGS}" ENABLE_EXPORTS ON)
+set_target_properties(${PROGRAM_NAME} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}" ENABLE_EXPORTS ON)
# On Windows, also link Anope to the wsock32 library, as well as set the version
if(WIN32)
target_link_libraries(${PROGRAM_NAME} wsock32)
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 266b420d5..623f36f3e 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -19,7 +19,7 @@ foreach(SRC ${CORE_SRCS})
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})
- set_target_properties(${SO} PROPERTIES PREFIX "" SUFFIX "" LINK_FLAGS "${LDFLAGS}")
+ set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${LDFLAGS}")
add_dependencies(${SO} ${PROGRAM_NAME})
# For Windows only, have the module link to the export library of Anope as well as the wsock32 library (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)
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt
index 300d87050..f8acaab58 100644
--- a/src/modules/CMakeLists.txt
+++ b/src/modules/CMakeLists.txt
@@ -19,7 +19,7 @@ foreach(SRC ${MODULES_SRCS})
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})
- set_target_properties(${SO} PROPERTIES PREFIX "" SUFFIX "" LINK_FLAGS "${LDFLAGS}")
+ set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${LDFLAGS}")
add_dependencies(${SO} ${PROGRAM_NAME})
# For Windows only, have the module link to the export library of Anope as well as the wsock32 library (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)
diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt
index c384f7a31..71352d576 100644
--- a/src/protocol/CMakeLists.txt
+++ b/src/protocol/CMakeLists.txt
@@ -19,7 +19,7 @@ foreach(SRC ${PROTOCOL_SRCS})
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})
- set_target_properties(${SO} PROPERTIES PREFIX "" SUFFIX "" LINK_FLAGS "${LDFLAGS}")
+ set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${LDFLAGS}")
add_dependencies(${SO} ${PROGRAM_NAME})
# For Windows only, have the module link to the export library of Anope as well as the wsock32 library (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)
diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c
index 1b38286d5..d1df8220f 100644
--- a/src/protocol/inspircd11.c
+++ b/src/protocol/inspircd11.c
@@ -61,7 +61,7 @@
#endif
#ifdef _WIN32
-#include "winsock.h"
+#include <winsock.h>
int inet_aton(const char *name, struct in_addr *addr)
{
uint32 a = inet_addr(name);
diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp
index c7edecd82..bef8d113c 100644
--- a/src/protocol/inspircd12.cpp
+++ b/src/protocol/inspircd12.cpp
@@ -61,7 +61,7 @@
#endif
#ifdef _WIN32
-#include "winsock.h"
+#include <winsock.h>
int inet_aton(const char *name, struct in_addr *addr)
{
uint32 a = inet_addr(name);
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index 17d9b9282..96fa1c39c 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -15,7 +15,7 @@ foreach(SRC ${TOOLS_SRCS})
calculate_depends(${SRC})
# Generate the executable and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand
add_executable(${EXE} ${SRC})
- set_target_properties(${EXE} PROPERTIES LINK_FLAGS "${LDFLAGS}")
+ set_target_properties(${EXE} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
add_dependencies(${EXE} ${PROGRAM_NAME})
# Set the executable to be installed to the tools directory under the bin directory
install(TARGETS ${EXE}