Browse Source

Build system fixes

* added a FindPackage module for clang-format
* fixed library dependencies
develop
Eyck Jentzsch 4 months ago
parent
commit
c08c553e9e
3 changed files with 76 additions and 13 deletions
  1. 6
    1
      CMakeLists.txt
  2. 34
    0
      cmake/FindClangFormat.cmake
  3. 36
    12
      cmake/clang-format.cmake

+ 6
- 1
CMakeLists.txt View File

@@ -79,7 +79,12 @@ set_target_properties(${LIBRARY_NAME} PROPERTIES
PUBLIC_HEADER "${LibHeaders}" # specify the public headers
)

target_link_libraries(${LIBRARY_NAME} scc-util )
target_link_libraries(${LIBRARY_NAME} scc-util ${CMAKE_DL_LIBS})
if(${CMAKE_VERSION} VERSION_LESS "3.2.0")
target_link_libraries(${LIBRARY_NAME} ${CMAKE_THREAD_LIBS_INIT})
else()
target_link_libraries(${LIBRARY_NAME} Threads::Threads)
endif()

if(CCI_FOUND)
target_compile_definitions(${LIBRARY_NAME} PUBLIC -DWITH_CCI)

+ 34
- 0
cmake/FindClangFormat.cmake View File

@@ -0,0 +1,34 @@
# Find Clang format
#
#
if(NOT CLANG_FORMAT_BIN_NAME)
set(CLANG_FORMAT_BIN_NAME clang-format)
endif()

# if custom path check there first
if(CLANG_FORMAT_ROOT_DIR)
find_program(CLANG_FORMAT_BIN
NAMES
${CLANG_FORMAT_BIN_NAME}
PATHS
"${CLANG_FORMAT_ROOT_DIR}"
NO_DEFAULT_PATH)
endif()

find_program(CLANG_FORMAT_BIN NAMES ${CLANG_FORMAT_BIN_NAME})

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
CLANG_FORMAT
DEFAULT_MSG
CLANG_FORMAT_BIN)

mark_as_advanced(
CLANG_FORMAT_BIN)

if(CLANG_FORMAT_FOUND)
# A CMake script to find all source files and setup clang-format targets for them
include(clang-format)
else()
message("clang-format not found. Not setting up format targets")
endif()

+ 36
- 12
cmake/clang-format.cmake View File

@@ -1,20 +1,44 @@
# additional target to perform clang-format run, requires clang-format

# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
foreach(PROJECT_TRDPARTY_DIR ${PROJECT_3PARTY_DIRS})
string(FIND ${SOURCE_FILE} ${PROJECT_TRDPARTY_DIR} PROJECT_EXTERNAL_DIR_FOUND)
if (NOT ${PROJECT_EXTERNAL_DIR_FOUND} EQUAL -1)
#message( STATUS "Skipping ${SOURCE_FILE} for clang-format." )
set(CLANG_FORMAT_CXX_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.h *.cxx *.hxx *.hpp *.cc *.ipp)
file(GLOB_RECURSE ALL_SOURCE_FILES ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})

# Don't include some common build folders
set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake")

# get all project files file
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND)
if (NOT ${EXCLUDE_FOUND} EQUAL -1)
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
endif ()
endforeach()
endif ()
endforeach ()
endforeach ()

add_custom_target(
clangformat
COMMAND clang-format
add_custom_target(clangformat
COMMENT "Running clang-format to change files"
COMMAND ${CLANG_FORMAT_BIN}
-i
${ALL_SOURCE_FILES}
)

add_custom_target(format
COMMENT "Running clang-format to change files"
COMMAND ${CLANG_FORMAT_BIN}
-style=file
-i
${ALL_SOURCE_FILES}
)


add_custom_target(format-check
COMMENT "Checking clang-format changes"
# Use ! to negate the result for correct output
COMMAND !
${CLANG_FORMAT_BIN}
-style=file
-output-replacements-xml
${ALL_SOURCE_FILES}
| grep -q "replacement offset"
)

Loading…
Cancel
Save