From 8c8dfe0e2ab3679ca37f3dec2c91ef56976a2b33 Mon Sep 17 00:00:00 2001 From: Roland Wolf Date: Wed, 27 Apr 2016 14:36:08 +0200 Subject: [PATCH 1/2] Added support for IDE's and shadow builds Using CMake instead of plain make allows for using shadow builds and provides integration with many IDE's like Qt Creator, Eclipse Visual Studio etc. --- CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ lexer.rl | 7 +------ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..be4c2d0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 2.8) +PROJECT(simplecalc) + + +# copy parser.y to build directory. We want a shaddow build that does not litter +# the source directory +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/parser.y + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/parser.y ${CMAKE_BINARY_DIR}/parser.y + DEPENDS ${CMAKE_SOURCE_DIR}/parser.y) + +# run lemon +add_custom_target(parser + #OUTPUT ${CMAKE_BINARY_DIR}/parser.c OUTPUT ${CMAKE_BINARY_DIR}/parser.c + COMMAND lemon ${CMAKE_BINARY_DIR}/parser.y + DEPENDS ${CMAKE_BINARY_DIR}/parser.y + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) + +# run ragel +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/lexer.cpp + COMMAND ragel ${CMAKE_SOURCE_DIR}/lexer.rl -o ${CMAKE_BINARY_DIR}/lexer.cpp +) + + +# build executable +add_executable(calc ${CMAKE_BINARY_DIR}/lexer.cpp) + +add_dependencies(calc parser ) diff --git a/lexer.rl b/lexer.rl index f1413b8..ee19601 100644 --- a/lexer.rl +++ b/lexer.rl @@ -6,11 +6,6 @@ #include #include "parser.c" -std::string getStr(const char* beg, const char* end) -{ - return std::string(beg).substr(0, end-beg); -} - %%{ @@ -46,7 +41,7 @@ action closep_tok { } action number_tok{ - Parse(lparser, DOUBLE, atof(getStr(ts, te).c_str())); + Parse(lparser, DOUBLE, atof(std::string(ts, te).c_str())); } number = [0-9]+('.'[0-9]+)?; From 76877018f6925b1842556af893671bc30fa20db0 Mon Sep 17 00:00:00 2001 From: Roland Wolf Date: Thu, 28 Apr 2016 23:04:14 +0200 Subject: [PATCH 2/2] Added dependency and improved IDE integration --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be4c2d0..7fe4d58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ add_custom_command( # run lemon add_custom_target(parser - #OUTPUT ${CMAKE_BINARY_DIR}/parser.c OUTPUT ${CMAKE_BINARY_DIR}/parser.c COMMAND lemon ${CMAKE_BINARY_DIR}/parser.y DEPENDS ${CMAKE_BINARY_DIR}/parser.y WORKING_DIRECTORY ${CMAKE_BINARY_DIR} @@ -21,8 +20,13 @@ add_custom_target(parser add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/lexer.cpp COMMAND ragel ${CMAKE_SOURCE_DIR}/lexer.rl -o ${CMAKE_BINARY_DIR}/lexer.cpp + DEPENDS ${CMAKE_SOURCE_DIR}/lexer.rl ) +add_custom_target(IDE SOURCES + parser.y + lexer.rl + ) # build executable add_executable(calc ${CMAKE_BINARY_DIR}/lexer.cpp)