From cb6baceea4092b6de75a60f3b70de976b456d2ea Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Wed, 28 Jul 2021 15:03:06 +1000 Subject: [PATCH 1/2] [CMakeLists.txt] Conditionally apply MSVC unsupported `-Wextra`; add `source_group`s [src/{daemon,main,options,utils}.c] MSVC support (WiP); [README.md] Use generator independent build command --- CMakeLists.txt | 7 ++++++- README.md | 2 +- src/daemon.c | 7 +++++++ src/main.c | 9 +++++++++ src/options.c | 8 +++++++- src/utils.c | 5 +++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 566e4d1..11e0550 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,12 +25,14 @@ set(VIOLET_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/options.c ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.c ) +source_group("Source Files" FILES "${VIOLET_SOURCES}") set(VIOLET_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/daemon.h ${CMAKE_CURRENT_SOURCE_DIR}/src/options.h ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.h ) +source_group("Header Files" FILES "${VIOLET_HEADERS}") add_executable(violet ${VIOLET_HEADERS} ${VIOLET_SOURCES}) target_compile_definitions(violet PRIVATE VIOLET_VERSION="${PROJECT_VERSION}") @@ -42,7 +44,10 @@ target_link_libraries(violet PRIVATE LibJuice::LibJuiceStatic) install(TARGETS violet RUNTIME DESTINATION bin) -target_compile_options(violet PRIVATE -Wall -Wextra) +target_compile_options(violet PRIVATE -Wall) +if (NOT MSVC) + target_compile_options(violet PRIVATE -Wextra) +endif() if(WARNINGS_AS_ERRORS) target_compile_options(violet PRIVATE -Werror) diff --git a/README.md b/README.md index 80b7cd9..0c8a493 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ $ git submodule update --init --recursive ```bash $ cmake -B build $ cd build -$ make -j2 +$ cmake --build . ``` ## Running diff --git a/src/daemon.c b/src/daemon.c index e4f39ed..b64d4d6 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -19,7 +19,14 @@ #include #include #include + +#ifdef _MSC_VER +//#include +typedef unsigned long DWORD; +typedef DWORD pid_t; +#else #include +#endif static void signal_handler(int sig) { (void)sig; } diff --git a/src/main.c b/src/main.c index 0a1f10b..5eb1486 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,12 @@ #include #include #include +#ifdef _MSC_VER +#include +#define localtime_r(timer, buf) localtime_s(buf, timer) +#else #include +#endif static FILE *log_file = NULL; @@ -85,7 +90,11 @@ int main(int argc, char *argv[]) { goto error; } +#ifdef _MSC_VER + SuspendThread(/*TODO*/); +#else pause(); +#endif juice_server_destroy(server); diff --git a/src/options.c b/src/options.c index b406c57..24a30ab 100644 --- a/src/options.c +++ b/src/options.c @@ -20,13 +20,19 @@ #include "utils.h" #include -#include #include #include #include #include #include +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; +#else +#include +#endif + static char *alloc_string_copy(const char *src, size_t max) { if (!src) return NULL; diff --git a/src/utils.c b/src/utils.c index d9bf1d1..7cc2e45 100644 --- a/src/utils.c +++ b/src/utils.c @@ -18,7 +18,12 @@ #include "utils.h" +#ifdef _MSC_VER +#include +#define strcasecmp _stricmp +#else #include +#endif const char *log_level_to_string(juice_log_level_t level) { switch (level) { From 296be1763d9d43610c35fbbea0d8b315b680433e Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Wed, 28 Jul 2021 22:29:03 +1000 Subject: [PATCH 2/2] Update CMakeLists.txt Co-authored-by: Paul-Louis Ageneau --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11e0550..4c9af75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,9 @@ if (NOT MSVC) endif() if(WARNINGS_AS_ERRORS) - target_compile_options(violet PRIVATE -Werror) +if(MSVC) + target_compile_options(violet PRIVATE /WX) +else() + target_compile_options(violet PRIVATE -Werror) +endif() endif() -