@@ -8,7 +8,14 @@ project(runcpp2)
88set (CMAKE_CXX_STANDARD 11)
99
1010option (RUNCPP2_UPDATE_DEFAULT_YAMLS "Update default yaml files" OFF )
11- option (RUNCPP2_BUILD_TESTS "Build runcpp2 tests" OFF )
11+
12+ if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR )
13+ option (RUNCPP2_WARNINGS_AS_ERRORS "Treat warnings as errors" ON )
14+ option (RUNCPP2_BUILD_TESTS "Build runcpp2 tests" ON )
15+ else ()
16+ option (RUNCPP2_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF )
17+ option (RUNCPP2_BUILD_TESTS "Build runcpp2 tests" OFF )
18+ endif ()
1219
1320# =========================================================================
1421# Retrieving Version String
@@ -158,28 +165,35 @@ target_link_libraries(runcpp2 PUBLIC ghc_filesystem ryml::ryml mpark_variant)
158165
159166if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
160167 # TODO: Try to change to /Wall
161- set (STANDARD_COMPILE_FLAGS "/utf-8;/W1;/DGHC_WIN_DISABLE_WSTRING_STORAGE_TYPE=1" )
168+ set (RUNCPP2_STANDARD_COMPILE_FLAGS "/utf-8;/W1;/DGHC_WIN_DISABLE_WSTRING_STORAGE_TYPE=1" )
169+ if (RUNCPP2_WARNINGS_AS_ERRORS)
170+ list (APPEND RUNCPP2_STANDARD_COMPILE_FLAGS "/WX" )
171+ endif ()
172+
173+ message ("RUNCPP2_STANDARD_COMPILE_FLAGS: ${RUNCPP2_STANDARD_COMPILE_FLAGS} " )
162174else ()
163- set (STANDARD_COMPILE_FLAGS "-Wall"
164- "-Wno-return-local-addr"
165- "-Wno-sign-compare"
166- #"-Wno-unused-variable"
167- #"-Wno-unused-but-set-variable"
168- "-Wno-unused-parameter"
169- "-Wno-switch"
170- "-Wno-gnu-zero-variadic-macro-arguments"
171- "-Wextra"
172- "-pedantic"
173- "-Werror" )
175+ set (RUNCPP2_STANDARD_COMPILE_FLAGS "-Wall"
176+ "-Wno-return-local-addr"
177+ "-Wno-sign-compare"
178+ #"-Wno-unused-variable"
179+ #"-Wno-unused-but-set-variable"
180+ "-Wno-unused-parameter"
181+ "-Wno-switch"
182+ "-Wno-gnu-zero-variadic-macro-arguments"
183+ "-Wextra"
184+ "-pedantic" )
185+ if (RUNCPP2_WARNINGS_AS_ERRORS)
186+ list (APPEND RUNCPP2_STANDARD_COMPILE_FLAGS "-Werror" )
187+ endif ()
174188endif ()
175189
176- target_compile_options (runcpp2 PRIVATE "${STANDARD_COMPILE_FLAGS } " )
190+ target_compile_options (runcpp2 PRIVATE "${RUNCPP2_STANDARD_COMPILE_FLAGS } " )
177191
178192# Define the version macro
179193target_compile_definitions (runcpp2 PUBLIC RUNCPP2_VERSION="${RUNCPP2_PROJECT_VERSION} " )
180194
181195add_executable (runcpp2_main "${CMAKE_CURRENT_LIST_DIR} /Src/runcpp2/main.cpp" )
182- target_compile_options (runcpp2_main PRIVATE "${STANDARD_COMPILE_FLAGS } " )
196+ target_compile_options (runcpp2_main PRIVATE "${RUNCPP2_STANDARD_COMPILE_FLAGS } " )
183197target_link_libraries (runcpp2_main PRIVATE runcpp2 ssLogger ghc_filesystem)
184198set_target_properties (runcpp2_main PROPERTIES OUTPUT_NAME "runcpp2" )
185199
0 commit comments