Skip to content

Initial changes for Windows compatibility #3824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@ check_struct_has_member ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
check_struct_has_member ("struct stat" st_birthtime "sys/types.h;sys/stat.h" HAVE_ST_BIRTHTIME)

message ("-- Looking for libuuid")
if (DARWIN OR FREEBSD OR OPENBSD)
if (WINDOWS)
# Windows has built-in UUID functionality via RPC API
message ("-- Windows detected, using Windows UUID API")
# Add the required Windows libraries for UUID support
set (TASK_LIBRARIES ${TASK_LIBRARIES} rpcrt4)
set (HAVE_UUID_UNPARSE_LOWER TRUE)
# No need to add include dirs as Windows headers are already available
elseif (DARWIN OR FREEBSD OR OPENBSD)
# Apple and FreeBSD include the uuid functions in their libc, rather than libuuid
check_function_exists (uuid_unparse_lower HAVE_UUID_UNPARSE_LOWER)
else (DARWIN OR FREEBSD OR OPENBSD)
else (WINDOWS)
find_path (UUID_INCLUDE_DIR uuid/uuid.h)
find_library (UUID_LIBRARY NAMES uuid)
if (UUID_INCLUDE_DIR AND UUID_LIBRARY)
Expand All @@ -91,7 +98,7 @@ else (DARWIN OR FREEBSD OR OPENBSD)
else (UUID_INCLUDE_DIR AND UUID_LIBRARY)
message (FATAL_ERROR "-- libuuid not found.")
endif (UUID_INCLUDE_DIR AND UUID_LIBRARY)
endif (DARWIN OR FREEBSD OR OPENBSD)
endif (WINDOWS)

if (HAVE_UUID_UNPARSE_LOWER)
message ("-- Found libuuid")
Expand Down
37 changes: 26 additions & 11 deletions cmake/CXXSniffer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ message ("-- System: ${CMAKE_SYSTEM_NAME}")

include (CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG("-std=c++17" _HAS_CXX17)
# Check for MSVC compiler to use the correct flag
if(MSVC)
set(_HAS_CXX17 ON) # MSVC 2019 supports C++17 by default
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
else()
# For GCC, Clang, etc.
CHECK_CXX_COMPILER_FLAG("-std=c++17" _HAS_CXX17)

if (_HAS_CXX17)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_EXTENSIONS OFF)
else (_HAS_CXX17)
message (FATAL_ERROR "C++17 support missing. Try upgrading your C++ compiler. If you have a good reason for using an outdated compiler, please let us know at [email protected].")
endif (_HAS_CXX17)
if (_HAS_CXX17)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_EXTENSIONS OFF)
else (_HAS_CXX17)
message (FATAL_ERROR "C++17 support missing. Try upgrading your C++ compiler. If you have a good reason for using an outdated compiler, please let us know at [email protected].")
endif (_HAS_CXX17)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set (LINUX true)
Expand All @@ -34,9 +43,15 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "GNU")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN")
set (CYGWIN true)
set (CMAKE_CXX_EXTENSIONS ON)
else (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set (WINDOWS true)
# Add Windows-specific flags if needed
else ()
set (UNKNOWN true)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif ()

set (CMAKE_CXX_FLAGS "${_CXX14_FLAGS} ${CMAKE_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wsign-compare -Wreturn-type ${CMAKE_CXX_FLAGS}")
if(NOT MSVC)
# These flags are not applicable to MSVC
set (CMAKE_CXX_FLAGS "${_CXX14_FLAGS} ${CMAKE_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wsign-compare -Wreturn-type ${CMAKE_CXX_FLAGS}")
endif()
2 changes: 1 addition & 1 deletion src/libshared
11 changes: 10 additions & 1 deletion src/recur.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@
#include <Duration.h>
#include <Lexer.h>
#include <format.h>

// Platform-specific includes
#ifdef _WIN32
#include <windows.h>
// Windows-specific user info implementation will be needed
// Create a pwd.h equivalent for Windows
#else
#include <pwd.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and unistd.h, appears to be unused and could just be removed.

#include <sys/types.h>
#include <unistd.h>
#endif

#include <time.h>
#include <unicode.h>
#include <unistd.h>
#include <util.h>

#include <optional>
Expand Down
17 changes: 13 additions & 4 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@
#include <cmake.h>
// cmake.h include header must come first

#include <sys/types.h>

#include <string>
#include <vector>
#if defined(FREEBSD) || defined(OPENBSD)

// Platform-specific UUID handling
#ifdef _WIN32
#include <rpc.h>
#include <windows.h>
// Define uuid_t for Windows compatibility
typedef UUID uuid_t;
#ifndef uuid_unparse_lower
void uuid_unparse_lower(uuid_t uu, char* out);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary if HAVE_UUID_UNPARSE_LOWER is unset correctly.

#endif
#elif defined(FREEBSD) || defined(OPENBSD)
#include <sys/types.h>
#include <uuid.h>
#else
#include <sys/types.h>
#include <uuid/uuid.h>
#endif
#include <Table.h>

// util.cpp
int confirm4(const std::string&);
Expand Down
Loading