mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-21 22:16:24 +00:00
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.
This commit is contained in:
@@ -53,6 +53,8 @@ option(SONAME "Set the (SO)VERSION of the target"
|
||||
option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
|
||||
|
||||
# Compilation options
|
||||
set(CMAKE_C_STANDARD "90" CACHE STRING "The C standard to compile against")
|
||||
option(CMAKE_C_EXTENSIONS "Whether compiler extensions are supported" OFF)
|
||||
option(ENABLE_WERROR "Enable compilation with -Werror" OFF)
|
||||
|
||||
if(UNIX)
|
||||
@@ -91,7 +93,6 @@ endif()
|
||||
# Modules
|
||||
|
||||
include(FeatureSummary)
|
||||
include(SetCStandard)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
@@ -378,8 +378,8 @@ linker. These flags may be useful for cross-compilation or specialized
|
||||
setups.
|
||||
|
||||
- `CMAKE_C_FLAGS`: Set your own compiler flags
|
||||
- `C_STANDARD`: the C standard to compile against; defaults to `C90`
|
||||
- `C_EXTENSIONS`: whether compiler extensions are supported; defaults to `OFF`
|
||||
- `CMAKE_C_STANDARD`: the C standard to compile against; defaults to `C90`
|
||||
- `CMAKE_C_EXTENSIONS`: whether compiler extensions are supported; defaults to `OFF`
|
||||
- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
|
||||
- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
|
||||
Tell CMake where to find those specific libraries
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
if("${C_STANDARD}" STREQUAL "")
|
||||
set(C_STANDARD "90")
|
||||
endif()
|
||||
if("${C_EXTENSIONS}" STREQUAL "")
|
||||
set(C_EXTENSIONS OFF)
|
||||
endif()
|
||||
|
||||
if(${C_STANDARD} MATCHES "^[Cc].*")
|
||||
string(REGEX REPLACE "^[Cc]" "" C_STANDARD ${C_STANDARD})
|
||||
endif()
|
||||
|
||||
if(${C_STANDARD} MATCHES ".*-strict$")
|
||||
string(REGEX REPLACE "-strict$" "" C_STANDARD ${C_STANDARD})
|
||||
set(C_EXTENSIONS OFF)
|
||||
|
||||
add_feature_info("C Standard" ON "C${C_STANDARD} (strict)")
|
||||
else()
|
||||
add_feature_info("C Standard" ON "C${C_STANDARD}")
|
||||
endif()
|
||||
|
||||
function(set_c_standard project)
|
||||
set_target_properties(${project} PROPERTIES C_STANDARD ${C_STANDARD})
|
||||
set_target_properties(${project} PROPERTIES C_EXTENSIONS ${C_EXTENSIONS})
|
||||
endfunction()
|
||||
1
deps/ntlmclient/CMakeLists.txt
vendored
1
deps/ntlmclient/CMakeLists.txt
vendored
@@ -37,4 +37,3 @@ else()
|
||||
endif()
|
||||
|
||||
add_library(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO})
|
||||
set_target_properties(ntlmclient PROPERTIES C_STANDARD 90)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
file(GLOB SRC_EXAMPLES *.c *.h)
|
||||
|
||||
add_executable(lg2 ${SRC_EXAMPLES})
|
||||
set_c_standard(lg2)
|
||||
|
||||
# Ensure that we do not use deprecated functions internally
|
||||
add_definitions(-DGIT_DEPRECATE_HARD)
|
||||
|
||||
@@ -20,7 +20,6 @@ foreach(fuzz_target_src ${SRC_FUZZERS})
|
||||
endif()
|
||||
|
||||
add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES})
|
||||
set_c_standard(${fuzz_target_name})
|
||||
target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
|
||||
target_include_directories(${fuzz_target_name} SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ add_executable(git2_cli ${CLI_SRC_C} ${CLI_SRC_OS} ${CLI_OBJECTS}
|
||||
${LIBGIT2_DEPENDENCY_OBJECTS})
|
||||
target_link_libraries(git2_cli ${CLI_LIBGIT2_LIBRARY} ${LIBGIT2_SYSTEM_LIBS})
|
||||
|
||||
set_c_standard(git2_cli)
|
||||
set_target_properties(git2_cli PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
|
||||
set_target_properties(git2_cli PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# git library functionality.
|
||||
|
||||
add_library(libgit2 OBJECT)
|
||||
set_c_standard(libgit2)
|
||||
|
||||
include(PkgBuildConfig)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# util: a shared library for common utility functions for libgit2 projects
|
||||
|
||||
add_library(util OBJECT)
|
||||
set_c_standard(util)
|
||||
|
||||
configure_file(git2_features.h.in git2_features.h)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
# even when they have aggressive C90 warnings enabled.
|
||||
|
||||
add_executable(headertest headertest.c)
|
||||
set_c_standard(headertest)
|
||||
|
||||
target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ set_source_files_properties(
|
||||
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
|
||||
|
||||
add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
|
||||
set_c_standard(libgit2_tests)
|
||||
|
||||
set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
|
||||
|
||||
@@ -38,7 +38,6 @@ set_source_files_properties(
|
||||
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
|
||||
|
||||
add_executable(util_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
|
||||
set_c_standard(util_tests)
|
||||
|
||||
set_target_properties(util_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user