summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-14 20:17:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-14 20:17:15 +0100
commit8e86e00a861468ed8b12b1370a04f04548f24343 (patch)
tree55b8618db855373c90db92e3e17437589a2fdffa
parentfd70a499d4364d622ab47092703f3bfaa72a149f (diff)
downloadrspamd-8e86e00a861468ed8b12b1370a04f04548f24343.tar.gz
rspamd-8e86e00a861468ed8b12b1370a04f04548f24343.zip
[Rework] Compile ragel sources when building rspamd
-rw-r--r--CMakeLists.txt11
-rw-r--r--FindRagel.cmake109
2 files changed, 119 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62711ca4f..ebef8a1ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,11 @@ OPTION(ENABLE_JEMALLOC "Build rspamd with jemalloc allocator [default: OFF]
INCLUDE(FindArch.cmake)
TARGET_ARCHITECTURE(ARCH)
+INCLUDE(FindRagel.cmake)
+IF(NOT RAGEL_FOUND)
+ MESSAGE(FATAL_ERROR "Ragel is required to build rspamd")
+ENDIF()
+
IF ("${ARCH}" STREQUAL "x86_64")
IF (ENABLE_HYPERSCAN MATCHES "ON")
ENABLE_LANGUAGE(CXX)
@@ -724,10 +729,11 @@ CHECK_C_COMPILER_FLAG(-Wunused-variable SUPPORT_WUNUSED_VAR)
CHECK_C_COMPILER_FLAG(-Wno-pointer-sign SUPPORT_WPOINTER_SIGN)
CHECK_C_COMPILER_FLAG(-Wstrict-prototypes SUPPORT_WSTRICT_PROTOTYPES)
CHECK_C_COMPILER_FLAG(-pedantic SUPPORT_PEDANTIC_FLAG)
+CHECK_C_COMPILER_FLAG(-pedantic SUPPORT_PEDANTIC_FLAG)
# GCC 6 specific
CHECK_C_COMPILER_FLAG(-Wnull-dereference SUPPORT_WNULL_DEREFERENCE)
CHECK_C_COMPILER_FLAG(-Wduplicated-cond SUPPORT_WDUPLICATED_COND)
-CHECK_C_COMPILER_FLAG(-Wlogical-op SUPPORT_WLOGICAL_OP)
+CHECK_C_COMPILER_FLAG(-Wno-unused-const-variable SUPPORT_WNO_UNUSED_CONST)
IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
CHECK_C_COMPILER_FLAG("-std=c11" SUPPORT_STD11_FLAG)
CHECK_C_COMPILER_FLAG("-std=c99" SUPPORT_STD99_FLAG)
@@ -768,6 +774,9 @@ ENDIF()
IF(SUPPORT_WLOGICAL_OP)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wlogical-op")
ENDIF()
+IF(SUPPORT_WNO_UNUSED_CONST)
+ SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wunused-const-variable")
+ENDIF()
IF(SUPPORT_STD11_FLAG)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -std=c11")
ELSE(SUPPORT_STD11_FLAG)
diff --git a/FindRagel.cmake b/FindRagel.cmake
new file mode 100644
index 000000000..7b4534a80
--- /dev/null
+++ b/FindRagel.cmake
@@ -0,0 +1,109 @@
+# - Find Ragel executable and provides macros to generate custom build rules
+# The module defines the following variables:
+#
+# RAGEL_EXECUTABLE - path to the ragel program
+# RAGEL_VERSION - version of ragel
+# RAGEL_FOUND - true if the program was found
+#
+# If ragel is found, the module defines the macros:
+#
+# RAGEL_TARGET(<Name> <RagelInp> <CodeOutput>
+# [COMPILE_FLAGS <string>])
+#
+# which will create a custom rule to generate a state machine. <RagelInp> is
+# the path to a Ragel file. <CodeOutput> is the name of the source file
+# generated by ragel. If COMPILE_FLAGS option is specified, the next
+# parameter is added in the ragel command line.
+#
+# The macro defines a set of variables:
+# RAGEL_${Name}_DEFINED - true is the macro ran successfully
+# RAGEL_${Name}_INPUT - The input source file, an alias for <RagelInp>
+# RAGEL_${Name}_OUTPUT_SOURCE - The source file generated by ragel
+# RAGEL_${Name}_OUTPUT_HEADER - The header file generated by ragel
+# RAGEL_${Name}_OUTPUTS - The sources files generated by ragel
+# RAGEL_${Name}_COMPILE_FLAGS - Options used in the ragel command line
+#
+# ====================================================================
+# Example:
+#
+# find_package(RAGEL) # or e.g.: find_package(RAGEL 6.6 REQUIRED)
+# RAGEL_TARGET(MyMachine machine.rl ${CMAKE_CURRENT_BINARY_DIR}/machine.cc)
+# add_executable(Foo main.cc ${RAGEL_MyMachine_OUTPUTS})
+# ====================================================================
+
+# 2014-02-09, Georg Sauthoff <mail@georg.so>
+#
+# I don't think that these few lines are even copyrightable material,
+# but I am fine with using the BSD/MIT/GPL license on it ...
+#
+# I've used following references:
+# http://www.cmake.org/cmake/help/v2.8.12/cmake.html
+# /usr/share/cmake/Modules/FindFLEX.cmake
+# /usr/share/cmake/Modules/FindBISON.cmake
+
+# uses some features which are not available in 2.6
+cmake_minimum_required(VERSION 2.8)
+
+find_program(RAGEL_EXECUTABLE NAMES ragel DOC "path to the ragel executable")
+mark_as_advanced(RAGEL_EXECUTABLE)
+
+if(RAGEL_EXECUTABLE)
+
+ execute_process(COMMAND ${RAGEL_EXECUTABLE} --version
+ OUTPUT_VARIABLE RAGEL_version_output
+ ERROR_VARIABLE RAGEL_version_error
+ RESULT_VARIABLE RAGEL_version_result
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(${RAGEL_version_result} EQUAL 0)
+ string(REGEX REPLACE "^Ragel State Machine Compiler version ([^ ]+) .*$"
+ "\\1"
+ RAGEL_VERSION "${RAGEL_version_output}")
+ else()
+ message(SEND_ERROR
+ "Command \"${RAGEL_EXECUTABLE} --version\" failed with output:
+${RAGEL_version_error}")
+ endif()
+
+ #============================================================
+ # RAGEL_TARGET (public macro)
+ #============================================================
+ #
+ macro(RAGEL_TARGET Name Input Output)
+ set(RAGEL_TARGET_usage
+ "RAGEL_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
+ if(${ARGC} GREATER 3)
+ if(${ARGC} EQUAL 5)
+ if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
+ set(RAGEL_EXECUTABLE_opts "${ARGV4}")
+ separate_arguments(RAGEL_EXECUTABLE_opts)
+ else()
+ message(SEND_ERROR ${RAGEL_TARGET_usage})
+ endif()
+ else()
+ message(SEND_ERROR ${RAGEL_TARGET_usage})
+ endif()
+ endif()
+
+ add_custom_command(OUTPUT ${Output}
+ COMMAND ${RAGEL_EXECUTABLE}
+ ARGS ${RAGEL_EXECUTABLE_opts} -o${Output} ${Input}
+ DEPENDS ${Input}
+ COMMENT
+ "[RAGEL][${Name}] Compiling state machine with Ragel ${RAGEL_VERSION}"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+ set(RAGEL_${Name}_DEFINED TRUE)
+ set(RAGEL_${Name}_OUTPUTS ${Output})
+ set(RAGEL_${Name}_INPUT ${Input})
+ set(RAGEL_${Name}_COMPILE_FLAGS ${RAGEL_EXECUTABLE_opts})
+ endmacro()
+
+endif()
+
+# use this include when module file is located under /usr/share/cmake/Modules
+#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+# use this include when module file is located in build tree
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(RAGEL REQUIRED_VARS RAGEL_EXECUTABLE
+ VERSION_VAR RAGEL_VERSION) \ No newline at end of file