Skip to content

Commit cb9be97

Browse files
[cmake] only require a CXX compiler when tests are build
Signed-off-by: Thomas Devoogdt <[email protected]>
1 parent e26dde3 commit cb9be97

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

build/cmake/CMakeLists.txt

+13-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ project(zstd
3737
VERSION "${ZSTD_FULL_VERSION}"
3838
LANGUAGES C # Main library is in C
3939
ASM # And ASM
40-
CXX # Testing contributed code also utilizes CXX
4140
)
4241

4342
message(STATUS "ZSTD VERSION: ${zstd_VERSION}")
@@ -54,12 +53,6 @@ endif()
5453

5554
include(GNUInstallDirs)
5655

57-
#-----------------------------------------------------------------------------
58-
# Add extra compilation flags
59-
#-----------------------------------------------------------------------------
60-
include(AddZstdCompilationFlags)
61-
ADD_ZSTD_COMPILATION_FLAGS()
62-
6356
# Always hide XXHash symbols
6457
add_definitions(-DXXH_NAMESPACE=ZSTD_)
6558

@@ -123,6 +116,19 @@ if (MSVC)
123116
option(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" OFF)
124117
endif ()
125118

119+
# Enable C++ support for testing.
120+
set(ZSTD_ENABLE_CXX ZSTD_BUILD_TESTS)
121+
122+
if(ZSTD_ENABLE_CXX)
123+
enable_language(CXX)
124+
endif()
125+
126+
#-----------------------------------------------------------------------------
127+
# Add extra compilation flags
128+
#-----------------------------------------------------------------------------
129+
include(AddZstdCompilationFlags)
130+
ADD_ZSTD_COMPILATION_FLAGS(ON ZSTD_ENABLE_CXX ON) # C CXX LD
131+
126132
#-----------------------------------------------------------------------------
127133
# External dependencies
128134
#-----------------------------------------------------------------------------

build/cmake/CMakeModules/AddZstdCompilationFlags.cmake

+17-17
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function(EnableCompilerFlag _flag _C _CXX _LD)
4949
endif ()
5050
endfunction()
5151

52-
macro(ADD_ZSTD_COMPILATION_FLAGS)
52+
macro(ADD_ZSTD_COMPILATION_FLAGS _C _CXX _LD)
5353
# We set ZSTD_HAS_NOEXECSTACK if we are certain we've set all the required
5454
# compiler flags to mark the stack as non-executable.
5555
set(ZSTD_HAS_NOEXECSTACK false)
@@ -63,26 +63,26 @@ macro(ADD_ZSTD_COMPILATION_FLAGS)
6363
# EnableCompilerFlag("-std=c99" true false) # Set C compilation to c99 standard
6464
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC)
6565
# clang-cl normally maps -Wall to -Weverything.
66-
EnableCompilerFlag("/clang:-Wall" true true false)
66+
EnableCompilerFlag("/clang:-Wall" _C _CXX false)
6767
else ()
68-
EnableCompilerFlag("-Wall" true true false)
68+
EnableCompilerFlag("-Wall" _C _CXX false)
6969
endif ()
70-
EnableCompilerFlag("-Wextra" true true false)
71-
EnableCompilerFlag("-Wundef" true true false)
72-
EnableCompilerFlag("-Wshadow" true true false)
73-
EnableCompilerFlag("-Wcast-align" true true false)
74-
EnableCompilerFlag("-Wcast-qual" true true false)
75-
EnableCompilerFlag("-Wstrict-prototypes" true false false)
70+
EnableCompilerFlag("-Wextra" _C _CXX false)
71+
EnableCompilerFlag("-Wundef" _C _CXX false)
72+
EnableCompilerFlag("-Wshadow" _C _CXX false)
73+
EnableCompilerFlag("-Wcast-align" _C _CXX false)
74+
EnableCompilerFlag("-Wcast-qual" _C _CXX false)
75+
EnableCompilerFlag("-Wstrict-prototypes" _C false false)
7676
# Enable asserts in Debug mode
7777
if (CMAKE_BUILD_TYPE MATCHES "Debug")
78-
EnableCompilerFlag("-DDEBUGLEVEL=1" true true false)
78+
EnableCompilerFlag("-DDEBUGLEVEL=1" _C _CXX false)
7979
endif ()
8080
# Add noexecstack flags
8181
# LDFLAGS
82-
EnableCompilerFlag("-Wl,-z,noexecstack" false false true)
82+
EnableCompilerFlag("-Wl,-z,noexecstack" false false _LD)
8383
# CFLAGS & CXXFLAGS
84-
EnableCompilerFlag("-Qunused-arguments" true true false)
85-
EnableCompilerFlag("-Wa,--noexecstack" true true false)
84+
EnableCompilerFlag("-Qunused-arguments" _C _CXX false)
85+
EnableCompilerFlag("-Wa,--noexecstack" _C _CXX false)
8686
# NOTE: Using 3 nested ifs because the variables are sometimes
8787
# empty if the condition is false, and sometimes equal to false.
8888
# This implicitly converts them to truthy values. There may be
@@ -99,15 +99,15 @@ macro(ADD_ZSTD_COMPILATION_FLAGS)
9999

100100
set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)")
101101
if (CMAKE_GENERATOR MATCHES "Visual Studio" AND ACTIVATE_MULTITHREADED_COMPILATION)
102-
EnableCompilerFlag("/MP" true true false)
102+
EnableCompilerFlag("/MP" _C _CXX false)
103103
endif ()
104104

105105
# UNICODE SUPPORT
106-
EnableCompilerFlag("/D_UNICODE" true true false)
107-
EnableCompilerFlag("/DUNICODE" true true false)
106+
EnableCompilerFlag("/D_UNICODE" _C _CXX false)
107+
EnableCompilerFlag("/DUNICODE" _C _CXX false)
108108
# Enable asserts in Debug mode
109109
if (CMAKE_BUILD_TYPE MATCHES "Debug")
110-
EnableCompilerFlag("/DDEBUGLEVEL=1" true true false)
110+
EnableCompilerFlag("/DDEBUGLEVEL=1" _C _CXX false)
111111
endif ()
112112
endif ()
113113

0 commit comments

Comments
 (0)