diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..a97d014 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,34 @@ +################################################################ +# Name: CMakeLists.txt +# Purpose: Input file for CMake for the Scyther tool +# Author: Cas Cremers +################################################################ + +# Scyther project +project (Scyther) +# I need 2.4 for flex/etc although it does not run yet +#CMAKE_MINIMUM_REQUIRED(VERSION 2.4) + +# List all the source files +set (Scyther_sources + arachne.c binding.c claim.c color.c compiler.c cost.c + debug.c depend.c dotout.c error.c heuristic.c hidelevel.c + intruderknowledge.c knowledge.c label.c list.c main.c mgu.c + prune_bounds.c prune_theorems.c role.c + specialterm.c states.c switches.c symbol.c system.c tac.c + termlist.c termmap.c term.c timer.c type.c warshall.c xmlout.c + parser.c scanner.c + ) + +# If we are in a debug mode we want to be strict +set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -DDEBUG") + +# Determine version number +include (SVNVersion.cmake) + +# Make scanner and parser +include (ScannerParser.cmake) + +# Make the Scyther linux binary +add_executable (scyther-linux ${Scyther_sources}) + diff --git a/src/FindBISON.cmake b/src/FindBISON.cmake new file mode 100644 index 0000000..552ce0d --- /dev/null +++ b/src/FindBISON.cmake @@ -0,0 +1,32 @@ +# - Try to find Bison +# Once done this will define +# +# BISON_FOUND - system has Bison +# BISON_EXECUTABLE - path of the bison executable +# BISON_VERSION - the version string, like "2.5.31" +# + + +FIND_PROGRAM(BISON_EXECUTABLE NAMES bison) + +#INCLUDE(MacroEnsureVersion) + +IF(BISON_EXECUTABLE) + SET(BISON_FOUND TRUE) + + EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version + OUTPUT_VARIABLE _BISON_VERSION + ) + string (REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" BISON_VERSION "${_bison_VERSION}") +ENDIF(BISON_EXECUTABLE) + +IF(BISON_FOUND) + IF(NOT Bison_FIND_QUIETLY) + MESSAGE(STATUS "Found Bison: ${BISON_EXECUTABLE}") + ENDIF(NOT Bison_FIND_QUIETLY) +ELSE(BISON_FOUND) + IF(Bison_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Bison") + ENDIF(Bison_FIND_REQUIRED) +ENDIF(BISON_FOUND) + diff --git a/src/FindFLEX.cmake b/src/FindFLEX.cmake new file mode 100644 index 0000000..30285f1 --- /dev/null +++ b/src/FindFLEX.cmake @@ -0,0 +1,32 @@ +# - Try to find Flex +# Once done this will define +# +# FLEX_FOUND - system has Flex +# FLEX_EXECUTABLE - path of the flex executable +# FLEX_VERSION - the version string, like "2.5.31" +# + + +FIND_PROGRAM(FLEX_EXECUTABLE NAMES flex) + +#INCLUDE(MacroEnsureVersion) + +IF(FLEX_EXECUTABLE) + SET(FLEX_FOUND TRUE) + + EXECUTE_PROCESS(COMMAND ${FLEX_EXECUTABLE} --version + OUTPUT_VARIABLE _FLEX_VERSION + ) + string (REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" FLEX_VERSION "${_FLEX_VERSION}") +ENDIF(FLEX_EXECUTABLE) + +IF(FLEX_FOUND) + IF(NOT Flex_FIND_QUIETLY) + MESSAGE(STATUS "Found Flex: ${FLEX_EXECUTABLE}") + ENDIF(NOT Flex_FIND_QUIETLY) +ELSE(FLEX_FOUND) + IF(Flex_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Flex") + ENDIF(Flex_FIND_REQUIRED) +ENDIF(FLEX_FOUND) + diff --git a/src/SVNVersion.cmake b/src/SVNVersion.cmake new file mode 100644 index 0000000..1ddd45f --- /dev/null +++ b/src/SVNVersion.cmake @@ -0,0 +1,31 @@ +################################################################ +# Name: SVNVersion.cmake +# Purpose: Determine subversion revision id for Scyther +# and write it into a macro in version.h +# Author: Cas Cremers +################################################################ + +# TODO: Technically, this only needs to be redone each time a file +# changes, so this might be a target with dependencies on all files. + +# Checkout version info +set_source_files_properties(version.h + PROPERTIES + GENERATED true) +find_program (SVNVERSION_EXECUTABLE NAMES svnversion) +if (SVNVERSION_EXECUTABLE) + # svnversion found; we should always build this + message (STATUS "Generating version.h using svnversion command") + exec_program (${SVNVERSION_EXECUTABLE} + OUTPUT_VARIABLE SVN_Version + ) + message (STATUS "svnversion gave ${SVN_Version}") + file (WRITE version.h + "#define SVNVERSION \"${SVN_Version}\"\n" + ) +else (SVNVERSION_EXECUTABLE) + # No svnversion. what do we write then? just empty...? + message (STATUS "Generating empty version.h") + file (WRITE version.h "") +endif (SVNVERSION_EXECUTABLE) + diff --git a/src/ScannerParser.cmake b/src/ScannerParser.cmake new file mode 100644 index 0000000..e5dd107 --- /dev/null +++ b/src/ScannerParser.cmake @@ -0,0 +1,41 @@ +################################################################ +# Name: ScannerParser.cmake +# Purpose: If flex/bison are available, generate parser and scanner +# Author: Cas Cremers +################################################################ + +# Make the scanner using flex, if it can be found +include(FindFLEX.cmake) +if (FLEX_FOUND) + set_source_files_properties(scanner.c PROPERTIES GENERATED true) + ADD_CUSTOM_COMMAND ( + OUTPUT scanner.c + DEPENDS scanner.l + COMMAND ${FLEX_EXECUTABLE} + # TODO: I should look up from which version the -o + # switch works, might not be portable. + ARGS -o scanner.c scanner.l + COMMENT "Building scanner.c from scanner.l using flex" + ) +else (FLEX_FOUND) + message (STATUS "Because flex is not found, we will use the existing scanner.c") +endif (FLEX_FOUND) + +# Make the parser using bison, if it can be found +include(FindBISON.cmake) +if (BISON_FOUND) + set_source_files_properties(parser.c PROPERTIES GENERATED true) + ADD_CUSTOM_COMMAND ( + OUTPUT parser.c + DEPENDS parser.y + COMMAND ${BISON_EXECUTABLE} + # TODO: I should look up from which version the -o + # switch works, might not be portable. + ARGS -o parser.c parser.y + COMMENT "Building parser.c from parser.y using bison" + ) +else (BISON_FOUND) + message (STATUS "Because bison is not found, we will use the existing parser.c") +endif (BISON_FOUND) + +