Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit ad0bf3e

Browse files
fouriauxpramodk
authored andcommitted
Fix clang-format cmake module for compatible versions (#75)
* fix clang-format finder to: -- support specific version -- support path containing multiple clang-format * Add cmake info messages for boost/tests
1 parent 1b55b2f commit ad0bf3e

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

CMake/packages/FindClangFormat.cmake

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,30 @@
2525
# THE POSSIBILITY OF SUCH DAMAGE.
2626

2727
string(REPLACE ":" ";" _PATH $ENV{PATH})
28+
set(CLANG_FORMAT_FOUND OFF)
2829
foreach(p ${_PATH})
29-
file(GLOB cand ${p}/clang-format*)
30-
if(cand)
31-
set(CLANG_FORMAT_EXECUTABLE ${cand})
32-
set(CLANG_FORMAT_FOUND ON)
33-
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version OUTPUT_VARIABLE clang_out )
34-
string(REGEX MATCH .*\(version[^\n]*\)\n version ${clang_out})
35-
set(CLANG_FORMAT_VERSION ${CMAKE_MATCH_1})
36-
break()
37-
else()
38-
set(CLANG_FORMAT_FOUND OFF)
30+
file(GLOB cand ${p}/clang-format ${p}/clang-format-[0-9].[0-9])
31+
foreach(candidate ${cand})
32+
set(CLANG_FORMAT_EXECUTABLE ${candidate})
33+
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version OUTPUT_VARIABLE clang_out )
34+
string(REGEX MATCH "version \([0-9]\\.[0-9]\)" VERSION_OUTPUT ${clang_out})
35+
set(CLANG_FORMAT_VERSION ${CMAKE_MATCH_1})
36+
if ((${CLANG_FORMAT_VERSION} VERSION_GREATER ${CLANG_FORMAT_MIN_VERSION}) OR (${CLANG_FORMAT_VERSION} VERSION_EQUAL ${CLANG_FORMAT_MIN_VERSION}))
37+
set (FIT_MIN_REQUIRED true)
38+
else ()
39+
set (FIT_MIN_REQUIRED false)
3940
endif()
41+
if ((${CLANG_FORMAT_VERSION} VERSION_LESS ${CLANG_FORMAT_MAX_VERSION}) OR (${CLANG_FORMAT_VERSION} VERSION_EQUAL ${CLANG_FORMAT_MAX_VERSION}))
42+
set (FIT_MAX_REQUIRED true)
43+
else ()
44+
set (FIT_MAX_REQUIRED false)
45+
endif()
46+
if ( ${FIT_MIN_REQUIRED} AND ${FIT_MAX_REQUIRED})
47+
set(CLANG_FORMAT_FOUND ON)
48+
break()
49+
endif()
50+
endforeach()
51+
if (${CLANG_FORMAT_FOUND})
52+
break()
53+
endif()
4054
endforeach()

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,14 @@ add_definitions(-DCORENEURON_BUILD)
164164
option (ENABLE_SELECTIVE_GPU_PROFILING "Enable GPU profiling only for Solver" ON)
165165
option (ENABLE_OPENACC "Enable use of OpenACC" OFF)
166166

167+
set(CLANG_FORMAT_MIN_VERSION "4.0")
168+
set(CLANG_FORMAT_MAX_VERSION "4.9")
167169
find_package(ClangFormat)
168170

169171
if(CLANG_FORMAT_FOUND)
170172
message("clang-format : ${CLANG_FORMAT_EXECUTABLE} : ${CLANG_FORMAT_VERSION}")
171173
else()
172-
message("clang-format executable not found")
174+
message("clang-format executable with appropriate version (min: ${CLANG_FORMAT_MIN_VERSION}, max: ${CLANG_FORMAT_MAX_VERSION}) not found")
173175
endif()
174176

175177
if(CLANG_FORMAT_FOUND)
@@ -255,6 +257,8 @@ endif(CORENEURON_MAIN)
255257
# Tests
256258
if(Boost_FOUND)
257259
add_subdirectory(tests)
260+
else()
261+
message(STATUS "Boost not found, disabling tests")
258262
endif(Boost_FOUND)
259263

260264

tests/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ endif()
3636

3737

3838
if(UNIT_TESTS)
39-
40-
add_subdirectory(unit/endian)
41-
add_subdirectory(unit/sdprintf)
42-
add_subdirectory(unit/mechbuild)
43-
add_subdirectory(unit/omp)
44-
add_subdirectory(unit/cmdline_interface)
45-
add_subdirectory(unit/interleave_info)
46-
add_subdirectory(unit/alignment)
47-
add_subdirectory(unit/queueing)
48-
39+
add_subdirectory(unit/endian)
40+
add_subdirectory(unit/sdprintf)
41+
add_subdirectory(unit/mechbuild)
42+
add_subdirectory(unit/omp)
43+
add_subdirectory(unit/cmdline_interface)
44+
add_subdirectory(unit/interleave_info)
45+
add_subdirectory(unit/alignment)
46+
add_subdirectory(unit/queueing)
47+
else()
48+
message(STATUS "Unit tests disabled")
4949
endif()
5050

5151
if(FUNCTIONAL_TESTS)
52-
53-
add_subdirectory(integration)
54-
add_subdirectory(regression)
55-
52+
add_subdirectory(integration)
53+
add_subdirectory(regression)
54+
else()
55+
message(STATUS "Functional tests disabled")
5656
endif()

0 commit comments

Comments
 (0)