diff --git a/CMakeLists.txt b/CMakeLists.txt index aff0da6f..231fab31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) project(PatternLanguage) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) option(LIBPL_SHARED_LIBRARY "Compile the library as a shared library" OFF) +option(LIBPL_WARNINGS_AS_ERRORS "Treat warnings as errors" ${PROJECT_IS_TOP_LEVEL}) option(LIBPL_ENABLE_TESTS "Enable testing" OFF) option(LIBPL_ENABLE_CLI "Enable building the CLI tool" ON) option(LIBPL_BUILD_CLI_AS_EXECUTABLE "Build the CLI tool as an executable" ON) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 163eded2..da89e2f1 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -31,8 +31,15 @@ else() find_package(CLI11 CONFIG QUIET) endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - target_compile_options(plcli PRIVATE -Wall -Wextra -Werror -Wno-unknown-pragmas -Wno-array-bounds) +if(MSVC) + if (LIBPL_WARNINGS_AS_ERRORS) + target_compile_options(plcli PRIVATE /WX) + endif() +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(plcli PRIVATE -Wall -Wextra -Wno-unknown-pragmas -Wno-array-bounds) + if (LIBPL_WARNINGS_AS_ERRORS) + target_compile_options(plcli PRIVATE -Werror) + endif() endif() target_include_directories(plcli PUBLIC include ${CLI11_INCLUDE_DIRS}) target_link_libraries(plcli PRIVATE ${CLI11_LIBRARIES} ${NLOHMANN_JSON_LIBRARIES} libwolv libpl_includes libpl-gen ${FMT_LIBRARIES}) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b1935689..4c35dd73 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -88,10 +88,16 @@ if (LIBPL_ENABLE_PRECOMPILED_HEADERS) ) endif () -if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") +if (MSVC) target_compile_options(libpl PRIVATE /EHsc) + if (LIBPL_WARNINGS_AS_ERRORS) + target_compile_options(libpl PRIVATE /WX) + endif() elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - target_compile_options(libpl PRIVATE -Wall -Wextra -Werror -Wpedantic -Wno-unknown-pragmas -Wno-array-bounds) + target_compile_options(libpl PRIVATE -Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-array-bounds) + if (LIBPL_WARNINGS_AS_ERRORS) + target_compile_options(libpl PRIVATE -Werror) + endif() if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(libpl PRIVATE -Wno-stringop-overflow) endif() diff --git a/lib/source/pl/lib/std/time.cpp b/lib/source/pl/lib/std/time.cpp index 11a05b70..94461b12 100644 --- a/lib/source/pl/lib/std/time.cpp +++ b/lib/source/pl/lib/std/time.cpp @@ -67,8 +67,15 @@ namespace pl::lib::libstd::time { auto time = time_t(params[0].toUnsigned()); try { +#ifdef _MSC_VER + std::tm localTimeBuf{}; + if(localtime_s(&localTimeBuf, &time) != 0) + return u128(0); + auto localTime = &localTimeBuf; +#else auto localTime = std::localtime(&time); if (localTime == nullptr) return u128(0); +#endif // _MSC_VER return { packTMValue(*localTime, runtime) }; } catch (const fmt::format_error&) { @@ -81,8 +88,15 @@ namespace pl::lib::libstd::time { auto time = time_t(params[0].toUnsigned()); try { +#ifdef _MSC_VER + std::tm gmTimeBuf{}; + if(gmtime_s(&gmTimeBuf, &time) != 0) + return u128(0); + auto gmTime = &gmTimeBuf; +#else auto gmTime = std::gmtime(&time); if (gmTime == nullptr) return u128(0); +#endif // _MSC_VER return { packTMValue(*gmTime, runtime) }; } catch (const fmt::format_error&) {