Skip to content

Commit dd77398

Browse files
committed
CMake: Add option "OPTIONAL_WERROR"
1 parent 5c48760 commit dd77398

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

CMakeLists.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ cmake_minimum_required(VERSION 3.11)
33
project(tl-optional VERSION 1.0.0 LANGUAGES CXX)
44

55
option(OPTIONAL_ENABLE_TESTS "Enable tests." ON)
6+
option(OPTIONAL_WERROR "Turn compiler warnings into errors" OFF)
67

78
include(FetchContent)
8-
FetchContent_Declare(
9-
tl_cmake
10-
GIT_REPOSITORY https://github.com/TartanLlama/tl-cmake.git
9+
FetchContent_Declare(
10+
tl_cmake
11+
GIT_REPOSITORY https://github.com/TartanLlama/tl-cmake.git
1112
)
12-
FetchContent_GetProperties(tl_cmake)
13-
if(NOT tl_cmake_POPULATED)
14-
FetchContent_Populate(tl_cmake)
15-
set(CMAKE_MODULE_PATH ${tl_cmake_SOURCE_DIR} ${CMAKE_MODULE_PATH})
13+
FetchContent_GetProperties(tl_cmake)
14+
if(NOT tl_cmake_POPULATED)
15+
FetchContent_Populate(tl_cmake)
16+
set(CMAKE_MODULE_PATH ${tl_cmake_SOURCE_DIR} ${CMAKE_MODULE_PATH})
1617
endif()
1718
include(add-tl)
1819

19-
tl_add_library(optional SOURCES
20+
tl_add_library(optional SOURCES
2021
include/tl/optional.hpp)
2122

2223
if(OPTIONAL_ENABLE_TESTS)
@@ -37,7 +38,7 @@ if(OPTIONAL_ENABLE_TESTS)
3738
${CMAKE_CURRENT_SOURCE_DIR}/tests/constexpr.cpp
3839
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp
3940
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
40-
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
41+
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
4142
${CMAKE_CURRENT_SOURCE_DIR}/tests/bases.cpp
4243
${CMAKE_CURRENT_SOURCE_DIR}/tests/nullopt.cpp
4344
${CMAKE_CURRENT_SOURCE_DIR}/tests/swap.cpp)
@@ -50,3 +51,10 @@ if(OPTIONAL_ENABLE_TESTS)
5051
set_property(TARGET tests PROPERTY CXX_STANDARD ${CXXSTD})
5152
endif()
5253

54+
if(OPTIONAL_WERROR)
55+
if(MSVC)
56+
target_compile_options(optional PUBLIC /W3 /WX)
57+
else()
58+
target_compile_options(optional PUBLIC -Wall -Wextra -pedantic -Werror)
59+
endif()
60+
endif()

0 commit comments

Comments
 (0)