Style/comment enhancements.

This commit is contained in:
Jon Siwek 2010-11-02 11:58:47 -05:00
parent b891379e06
commit 7eb92d6a2d
2 changed files with 64 additions and 45 deletions

View file

@ -1,12 +1,10 @@
## ########################################################################
## CMake Configuration ## CMake Configuration
##
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# Prohibit in-source builds. # Prohibit in-source builds.
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" source_build) if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
if (source_build)
message(FATAL_ERROR "In-source builds are not allowed. Please use " message(FATAL_ERROR "In-source builds are not allowed. Please use "
"./configure to choose a build directory and " "./configure to choose a build directory and "
"initialize the build configuration.") "initialize the build configuration.")
@ -28,12 +26,13 @@ include(${build_options_file})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
## ########################################################################
## Project Configuration ## Project/Build Configuration
##
project(Bro) project(Bro)
file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)
if (ENABLE_DEBUG AND ENABLE_RELEASE) if (ENABLE_DEBUG AND ENABLE_RELEASE)
set(CMAKE_BUILD_TYPE RelWithDebInfo) set(CMAKE_BUILD_TYPE RelWithDebInfo)
elseif (ENABLE_DEBUG AND NOT ENABLE_RELEASE) elseif (ENABLE_DEBUG AND NOT ENABLE_RELEASE)
@ -53,9 +52,8 @@ endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}")
## ########################################################################
## Dependency Configuration ## Dependency Configuration
##
# Check cache value first to avoid displaying "Found sed" messages everytime # Check cache value first to avoid displaying "Found sed" messages everytime
if (NOT SED_EXE) if (NOT SED_EXE)
@ -118,11 +116,8 @@ if (ENABLE_PERFTOOLS)
endif () endif ()
endif () endif ()
## ########################################################################
## Configuration Checks/Tests ## System Introspection
##
file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)
include(TestBigEndian) include(TestBigEndian)
test_big_endian(WORDS_BIGENDIAN) test_big_endian(WORDS_BIGENDIAN)
@ -141,9 +136,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
## ########################################################################
## Recurse on sub-directories ## Recurse on sub-directories
##
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(policy) add_subdirectory(policy)
@ -154,9 +148,8 @@ if (INSTALL_AUXTOOLS)
add_subdirectory(aux) add_subdirectory(aux)
endif () endif ()
## ########################################################################
## Packaging Setup ## Packaging Setup
##
include(SetPackageVersion) include(SetPackageVersion)
SetPackageVersion(${VERSION}) SetPackageVersion(${VERSION})
@ -198,9 +191,8 @@ endif ()
include(CPack) include(CPack)
## ########################################################################
## Build Summary ## Build Summary
##
if (CMAKE_BUILD_TYPE) if (CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} BuildType) string(TOUPPER ${CMAKE_BUILD_TYPE} BuildType)

View file

