Skip to content

Commit d090433

Browse files
committed
cmake: use CMAKE_C_STANDARD and CMAKE_C_EXTENSIONS
cmake already provides a standard way for callers to override the C_STANDARD and C_EXTENSIONS properties. Support and document those.
1 parent 6ea625c commit d090433

File tree

12 files changed

+4
-36
lines changed

12 files changed

+4
-36
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ option(SONAME "Set the (SO)VERSION of the target"
5353
option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
5454

5555
# Compilation options
56+
set(CMAKE_C_STANDARD "90" CACHE STRING "The C standard to compile against")
57+
option(CMAKE_C_EXTENSIONS "Whether compiler extensions are supported" OFF)
5658
option(ENABLE_WERROR "Enable compilation with -Werror" OFF)
5759

5860
if(UNIX)
@@ -91,7 +93,6 @@ endif()
9193
# Modules
9294

9395
include(FeatureSummary)
94-
include(SetCStandard)
9596
include(CheckLibraryExists)
9697
include(CheckFunctionExists)
9798
include(CheckSymbolExists)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ linker. These flags may be useful for cross-compilation or specialized
378378
setups.
379379

380380
- `CMAKE_C_FLAGS`: Set your own compiler flags
381-
- `C_STANDARD`: the C standard to compile against; defaults to `C90`
382-
- `C_EXTENSIONS`: whether compiler extensions are supported; defaults to `OFF`
381+
- `CMAKE_C_STANDARD`: the C standard to compile against; defaults to `C90`
382+
- `CMAKE_C_EXTENSIONS`: whether compiler extensions are supported; defaults to `OFF`
383383
- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
384384
- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
385385
Tell CMake where to find those specific libraries

cmake/SetCStandard.cmake

Lines changed: 0 additions & 24 deletions
This file was deleted.

deps/ntlmclient/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ else()
3737
endif()
3838

3939
add_library(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO})
40-
set_target_properties(ntlmclient PROPERTIES C_STANDARD 90)

examples/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
file(GLOB SRC_EXAMPLES *.c *.h)
44

55
add_executable(lg2 ${SRC_EXAMPLES})
6-
set_c_standard(lg2)
76

87
# Ensure that we do not use deprecated functions internally
98
add_definitions(-DGIT_DEPRECATE_HARD)

fuzzers/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ foreach(fuzz_target_src ${SRC_FUZZERS})
2020
endif()
2121

2222
add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES})
23-
set_c_standard(${fuzz_target_name})
2423
target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
2524
target_include_directories(${fuzz_target_name} SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
2625

src/cli/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ add_executable(git2_cli ${CLI_SRC_C} ${CLI_SRC_OS} ${CLI_OBJECTS}
4040
${LIBGIT2_DEPENDENCY_OBJECTS})
4141
target_link_libraries(git2_cli ${CLI_LIBGIT2_LIBRARY} ${LIBGIT2_SYSTEM_LIBS})
4242

43-
set_c_standard(git2_cli)
4443
set_target_properties(git2_cli PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
4544
set_target_properties(git2_cli PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
4645

src/libgit2/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# git library functionality.
33

44
add_library(libgit2 OBJECT)
5-
set_c_standard(libgit2)
65

76
include(PkgBuildConfig)
87

src/util/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# util: a shared library for common utility functions for libgit2 projects
22

33
add_library(util OBJECT)
4-
set_c_standard(util)
54

65
configure_file(git2_features.h.in git2_features.h)
76

tests/headertest/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# even when they have aggressive C90 warnings enabled.
44

55
add_executable(headertest headertest.c)
6-
set_c_standard(headertest)
76

87
target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
98

0 commit comments

Comments
 (0)