Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
11 changes: 9 additions & 2 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
10 changes: 8 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions lib/source/pl/lib/std/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&) {
Expand All @@ -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&) {
Expand Down
Loading