Skip to content

Commit

Permalink
Merge pull request #353 from wdigger/cmake
Browse files Browse the repository at this point in the history
Changed: cpp linting with cmake
  • Loading branch information
wdigger committed Aug 18, 2017
2 parents 1941808 + 5091131 commit 2b978b9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
9 changes: 1 addition & 8 deletions .travis.yml
Expand Up @@ -57,18 +57,11 @@ install:
make -j5 && make install)
fi
- |
cd $BUID_DIR
git clone https://github.com/google/styleguide.git ./styleguide
- export CPPLINT_PATH="$PWD/styleguide/cpplint"

script:
- |
cd $TRAVIS_BUILD_DIR
$CPPLINT_PATH/cpplint.py ./src/*.cc ./src/*.h ./tests/*.cc
- |
cd $BUID_DIR
cmake $TRAVIS_BUILD_DIR
make check_style
make
make test
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then make package; else make package_source; fi
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -82,6 +82,9 @@ else()
find_package(XMP)
endif()

include(CppLint)
enable_check_style()

add_subdirectory(src)
if(ENABLE_TESTS)
add_subdirectory(tests)
Expand Down
10 changes: 8 additions & 2 deletions HACKING.md
Expand Up @@ -28,8 +28,14 @@ Dependencies
Coding style
------------

For the C++ code we are following the Google C++ Style Guide
<https://google-styleguide.googlecode.com/svn/trunk/cppguide.html>.
For the C++ code we are following the [Google C++ Style Guide](https://google-styleguide.googlecode.com/svn/trunk/cppguide.html).

You can check style during the build

``` shell
$ make check_style
```


Creating a pull request
-----------------------
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -66,6 +66,7 @@ install:
build_script:
- cmd: cmake -G "NMake Makefiles"
- cmd: nmake check_style
- cmd: nmake
- cmd: nmake test
- cmd: nmake package
Expand Down
35 changes: 35 additions & 0 deletions cmake/CppLint.cmake
@@ -0,0 +1,35 @@
find_package(PythonInterp)

if(PYTHONINTERP_FOUND AND NOT CPPLINT_FOUND)
file(DOWNLOAD "https://github.com/google/styleguide/archive/gh-pages.zip" "${CMAKE_CURRENT_BINARY_DIR}/styleguide.zip")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz styleguide.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set(CPPLINT_COMMAND "${CMAKE_CURRENT_BINARY_DIR}/styleguide-gh-pages/cpplint/cpplint.py" CACHE FILEPATH "CppLint commad")
set(CPPLINT_FOUND ON CACHE BOOL "CppLint found")
endif()

function(enable_check_style)
if(CPPLINT_FOUND)
add_custom_target(check_style)
endif()
endfunction()

function(target_check_style TARGET)
if(CPPLINT_FOUND)
get_target_property(TARGET_SOURCES ${TARGET} SOURCES)

set(TARGET_NAME "check_style_${TARGET}")

set(SOURCES_LIST)
foreach(sourcefile ${TARGET_SOURCES})
if(sourcefile MATCHES \\.c$|\\.cxx$|\\.cpp$|\\.cc$|\\.h$|\\.hh$)
list(APPEND SOURCES_LIST ${sourcefile})
endif()
endforeach(sourcefile)

add_custom_target(${TARGET_NAME} ${PYTHON_EXECUTABLE} ${CPPLINT_COMMAND} ${SOURCES_LIST}
DEPENDS ${SOURCES_LIST}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(check_style ${TARGET_NAME})
endif()
endfunction()
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -76,7 +76,6 @@ set(OTHER_HEADERS data.h
misc.h
freeserf_endian.h
version.h
version-vcs.h
data-source-dos.h
data-source-amiga.h
tpwm.h
Expand Down Expand Up @@ -116,6 +115,7 @@ endif()
set(FREESERF_SOURCES freeserf.cc ${OTHER_SOURCES})
set(FREESERF_HEADERS freeserf.h ${OTHER_HEADERS})
add_executable(FreeSerf MACOSX_BUNDLE WIN32 ${FREESERF_SOURCES} ${FREESERF_HEADERS})
target_check_style(FreeSerf)
target_link_libraries(FreeSerf game)
if(SDL2_FOUND)
target_link_libraries(FreeSerf ${SDL2_LIBRARY})
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Expand Up @@ -6,16 +6,19 @@ endif()

set(TEST_MAP_SOURCES ../tests/test_map.cc)
add_executable(test_map ${TEST_MAP_SOURCES})
target_check_style(test_map)
target_link_libraries(test_map game)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/map-memdump-1 ${CMAKE_CURRENT_BINARY_DIR}/tests/data/map-memdump-1 COPYONLY)
add_test(NAME test_map COMMAND test_map WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set(TEST_SAVE_GAME_SOURCES ../tests/test_save_game.cc)
add_executable(test_save_game ${TEST_SAVE_GAME_SOURCES})
target_check_style(test_save_game)
target_link_libraries(test_save_game game)
add_test(test_save_game test_save_game)

set(TEST_MAP_GEOMETRY_SOURCES ../tests/test_map_geometry.cc)
add_executable(test_map_geometry ${TEST_MAP_GEOMETRY_SOURCES})
target_check_style(test_map_geometry)
target_link_libraries(test_map_geometry game)
add_test(test_map_geometry test_map_geometry)

0 comments on commit 2b978b9

Please sign in to comment.