Skip to content

Commit

Permalink
Run cmake-lint with pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Feb 7, 2024
1 parent 4fb8be7 commit 7197038
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ repos:
files: ^src\/.+\.[ch]$
- id: fix-byte-order-marker
files: ^src\/.+\.[ch]$

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.10
hooks:
- id: cmake-format
args:
- --line-width=120
- --tab-size=4
exclude: cmake/conan.cmake
- id: cmake-lint
args:
- --linelength=120
- --spaces=4
exclude: cmake/conan.cmake
7 changes: 5 additions & 2 deletions cmake/compilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ check_c_source_compiles("${TEST_CODE_THOUSANDS_SEP}" HAVE_STRUCT_LCONV_THOUSANDS

set(USE_GNU_LINK_FLAGS 0)
set(USE_LLVM_MACOS_LINK_FLAGS 0)
if (NOT MSVC)
if(NOT MSVC)
if(${CMAKE_VERSION} VERSION_GREATER "3.17")
include(CheckLinkerFlag)
check_linker_flag(C "-Wl,--no-undefined" HAVE_LINK_NO_UNDEFINED)
check_linker_flag(C "-Wl,--retain-symbols-file,${PROJECT_SOURCE_DIR}/src/matio.sym" HAVE_LINK_RETAIN_SYMBOLS_FILE)
check_linker_flag(
C "-Wl,--retain-symbols-file,${PROJECT_SOURCE_DIR}/src/matio.sym"
HAVE_LINK_RETAIN_SYMBOLS_FILE
)
check_linker_flag(C "-Wl,-undefined,error" HAVE_LINK_UNDEFINED_ERROR)

if(HAVE_LINK_NO_UNDEFINED AND HAVE_LINK_RETAIN_SYMBOLS_FILE)
Expand Down
2 changes: 1 addition & 1 deletion cmake/getopt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if(NOT HAVE_GETOPT)
${PROJECT_SOURCE_DIR}/getopt/getopt_long.c
${PROJECT_SOURCE_DIR}/getopt/getopt.h
)
add_library(getopt STATIC ${getopt_SOURCES} )
add_library(getopt STATIC ${getopt_SOURCES})
target_include_directories(getopt PUBLIC ${PROJECT_SOURCE_DIR}/getopt)

# FIXME this should be fixed in the sourcecode
Expand Down
4 changes: 2 additions & 2 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ set_property(CACHE MATIO_DEFAULT_FILE_VERSION PROPERTY STRINGS 4 5 7.3)

if(MATIO_DEFAULT_FILE_VERSION STREQUAL "4")
set(MAT_FT_DEFAULT MAT_FT_MAT4)
elseif (MATIO_DEFAULT_FILE_VERSION STREQUAL "5")
elseif(MATIO_DEFAULT_FILE_VERSION STREQUAL "5")
set(MAT_FT_DEFAULT MAT_FT_MAT5)
elseif (MATIO_DEFAULT_FILE_VERSION STREQUAL "7.3")
elseif(MATIO_DEFAULT_FILE_VERSION STREQUAL "7.3")
set(MAT_FT_DEFAULT MAT_FT_MAT73)
else()
message(ERROR "Unrecognized MAT file version")
Expand Down
5 changes: 4 additions & 1 deletion cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ if(NOT HAVE_GETOPT)
endif()

if(NOT HAVE_SNPRINTF OR UNIX)
add_executable(test_snprintf ${PROJECT_SOURCE_DIR}/test/test_snprintf.c ${PROJECT_SOURCE_DIR}/snprintf/snprintf.c)
add_executable(test_snprintf
${PROJECT_SOURCE_DIR}/test/test_snprintf.c
${PROJECT_SOURCE_DIR}/snprintf/snprintf.c
)
if(HAVE_LIBM)
target_link_libraries(test_snprintf m)
endif()
Expand Down
18 changes: 15 additions & 3 deletions cmake/thirdParties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ if(MATIO_WITH_HDF5)

if(MATIO_USE_CONAN)
if(HDF5_USE_STATIC_LIBRARIES)
conan_cmake_run(REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]" BASIC_SETUP CMAKE_TARGETS OPTIONS hdf5:shared=False zlib:shared=False BUILD missing)
conan_cmake_run(
REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]"
BASIC_SETUP CMAKE_TARGETS
OPTIONS hdf5:shared=False zlib:shared=False
BUILD missing
)
else()
conan_cmake_run(REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]" BASIC_SETUP CMAKE_TARGETS OPTIONS hdf5:shared=True zlib:shared=True BUILD missing)
conan_cmake_run(
REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]"
BASIC_SETUP CMAKE_TARGETS
OPTIONS hdf5:shared=True zlib:shared=True
BUILD missing)
endif()
set(HDF5_FOUND TRUE)
else()
find_package(HDF5)
if(HDF5_FOUND)
set(HDF_MIN_VER 1.8)
if(HDF5_VERSION VERSION_LESS ${HDF_MIN_VER})
message(FATAL_ERROR "Could NOT find HDF5: Found unsuitable version ${HDF5_VERSION}, but required is at least ${HDF_MIN_VER} (found ${HDF5_LIBRARIES})")
message(FATAL_ERROR
"Could NOT find HDF5: Found unsuitable version ${HDF5_VERSION}, "
"but required is at least ${HDF_MIN_VER} (found ${HDF5_LIBRARIES})."
)
endif()
endif()
endif()
Expand Down
5 changes: 4 additions & 1 deletion cmake/tools.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
add_executable(matdump ${PROJECT_SOURCE_DIR}/tools/matdump.c ${PROJECT_SOURCE_DIR}/snprintf/snprintf.c)
add_executable(matdump
${PROJECT_SOURCE_DIR}/tools/matdump.c
${PROJECT_SOURCE_DIR}/snprintf/snprintf.c
)
target_link_libraries(matdump matio)
if(NOT HAVE_GETOPT)
target_link_libraries(matdump getopt)
Expand Down

0 comments on commit 7197038

Please sign in to comment.