Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
209 additions
and 4 deletions.
- +3 −0 .gitmodules
- +5 −2 .travis.yml
- +13 −0 CMakeLists.txt
- +28 −0 cmake/Modules/scxmlcc_generator.cmake
- +38 −0 src/CMakeLists.txt
- +47 −0 src/examples/CMakeLists.txt
- +45 −0 src/test/CMakeLists.txt
- +1 −0 src/test/gtest
- +2 −2 src/test/makefile
- +27 −0 src/version_git.cpp
@@ -0,0 +1,3 @@ | ||
[submodule "src/test/gtest"] | ||
path = src/test/gtest | ||
url = https://github.com/google/googletest.git |
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
|
||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules ) | ||
add_subdirectory(src) | ||
|
||
# prevent the examples and tests libs installing | ||
macro(install) | ||
endmacro() | ||
|
||
add_subdirectory(src/examples) | ||
|
||
enable_testing() | ||
add_subdirectory(src/test) |
@@ -0,0 +1,28 @@ | ||
function (scxmlcc_generator filename gen-list ) | ||
|
||
# if we didn't compile the scxmlcc, then go find it in the system | ||
if ( TARGET scxmlcc ) | ||
set(SCC scxmlcc ) | ||
else() | ||
find_program( SCC scxmlcc ) | ||
endif() | ||
|
||
get_filename_component(ext ${filename} EXT) | ||
if(NOT ext STREQUAL ".scxml") | ||
message("skipping ${filename}") | ||
return() | ||
endif() | ||
|
||
get_filename_component(base ${filename} NAME_WE) | ||
set(output ${CMAKE_CURRENT_BINARY_DIR}/${base}.h) | ||
|
||
set_source_files_properties(${output} PROPERTIES GENERATED TRUE) | ||
set(${gen-list} ${${gen-list}} ${output} PARENT_SCOPE) | ||
|
||
add_custom_command( | ||
OUTPUT ${output} | ||
COMMAND ${SCC} -i ${filename} -o ${output} | ||
DEPENDS ${filename} | ||
) | ||
|
||
endfunction() |
@@ -0,0 +1,38 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
project( scxmlcc ) | ||
|
||
find_package (Boost REQUIRED COMPONENTS filesystem system program_options ) | ||
|
||
add_executable( ${PROJECT_NAME} | ||
cpp_output.cpp | ||
main.cpp | ||
scxml_parser.cpp | ||
version_git.cpp | ||
) | ||
|
||
target_include_directories( ${PROJECT_NAME} PRIVATE | ||
${CMAKE_BINARY_DIR} | ||
${Boost_INCLUDE_DIR} ) | ||
|
||
target_link_libraries( ${PROJECT_NAME} PRIVATE | ||
${Boost_LIBRARIES} ) | ||
|
||
set_property(TARGET ${PROJECT_NAME} | ||
PROPERTY CXX_STANDARD 11) | ||
|
||
install(TARGETS ${PROJECT_NAME} | ||
DESTINATION bin) | ||
|
||
install(FILES ${CMAKE_SOURCE_DIR}/cmake/Modules/scxmlcc_generator.cmake | ||
DESTINATION share/cmake/Modules ) | ||
|
||
# create version header file | ||
find_package(Git) | ||
execute_process( | ||
COMMAND git describe --first-parent --tags | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_DESCRIBE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
FILE(WRITE ${CMAKE_BINARY_DIR}/gitversion.h "\#define GITVERSION \"${GIT_DESCRIBE}\"\n") | ||
|
@@ -0,0 +1,47 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
|
||
include( scxmlcc_generator ) | ||
|
||
set( CMAKE_INCLUDE_CURRENT_DIR ON ) | ||
|
||
set(S ${CMAKE_CURRENT_SOURCE_DIR} ) | ||
scxmlcc_generator( ${S}/hello_world.scxml hello_gen_src ) | ||
scxmlcc_generator( ${S}/timer_switch.scxml timer_gen_src ) | ||
scxmlcc_generator( ${S}/microwave-01-cplusplus.scxml microwave_gen_src ) | ||
scxmlcc_generator( ${S}/vending_machine/vending_machine.scxml vending_gen_src ) | ||
|
||
set (CMAKE_CXX_STANDARD 11) | ||
|
||
add_executable( hello_world | ||
hello_world.cpp | ||
${hello_gen_src} | ||
) | ||
|
||
add_executable( timer_switch | ||
timer_switch.cpp | ||
${timer_gen_src} | ||
) | ||
|
||
add_executable( microwave | ||
microwave.cpp | ||
${microwave_gen_src} | ||
) | ||
|
||
add_executable( vending_machine | ||
vending_machine/coin_refund.cpp | ||
vending_machine/coin_refund.h | ||
vending_machine/coin_sensor.cpp | ||
vending_machine/coin_sensor.h | ||
vending_machine/dispenser.cpp | ||
vending_machine/dispenser.h | ||
vending_machine/display.cpp | ||
vending_machine/display.h | ||
vending_machine/input.cpp | ||
vending_machine/input.h | ||
vending_machine/keypad.cpp | ||
vending_machine/keypad.h | ||
vending_machine/machine.h | ||
vending_machine/main.cpp | ||
vending_machine/signal.h | ||
${vending_gen_src} | ||
) |
@@ -0,0 +1,45 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
|
||
project(tests) | ||
|
||
# setup gtest | ||
add_subdirectory(gtest) | ||
enable_testing() | ||
|
||
set( CMAKE_INCLUDE_CURRENT_DIR ON ) | ||
set( CMAKE_CXX_STANDARD 11 ) | ||
|
||
#generate txml->scxml->headers | ||
include( scxmlcc_generator ) | ||
file(GLOB txmls "test*.txml") | ||
find_program( XSLT xsltproc ) | ||
foreach(file ${txmls}) | ||
get_filename_component(base ${file} NAME_WE) | ||
set(output ${CMAKE_CURRENT_BINARY_DIR}/${base}.scxml) | ||
add_custom_command( | ||
OUTPUT ${output} | ||
COMMAND ${XSLT} ${CMAKE_CURRENT_LIST_DIR}/cpp.xsl ${file} > ${output} | ||
DEPENDS ${file} | ||
) | ||
scxmlcc_generator( ${output} gen_src ) | ||
endforeach() | ||
|
||
#generate scxml->headers | ||
scxmlcc_generator( ${CMAKE_CURRENT_SOURCE_DIR}/event_list.scxml gen_src ) | ||
scxmlcc_generator( ${CMAKE_CURRENT_SOURCE_DIR}/event_tokens.scxml gen_src ) | ||
scxmlcc_generator( ${CMAKE_CURRENT_SOURCE_DIR}/conditional.scxml gen_src ) | ||
|
||
add_executable( test_scxml | ||
${gen_src} | ||
test.cpp | ||
test_t.cpp | ||
) | ||
|
||
# includes and libs | ||
target_link_libraries( test_scxml gtest gtest_main ) | ||
target_include_directories( test_scxml PRIVATE | ||
${gtest_SOURCE_DIR}/include | ||
${gtest_SOURCE_DIR} | ||
) | ||
|
||
add_test(txml_tests test_scxml) |
@@ -0,0 +1,27 @@ | ||
/************************************************************************* | ||
** Copyright (C) 2013 Jan Pedersen <jp@jp-embedded.com> | ||
** | ||
** This program is free software: you can redistribute it and/or modify | ||
** it under the terms of the GNU General Public License as published by | ||
** the Free Software Foundation, either version 3 of the License, or | ||
** (at your option) any later version. | ||
** | ||
** This program is distributed in the hope that it will be useful, | ||
** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
** GNU General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License | ||
** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*************************************************************************/ | ||
|
||
#include "version.h" | ||
#include "gitversion.h" | ||
|
||
static const char _version[] = GITVERSION ; | ||
|
||
const char* version() | ||
{ | ||
return _version; | ||
} | ||
|