-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not define AVIF_ENABLE_NODISCARD for avif.h #2351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,19 @@ include(FetchContent) | |
include(FindPkgConfig) | ||
include(AvifExternalProjectUtils) | ||
|
||
option(AVIF_ENABLE_NODISCARD "Add [[nodiscard]] to some functions. CMake must be at least 3.21 to force C23." OFF) | ||
|
||
# Set C99 as the default | ||
set(CMAKE_C_STANDARD 99) | ||
if(AVIF_ENABLE_NODISCARD) | ||
# [[nodiscard]] requires C23. | ||
if(CMAKE_VERSION VERSION_LESS 3.21.0) | ||
message(FATAL_ERROR "CMake must be at least 3.21 to force C23, bailing out") | ||
endif() | ||
set(CMAKE_C_STANDARD 23) | ||
set(CMAKE_C_STANDARD_REQUIRED ON) | ||
else() | ||
set(CMAKE_C_STANDARD 99) | ||
endif() | ||
|
||
# SOVERSION scheme: MAJOR.MINOR.PATCH | ||
# If there was an incompatible interface change: | ||
|
@@ -52,7 +63,6 @@ set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR}) | |
option(BUILD_SHARED_LIBS "Build shared avif library" ON) | ||
|
||
option(AVIF_ENABLE_WERROR "Treat all compiler warnings as errors" OFF) | ||
option(AVIF_ENABLE_NODISCARD "Add [[nodiscard]] to some functions. CMake must be at least 3.21 to force C23" OFF) | ||
|
||
option(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R "Enable experimental YCgCo-R matrix code" OFF) | ||
option(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP | ||
|
@@ -334,22 +344,6 @@ endif() | |
|
||
target_link_libraries(avif_obj PRIVATE avif_enable_warnings) | ||
|
||
if(AVIF_ENABLE_NODISCARD) | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0) | ||
set(CMAKE_C_STANDARD 23) | ||
set_property(TARGET avif_obj PROPERTY C_STANDARD 23) | ||
else() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we redefine |
||
unset(CMAKE_C_STANDARD) | ||
set_property(TARGET avif_obj PROPERTY C_STANDARD) | ||
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") | ||
target_compile_options(avif_obj PUBLIC $<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:-std=gnu2x>>) | ||
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC") | ||
target_compile_options(avif_obj PUBLIC $<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:/std:clatest>>) | ||
endif() | ||
endif() | ||
target_compile_definitions(avif_obj PUBLIC $<BUILD_INTERFACE:AVIF_ENABLE_NODISCARD=1>) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The definition of the |
||
endif() | ||
|
||
if(AVIF_ENABLE_COVERAGE) | ||
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") | ||
message(STATUS "libavif: Enabling coverage for Clang") | ||
|
@@ -592,7 +586,9 @@ if(AVIF_LIB_USE_CXX OR (AVIF_BUILD_APPS AND AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP) O | |
) | ||
enable_language(CXX) | ||
if(AVIF_ENABLE_NODISCARD) | ||
# [[nodiscard]] requires C++17. | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
else() | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think this would be required too, but it's highly unlikely anyone would try this with a c90 only compiler (or force those flags)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we assume the compiler supports C99.