Skip to content

Commit bdaba5f

Browse files
committed
[C++] Enable C++ Windows build
1 parent 69af9c6 commit bdaba5f

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

.github/workflows/ci.yml

+14
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,17 @@ jobs:
168168
sudo xcode-select -switch /Applications/Xcode_${{ matrix.version }}.app
169169
- name: Build
170170
run: ./cppbuild/cppbuild
171+
172+
cpp-msvc-build:
173+
name: C++ MSVC (Windows)
174+
runs-on: windows-latest
175+
strategy:
176+
fail-fast: false
177+
env:
178+
CC: cl
179+
CXX: cl
180+
steps:
181+
- name: Checkout code
182+
uses: actions/checkout@v2
183+
- name: Build
184+
run: cppbuild/cppbuild.cmd

CMakeLists.txt

+36-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif ()
3232
option(SBE_TESTS "Enable tests" ${STANDALONE_BUILD})
3333
option(SBE_BUILD_SAMPLES "Enable building the sample projects" ${STANDALONE_BUILD})
3434
option(SBE_BUILD_BENCHMARKS "Enable building the benchmarks" ${STANDALONE_BUILD})
35+
option(C_WARNINGS_AS_ERRORS "Enable warnings as errors for C" OFF)
36+
option(CXX_WARNINGS_AS_ERRORS "Enable warnings as errors for C++" OFF)
3537

3638
unset(STANDALONE_BUILD)
3739

@@ -80,6 +82,12 @@ if (SBE_TESTS)
8082
ExternalProject_Get_Property(gtest binary_dir)
8183
set(GTEST_BINARY_DIR ${binary_dir})
8284

85+
if (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
86+
set(GTEST_POSTFIX "d")
87+
else ()
88+
set(GTEST_POSTFIX "")
89+
endif ()
90+
8391
set(GTEST_LIBS
8492
${GTEST_BINARY_DIR}/lib/${CMAKE_CFG_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}
8593
${GTEST_BINARY_DIR}/lib/${CMAKE_CFG_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
@@ -91,17 +99,42 @@ find_package(Threads)
9199

92100
if (UNIX)
93101
add_compile_options(-Wall -Wpedantic -Wextra -Wno-unused-parameter)
102+
103+
if (C_WARNINGS_AS_ERRORS)
104+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Werror>)
105+
endif (C_WARNINGS_AS_ERRORS)
106+
107+
if (CXX_WARNINGS_AS_ERRORS)
108+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror>)
109+
endif (CXX_WARNINGS_AS_ERRORS)
94110
endif ()
95111

96112
if (APPLE)
97113
# -Wall doesn't enable everything we want to see
98114
add_compile_options(-Wsign-compare)
99115
add_definitions(-DDarwin)
116+
add_compile_options(-Wno-deprecated-register)
100117
elseif (MSVC)
101118
add_definitions(-DWIN32)
119+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
120+
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
121+
add_definitions(-DNOMINMAX)
122+
123+
if (${MSVC_VERSION} GREATER_EQUAL 1915)
124+
# Acknowledge that we understand MSVC resolved a byte alignment issue in this compiler
125+
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
126+
endif ()
127+
128+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /Od /Zi /MP")
129+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /MP")
130+
131+
if (C_WARNINGS_AS_ERRORS)
132+
add_compile_options($<$<COMPILE_LANGUAGE:C>:/WX>)
133+
endif (C_WARNINGS_AS_ERRORS)
102134

103-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /Od /Zi")
104-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
135+
if (CXX_WARNINGS_AS_ERRORS)
136+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/WX>)
137+
endif (CXX_WARNINGS_AS_ERRORS)
105138
else ()
106139
add_definitions(-D_GNU_SOURCE)
107140
endif ()
@@ -111,6 +144,7 @@ set(LIBSUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
111144

112145
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/binaries")
113146
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
147+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
114148

115149
set(SBE_JAR "${CMAKE_CURRENT_SOURCE_DIR}/sbe-all/build/libs/sbe-all-${SBE_VERSION_TXT}.jar")
116150

cppbuild/cppbuild.cmd

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ setlocal EnableDelayedExpansion
44
set SOURCE_DIR=%CD%
55
set BUILD_DIR=%CD%\cppbuild\Release
66

7+
for %%o in (%*) do (
8+
9+
set PROCESSED=0
10+
11+
if "%%o"=="--help" (
12+
echo cppbuild.cmd [--c-warnings-as-errors] [--cxx-warnings-as-errors]
13+
exit /b
14+
)
15+
16+
if "%%o"=="--c-warnings-as-errors" (
17+
set EXTRA_CMAKE_ARGS=!EXTRA_CMAKE_ARGS! -DC_WARNINGS_AS_ERRORS=ON
18+
set PROCESSED=1
19+
)
20+
21+
if "%%o"=="--cxx-warnings-as-errors" (
22+
set EXTRA_CMAKE_ARGS=!EXTRA_CMAKE_ARGS! -DCXX_WARNINGS_AS_ERRORS=ON
23+
set PROCESSED=1
24+
)
25+
)
26+
727
call cppbuild/vs-helper.cmd
828
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
929

@@ -12,8 +32,11 @@ if EXIST %BUILD_DIR% rd /S /Q %BUILD_DIR%
1232
md %BUILD_DIR%
1333
pushd %BUILD_DIR%
1434

35+
cmake %EXTRA_CMAKE_ARGS% %SOURCE_DIR%
36+
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
37+
1538
cmake --build . --clean-first --config Release
1639
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
1740

18-
ctest -C Release
41+
ctest -C Release --output-on-failure
1942
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%

0 commit comments

Comments
 (0)