diff --git a/CMakeLists.txt b/CMakeLists.txt index a9364a5497366799213dd0d1d5085d8b7cf65d19..639dee25c0bb5de460a9d36f90ff1d6a63cfdadc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ option(BUILD_DOCS "Uses doxygen to build the documentaion" OFF) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/) +# format sources include(astyle) include(testing_cpp) diff --git a/CMakeModules/astyle.cmake b/CMakeModules/astyle.cmake index a6ad6663b839ea51c33067ec5f171a1295940b92..abb7dc9be5969c8e1d938b1dea4f7db742db45ba 100644 --- a/CMakeModules/astyle.cmake +++ b/CMakeModules/astyle.cmake @@ -1,14 +1,19 @@ -function(astyle target source_files) - find_program(ASTYLE_EXECUTABLE astyle) - if(ASTYLE_EXECUTABLE) - message(STATUS "Found astyle, using astyle to format code of target ${target}.") - add_custom_command( - TARGET ${target} PRE_BUILD - COMMAND - ${ASTYLE_EXECUTABLE} -n --style=1tbs --indent-namespaces --indent-preproc-block ${source_files} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} VERBATIM +find_program(ASTYLE_EXECUTABLE astyle) + +add_custom_target(ASTYLE) + +if(ASTYLE_EXECUTABLE) + message(STATUS "Found astyle, using astyle to format code of target ${target}.") + add_custom_target(astyle ALL + COMMAND + ${ASTYLE_EXECUTABLE} -i + --exclude=${PROJECT_BINARY_DIR} + --recursive -n --style=google + "${PROJECT_SOURCE_DIR}/*.cpp" "${PROJECT_SOURCE_DIR}/*.h" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + VERBATIM ) - else() - message(WARNING "Unable to find astyle. Skipping code formatting for ${target}") - endif() -endfunction() +else() + message(WARNING "Unable to find astyle. Code formatting willbe skipped") +endif() + diff --git a/CMakeModules/testing_cpp.cmake b/CMakeModules/testing_cpp.cmake index e476ee067a02742b6668e522e310e405d186078e..eeec49167f8cb15d66c141d4f039343f1309d482 100644 --- a/CMakeModules/testing_cpp.cmake +++ b/CMakeModules/testing_cpp.cmake @@ -12,8 +12,6 @@ function(gtest target test_source_files test_libraries) target_link_libraries(test-${target} ${test_libraries}) add_test(NAME test-${target} COMMAND test-${target}) - astyle(test-${target} ${test_source_files}) - message(STATUS "Added test 'test-${target}'") if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/common/cpp/CMakeLists.txt b/common/cpp/CMakeLists.txt index a291827b85b884bf763fa08cb2792aca238d30e4..8a24c3accfb2236713ced19c03304653d9ab1a72 100644 --- a/common/cpp/CMakeLists.txt +++ b/common/cpp/CMakeLists.txt @@ -9,9 +9,6 @@ add_library(${TARGET_NAME} SHARED ${SOURCE_FILES}) target_include_directories(${TARGET_NAME} PUBLIC include) set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) -astyle(${TARGET_NAME} ${SOURCE_FILES}) - - ################################ # Testing ################################ diff --git a/producer/api/CMakeLists.txt b/producer/api/CMakeLists.txt index 97a0876ee174d4d9fb57b76d5368d1313512a5a0..40d5bc8d8b6be2872438fab2b77b918ac6e67ae3 100644 --- a/producer/api/CMakeLists.txt +++ b/producer/api/CMakeLists.txt @@ -10,9 +10,6 @@ target_include_directories(${TARGET_NAME} PUBLIC include) target_link_libraries(${TARGET_NAME} common) set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) -astyle(${TARGET_NAME} ${SOURCE_FILES}) - - ################################ # Testing ################################ diff --git a/producer/inotify-event-detector-cpp/CMakeLists.txt b/producer/inotify-event-detector-cpp/CMakeLists.txt index f940663aadcac14bb8c4d365386ac4664488ab24..dcb6da5431f4b6f4bd99004f33daeb122739dcdd 100644 --- a/producer/inotify-event-detector-cpp/CMakeLists.txt +++ b/producer/inotify-event-detector-cpp/CMakeLists.txt @@ -10,9 +10,6 @@ target_include_directories(${TARGET_NAME} PRIVATE include) target_link_libraries(${TARGET_NAME} common producer-api) set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) -astyle(${TARGET_NAME} ${SOURCE_FILES}) - - ################################ # Testing ################################