Skip to content

Commit 3594a54

Browse files
authored
Merge pull request libgit2#6911 from libgit2/ethomson/c90-2
Configurable C standard
2 parents 99e0d2a + d6a1107 commit 3594a54

File tree

16 files changed

+1297
-824
lines changed

16 files changed

+1297
-824
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
env:
133133
CC: clang
134134
CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer
135-
CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
135+
CMAKE_OPTIONS: -DC_EXTENSIONS=ON -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
136136
CMAKE_GENERATOR: Ninja
137137
SKIP_SSH_TESTS: true
138138
SKIP_NEGOTIATE_TESTS: true

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ endif()
9090

9191
# Modules
9292

93+
include(FeatureSummary)
94+
include(SetCStandard)
9395
include(CheckLibraryExists)
9496
include(CheckFunctionExists)
9597
include(CheckSymbolExists)
@@ -102,7 +104,6 @@ include(FindStatNsec)
102104
include(Findfutimens)
103105
include(GNUInstallDirs)
104106
include(IdeSplitSources)
105-
include(FeatureSummary)
106107
include(EnableWarnings)
107108
include(DefaultCFlags)
108109
include(ExperimentalFeatures)

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,13 @@ following:
373373
Compiler and linker options
374374
---------------------------
375375

376-
CMake lets you specify a few variables to control the behavior of the
377-
compiler and linker. These flags are rarely used but can be useful for
378-
64-bit to 32-bit cross-compilation.
376+
There are several options that control the behavior of the compiler and
377+
linker. These flags may be useful for cross-compilation or specialized
378+
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`
381383
- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
382384
- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
383385
Tell CMake where to find those specific libraries

cmake/SetCStandard.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if("${C_STANDARD}" STREQUAL "")
2+
set(C_STANDARD "90")
3+
endif()
4+
if("${C_EXTENSIONS}" STREQUAL "")
5+
set(C_EXTENSIONS OFF)
6+
endif()
7+
8+
if(${C_STANDARD} MATCHES "^[Cc].*")
9+
string(REGEX REPLACE "^[Cc]" "" C_STANDARD ${C_STANDARD})
10+
endif()
11+
12+
if(${C_STANDARD} MATCHES ".*-strict$")
13+
string(REGEX REPLACE "-strict$" "" C_STANDARD ${C_STANDARD})
14+
set(C_EXTENSIONS OFF)
15+
16+
add_feature_info("C Standard" ON "C${C_STANDARD} (strict)")
17+
else()
18+
add_feature_info("C Standard" ON "C${C_STANDARD}")
19+
endif()
20+
21+
function(set_c_standard project)
22+
set_target_properties(${project} PROPERTIES C_STANDARD ${C_STANDARD})
23+
set_target_properties(${project} PROPERTIES C_EXTENSIONS ${C_EXTENSIONS})
24+
endfunction()

0 commit comments

Comments
 (0)