Repository navigation
lib: zstd: only require a C compiler #12538
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
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 |
|---|---|---|
|
|
@@ -37,7 +37,6 @@ project(zstd | |
| VERSION "${ZSTD_FULL_VERSION}" | ||
| LANGUAGES C # Main library is in C | ||
| ASM # And ASM | ||
| CXX # Testing contributed code also utilizes CXX | ||
| ) | ||
|
|
||
| message(STATUS "ZSTD VERSION: ${zstd_VERSION}") | ||
|
|
@@ -54,12 +53,6 @@ endif() | |
|
|
||
| include(GNUInstallDirs) | ||
|
|
||
| #----------------------------------------------------------------------------- | ||
| # Add extra compilation flags | ||
| #----------------------------------------------------------------------------- | ||
| include(AddZstdCompilationFlags) | ||
| ADD_ZSTD_COMPILATION_FLAGS() | ||
|
|
||
| # Always hide XXHash symbols | ||
| add_definitions(-DXXH_NAMESPACE=ZSTD_) | ||
|
|
||
|
|
@@ -123,6 +116,19 @@ if (MSVC) | |
| option(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" OFF) | ||
| endif () | ||
|
|
||
| # Enable C++ support for testing. | ||
| set(ZSTD_ENABLE_CXX ${ZSTD_BUILD_TESTS}) | ||
|
|
||
| if(ZSTD_ENABLE_CXX) | ||
| enable_language(CXX) | ||
| endif() | ||
|
|
||
| #----------------------------------------------------------------------------- | ||
| # Add extra compilation flags | ||
| #----------------------------------------------------------------------------- | ||
| include(AddZstdCompilationFlags) | ||
| ADD_ZSTD_COMPILATION_FLAGS(ON ZSTD_ENABLE_CXX ON) # C CXX LD | ||
|
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.
When tests are disabled and CXX is not enabled, Useful? React with 👍 / 👎. |
||
|
|
||
| #----------------------------------------------------------------------------- | ||
| # External dependencies | ||
| #----------------------------------------------------------------------------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ function(EnableCompilerFlag _flag _C _CXX _LD) | |
| endif () | ||
| endfunction() | ||
|
|
||
| macro(ADD_ZSTD_COMPILATION_FLAGS) | ||
| macro(ADD_ZSTD_COMPILATION_FLAGS _C _CXX _LD) | ||
| # We set ZSTD_HAS_NOEXECSTACK if we are certain we've set all the required | ||
| # compiler flags to mark the stack as non-executable. | ||
| set(ZSTD_HAS_NOEXECSTACK false) | ||
|
|
@@ -63,26 +63,26 @@ macro(ADD_ZSTD_COMPILATION_FLAGS) | |
| # EnableCompilerFlag("-std=c99" true false) # Set C compilation to c99 standard | ||
| if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC) | ||
| # clang-cl normally maps -Wall to -Weverything. | ||
| EnableCompilerFlag("/clang:-Wall" true true false) | ||
| EnableCompilerFlag("/clang:-Wall" _C _CXX false) | ||
| else () | ||
| EnableCompilerFlag("-Wall" true true false) | ||
| EnableCompilerFlag("-Wall" _C _CXX false) | ||
|
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Forward the macro argument values to The changed registrations pass bare 🤖 Prompt for AI Agents |
||
| endif () | ||
| EnableCompilerFlag("-Wextra" true true false) | ||
| EnableCompilerFlag("-Wundef" true true false) | ||
| EnableCompilerFlag("-Wshadow" true true false) | ||
| EnableCompilerFlag("-Wcast-align" true true false) | ||
| EnableCompilerFlag("-Wcast-qual" true true false) | ||
| EnableCompilerFlag("-Wstrict-prototypes" true false false) | ||
| EnableCompilerFlag("-Wextra" _C _CXX false) | ||
| EnableCompilerFlag("-Wundef" _C _CXX false) | ||
| EnableCompilerFlag("-Wshadow" _C _CXX false) | ||
| EnableCompilerFlag("-Wcast-align" _C _CXX false) | ||
| EnableCompilerFlag("-Wcast-qual" _C _CXX false) | ||
| EnableCompilerFlag("-Wstrict-prototypes" _C false false) | ||
| # Enable asserts in Debug mode | ||
| if (CMAKE_BUILD_TYPE MATCHES "Debug") | ||
| EnableCompilerFlag("-DDEBUGLEVEL=1" true true false) | ||
| EnableCompilerFlag("-DDEBUGLEVEL=1" _C _CXX false) | ||
| endif () | ||
| # Add noexecstack flags | ||
| # LDFLAGS | ||
| EnableCompilerFlag("-Wl,-z,noexecstack" false false true) | ||
| EnableCompilerFlag("-Wl,-z,noexecstack" false false _LD) | ||
| # CFLAGS & CXXFLAGS | ||
| EnableCompilerFlag("-Qunused-arguments" true true false) | ||
| EnableCompilerFlag("-Wa,--noexecstack" true true false) | ||
| EnableCompilerFlag("-Qunused-arguments" _C _CXX false) | ||
| EnableCompilerFlag("-Wa,--noexecstack" _C _CXX false) | ||
| # NOTE: Using 3 nested ifs because the variables are sometimes | ||
| # empty if the condition is false, and sometimes equal to false. | ||
| # This implicitly converts them to truthy values. There may be | ||
|
|
@@ -99,15 +99,15 @@ macro(ADD_ZSTD_COMPILATION_FLAGS) | |
|
|
||
| set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)") | ||
| if (CMAKE_GENERATOR MATCHES "Visual Studio" AND ACTIVATE_MULTITHREADED_COMPILATION) | ||
| EnableCompilerFlag("/MP" true true false) | ||
| EnableCompilerFlag("/MP" _C _CXX false) | ||
| endif () | ||
|
|
||
| # UNICODE SUPPORT | ||
| EnableCompilerFlag("/D_UNICODE" true true false) | ||
| EnableCompilerFlag("/DUNICODE" true true false) | ||
| EnableCompilerFlag("/D_UNICODE" _C _CXX false) | ||
|
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.
When AGENTS.md reference: AGENTS.md:L11-L15 Useful? React with 👍 / 👎. |
||
| EnableCompilerFlag("/DUNICODE" _C _CXX false) | ||
| # Enable asserts in Debug mode | ||
| if (CMAKE_BUILD_TYPE MATCHES "Debug") | ||
| EnableCompilerFlag("/DDEBUGLEVEL=1" true true false) | ||
| EnableCompilerFlag("/DDEBUGLEVEL=1" _C _CXX false) | ||
| endif () | ||
| 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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Remove the remaining C++ assumptions from C-only builds.
When
ZSTD_BUILD_TESTSis off, a standalone C-only configure leavesCMAKE_CXX_COMPILER_IDempty. The guard at Line 57 oflib/zstd-1.5.7/build/cmake/CMakeModules/AddZstdCompilationFlags.cmakethen skips the GNU/Clang C flags. The condition at Lines 90–92 also requires a C++ flag result before it setsZSTD_HAS_NOEXECSTACK, which can disable assembly. Select the flag block withCMAKE_C_COMPILER_ID, and require the C++ flag result only when C++ is enabled. (cmake.org)🤖 Prompt for AI Agents