@ -2,18 +2,33 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
configure_file(version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c)
# This creates a custom command to transform a bison output file (inFile)
# into outFile in order to avoid symbol conflicts:
# - replaces instances of 'yylex' in inFile with yylexPrefix
# - replaces instances of 'yy' in inFile with yyPrefix
# - deletes instances of 'extern char.*getenv' in inFile
# - writes results to outFile and adds it to list TRANSFORMED_BISON_OUTPUTS
macro(REPLACE_YY_PREFIX_TARGET inFile outFile yylexPrefix yyPrefix) macro(REPLACE_YY_PREFIX_TARGET inFile outFile yylexPrefix yyPrefix)
set(args "'/extern char.*getenv/d\;s/yylex/${yylexPrefix}lex/\;s/yy/${yyPrefix}/g'" < ${inFile} > ${outFile}) set(args "'/extern char.*getenv/d")
set(args "${args}\;s/yylex/${yylexPrefix}lex/")
set(args "${args}\;s/yy/${yyPrefix}/g'" < ${inFile} > ${outFile})
add_custom_command(OUTPUT ${outFile} add_custom_command(OUTPUT ${outFile}
COMMAND ${SED_EXE} COMMAND ${SED_EXE}
ARGS ${args} ARGS ${args}
DEPENDS ${inFile} DEPENDS ${inFile}
COMMENT "[sed] replacing stuff in ${inFile}" COMMENT "[sed] replacing stuff in ${inFile}"
) )
list(APPEND TRANSFORMED_BISON_OUTPUTS ${outFile})
endmacro(REPLACE_YY_PREFIX_TARGET) endmacro(REPLACE_YY_PREFIX_TARGET)
########################################################################
## Create targets to generate parser and scanner code
set(BISON_FLAGS "--debug") set(BISON_FLAGS "--debug")
# BIF parser/scanner
bison_target(BIFParser builtin-func.y bison_target(BIFParser builtin-func.y
${CMAKE_CURRENT_BINARY_DIR}/bif_parse.cc ${CMAKE_CURRENT_BINARY_DIR}/bif_parse.cc
HEADER ${CMAKE_CURRENT_BINARY_DIR}/bif_parse.h HEADER ${CMAKE_CURRENT_BINARY_DIR}/bif_parse.h
@ -22,6 +37,7 @@ bison_target(BIFParser builtin-func.y
flex_target(BIFScanner builtin-func.l ${CMAKE_CURRENT_BINARY_DIR}/bif_lex.cc) flex_target(BIFScanner builtin-func.l ${CMAKE_CURRENT_BINARY_DIR}/bif_lex.cc)
add_flex_bison_dependency(BIFScanner BIFParser) add_flex_bison_dependency(BIFScanner BIFParser)
# Rule parser/scanner
bison_target(RuleParser rule-parse.y bison_target(RuleParser rule-parse.y
${CMAKE_CURRENT_BINARY_DIR}/rup.cc ${CMAKE_CURRENT_BINARY_DIR}/rup.cc
HEADER ${CMAKE_CURRENT_BINARY_DIR}/rup.h HEADER ${CMAKE_CURRENT_BINARY_DIR}/rup.h
@ -36,6 +52,7 @@ replace_yy_prefix_target(${CMAKE_CURRENT_BINARY_DIR}/rup.h
flex_target(RuleScanner rule-scan.l ${CMAKE_CURRENT_BINARY_DIR}/rule-scan.cc flex_target(RuleScanner rule-scan.l ${CMAKE_CURRENT_BINARY_DIR}/rule-scan.cc
COMPILE_FLAGS "-Prules_") COMPILE_FLAGS "-Prules_")
# RE parser/scanner
bison_target(REParser re-parse.y bison_target(REParser re-parse.y
${CMAKE_CURRENT_BINARY_DIR}/rep.cc ${CMAKE_CURRENT_BINARY_DIR}/rep.cc
HEADER ${CMAKE_CURRENT_BINARY_DIR}/re-parse.h HEADER ${CMAKE_CURRENT_BINARY_DIR}/re-parse.h
@ -48,6 +65,7 @@ flex_target(REScanner re-scan.l ${CMAKE_CURRENT_BINARY_DIR}/re-scan.cc
COMPILE_FLAGS "-Pre_") COMPILE_FLAGS "-Pre_")
add_flex_bison_dependency(REScanner REParser) add_flex_bison_dependency(REScanner REParser)
# Parser/Scanner
bison_target(Parser parse.y bison_target(Parser parse.y
${CMAKE_CURRENT_BINARY_DIR}/p.cc ${CMAKE_CURRENT_BINARY_DIR}/p.cc
HEADER ${CMAKE_CURRENT_BINARY_DIR}/broparse.h HEADER ${CMAKE_CURRENT_BINARY_DIR}/broparse.h
@ -56,13 +74,11 @@ bison_target(Parser parse.y
replace_yy_prefix_target(${CMAKE_CURRENT_BINARY_DIR}/p.cc replace_yy_prefix_target(${CMAKE_CURRENT_BINARY_DIR}/p.cc
${CMAKE_CURRENT_BINARY_DIR}/parse.cc ${CMAKE_CURRENT_BINARY_DIR}/parse.cc
bro yy) bro yy)
flex_target(Scanner scan.l ${CMAKE_CURRENT_BINARY_DIR}/scan.cc flex_target(Scanner scan.l ${CMAKE_CURRENT_BINARY_DIR}/scan.cc
COMPILE_FLAGS "-Pbro") COMPILE_FLAGS "-Pbro")
configure_file(version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c) ########################################################################
## bifcl (BIF compiler) target
########### bifcl target###############
set(bifcl_SRCS set(bifcl_SRCS
${BISON_BIFParser_OUTPUTS} ${BISON_BIFParser_OUTPUTS}
@ -74,6 +90,13 @@ add_executable(bifcl ${bifcl_SRCS})
target_link_libraries(bifcl) target_link_libraries(bifcl)
########################################################################
## bifcl-dependent targets
# A macro to define a command that uses the BIF compiler to produce
# C++ segments and Bro language declarations from .bif file
# The outputs are appended to list ALL_BIF_OUTPUTS
# Outputs that should be installed are appended to INSTALL_BIF_OUTPUTS
macro(BIF_TARGET bifInput) macro(BIF_TARGET bifInput)
get_bif_output_files(${bifInput} bifOutputs) get_bif_output_files(${bifInput} bifOutputs)
add_custom_command(OUTPUT ${bifOutputs} add_custom_command(OUTPUT ${bifOutputs}
@ -87,6 +110,8 @@ macro(BIF_TARGET bifInput)
${CMAKE_CURRENT_BINARY_DIR}/${bifInput}.bro) ${CMAKE_CURRENT_BINARY_DIR}/${bifInput}.bro)
endmacro(BIF_TARGET) endmacro(BIF_TARGET)
# returns a list of output files that bifcl will produce
# for given input file in ${outputFileVar}
macro(GET_BIF_OUTPUT_FILES inputFile outputFileVar) macro(GET_BIF_OUTPUT_FILES inputFile outputFileVar)
set(${outputFileVar} set(${outputFileVar}
${inputFile}.bro ${inputFile}.bro
@ -99,8 +124,6 @@ macro(GET_BIF_OUTPUT_FILES inputFile outputFileVar)
) )
endmacro(GET_BIF_OUTPUT_FILES) endmacro(GET_BIF_OUTPUT_FILES)
########## targets that needed bifcl ##########
set(BIF_SRCS set(BIF_SRCS
bro.bif bro.bif
event.bif event.bif
@ -120,7 +143,8 @@ foreach (bift ${BIF_SRCS})
bif_target(${bift}) bif_target(${bift})
endforeach () endforeach ()
########## targets that need binpac ########## ########################################################################
## BinPAC-dependent targets
set(BINPAC_AUXSRC set(BINPAC_AUXSRC
binpac.pac binpac.pac
@ -128,6 +152,9 @@ set(BINPAC_AUXSRC
binpac_bro.h binpac_bro.h
) )
# A macro to define a command that uses the BinPac compiler to
# produce C++ code that implements a protocol parser/analyzer
# The outputs of the command are appended to list ALL_BINPAC_OUTPUTS
macro(BINPAC_TARGET pacFile) macro(BINPAC_TARGET pacFile)
get_filename_component(basename ${pacFile} NAME_WE) get_filename_component(basename ${pacFile} NAME_WE)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.h add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.h
@ -173,17 +200,11 @@ binpac_target(ssl.pac
binpac_target(ssl-record-layer.pac binpac_target(ssl-record-layer.pac
ssl-defs.pac ssl.pac) ssl-defs.pac ssl.pac)
########### bro target ############### ########################################################################
## bro target
set(dns_SRCS nb_dns.c nb_dns.h)
set(openssl_SRCS X509.cc SSLCiphers.cc SSLInterpreter.cc SSLProxy.cc
SSLv2.cc SSLv3.cc SSLv3Automaton.cc)
if (USE_NMALLOC)
set(malloc_SRCS malloc.c)
endif ()
# define a command that's used to run the make_dbg_constants.pl script
# building the bro binary depends on the outputs of this script
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h
${CMAKE_CURRENT_BINARY_DIR}/DebugCmdInfoConstants.cc ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdInfoConstants.cc
COMMAND ${PERL_EXECUTABLE} COMMAND ${PERL_EXECUTABLE}
@ -195,16 +216,22 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
set(dns_SRCS nb_dns.c nb_dns.h)
set(openssl_SRCS X509.cc SSLCiphers.cc SSLInterpreter.cc SSLProxy.cc
SSLv2.cc SSLv3.cc SSLv3Automaton.cc)
if (USE_NMALLOC)
set(malloc_SRCS malloc.c)
endif ()
set(bro_SRCS set(bro_SRCS
${CMAKE_CURRENT_BINARY_DIR}/version.c
${ALL_BIF_OUTPUTS} ${ALL_BIF_OUTPUTS}
${ALL_BINPAC_OUTPUTS} ${ALL_BINPAC_OUTPUTS}
${CMAKE_CURRENT_BINARY_DIR}/version.c ${TRANSFORMED_BISON_OUTPUTS}
rule-parse.cc
rule-parse.h
${FLEX_RuleScanner_OUTPUTS} ${FLEX_RuleScanner_OUTPUTS}
re-parse.cc
${FLEX_REScanner_OUTPUTS} ${FLEX_REScanner_OUTPUTS}
parse.cc
${FLEX_Scanner_OUTPUTS} ${FLEX_Scanner_OUTPUTS}
${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h
main.cc main.cc