Skip to content

Commit

Permalink
Add cmake DEVELOPER option for building tests and examples
Browse files Browse the repository at this point in the history
Fetching gtest with git submodules was causing confusing so this is now
done with cmake during the configure step
  • Loading branch information
aboseley committed Nov 14, 2018
1 parent f426ea2 commit 7b0d2fb
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -29,4 +29,5 @@ compiler:
jobs: jobs:
include: include:
- script: make -C src && make -C src/examples && make -C src/test && ./src/test/test - script: make -C src && make -C src/examples && make -C src/test && ./src/test/test
- script: mkdir build && cd build && cmake .. && make -j4 && ctest -V - script: mkdir build && cd build && cmake .. && make -j4
- script: mkdir build-dev && cd build-dev && cmake -DDEVELOPER=1 .. && make -j4 && ctest -V
15 changes: 6 additions & 9 deletions CMakeLists.txt
@@ -1,13 +1,10 @@
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules )
add_subdirectory(src)


# prevent the examples and tests libs installing add_subdirectory(src)
macro(install)
endmacro()

add_subdirectory(src/examples)


enable_testing() if( DEFINED DEVELOPER )
add_subdirectory(src/test) add_subdirectory(src/examples)
enable_testing()
add_subdirectory(src/test)
endif( DEFINED DEVELOPER )
11 changes: 10 additions & 1 deletion doc/getting-started.md
Expand Up @@ -50,17 +50,26 @@ make
``` ```
#### with cmake #### with cmake
``` ```
git submodule update --init
mkdir build mkdir build
cd build cd build
cmake .. cmake ..
make -j4 make -j4
make install make install
``` ```

If you're not familar with cmake have a look at the supported generators for visual studio, eclipse etc- https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html. If you're not familar with cmake have a look at the supported generators for visual studio, eclipse etc- https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html.


To help with auto-generating state-machines in cmake projects, an scxml_generator.cmake module is installed. The examples demonstrate how this can be used. To help with auto-generating state-machines in cmake projects, an scxml_generator.cmake module is installed. The examples demonstrate how this can be used.


To build unit tests, and examples run cmake with
```
mkdir build
cd build
cmake -DDEVELOPER=1 ..
make -j4
make test
```

### On Windows ### On Windows
The solution file `scxmlcc\src\vc2013\vc2013.sln` contain projects to build the scxml compiler and examples. This is for visual studio 2013. The solution file `scxmlcc\src\vc2013\vc2013.sln` contain projects to build the scxml compiler and examples. This is for visual studio 2013.


Expand Down
47 changes: 37 additions & 10 deletions src/test/CMakeLists.txt
Expand Up @@ -2,14 +2,44 @@ cmake_minimum_required(VERSION 2.8.11)


project(tests) project(tests)


# setup gtest ############################################
add_subdirectory(gtest) # per gtest instructions for cmake inclusion
enable_testing() # https://github.com/google/googletest/blob/master/googletest/README.md

configure_file(gtest.cmake.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()

execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)


set( CMAKE_INCLUDE_CURRENT_DIR ON ) set( CMAKE_INCLUDE_CURRENT_DIR ON )
set( CMAKE_CXX_STANDARD 11 ) set( CMAKE_CXX_STANDARD 11 )


#generate txml->scxml->headers
############################################
# Setup scxml tests
#
# generate txml->scxml->headers

include( scxmlcc_generator ) include( scxmlcc_generator )
file(GLOB txmls "test*.txml") file(GLOB txmls "test*.txml")
find_program( XSLT xsltproc ) find_program( XSLT xsltproc )
Expand Down Expand Up @@ -39,11 +69,8 @@ add_executable( test_scxml
test_t.cpp test_t.cpp
) )


# includes and libs target_link_libraries(test_scxml
target_link_libraries( test_scxml gtest gtest_main ) gtest_main
target_include_directories( test_scxml PRIVATE
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR}
) )


add_test(txml_tests test_scxml) add_test(scxml_tests test_scxml)
1 change: 0 additions & 1 deletion src/test/gtest
Submodule gtest deleted from 278aba
15 changes: 15 additions & 0 deletions src/test/gtest.cmake.in
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8.2)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

0 comments on commit 7b0d2fb

Please sign in to comment.