Skip to content
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

✨ Adds MSVC support #56

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "src/melon/cJSON"]
path = src/melon/libs/cJSON
url = https://github.com/DaveGamble/cJSON
[submodule "src/melon/libs/dirent"]
path = src/melon/libs/dirent
url = [email protected]:tronkko/dirent.git
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ check_include_file("windows.h" HAVE_WINDOWS)
check_include_file("execinfo.h" HAVE_EXECINFO)

check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RAND)

if (MSVC)
else()
add_definitions(-Werror=incompatible-pointer-types)
add_definitions(-Werror=implicit-function-declaration)
add_definitions(-Werror=return-type)
Expand All @@ -70,6 +71,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()
add_definitions(-Wdouble-promotion)
add_definitions(-Wno-format)
endif()

set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")

Expand All @@ -83,10 +85,13 @@ if (HAVE_STDIO)
set(PLATFORM_SRCS ${PLATFORM_SRCS} src/melon/modules/io/platform/io_os_api_stdio.c)
endif(HAVE_STDIO)

if (HAVE_UNISTD AND HAVE_POSIX_STAT)
if(HAVE_WINDOWS)
message(STATUS "Using Windows API for the FS module")
set(PLATFORM_SRCS ${PLATFORM_SRCS} src/melon/modules/fs/platform/fs_os_api_windows.c)
elseif (HAVE_UNISTD AND HAVE_POSIX_STAT)
message(STATUS "Using POSIX API for the FS module")
set(PLATFORM_SRCS ${PLATFORM_SRCS} src/melon/modules/fs/platform/fs_os_api_posix.c)
endif(HAVE_UNISTD AND HAVE_POSIX_STAT)
endif(HAVE_WINDOWS)

if(HAVE_WINDOWS)
message(STATUS "Using Windows API for the path module")
Expand Down Expand Up @@ -165,9 +170,11 @@ endif()

add_subdirectory(src/melon/libs/cJSON)

if (NOT MSVC)
# Ignores the -Werror in cJSON that
# causes issue with NAN casting in clang
target_compile_options(cjson PRIVATE -Wno-error)
endif (NOT MSVC)

add_library(
external STATIC
Expand Down Expand Up @@ -216,6 +223,11 @@ add_executable(
tests/main.cpp
)

if (MSVC)
target_include_directories(tests PRIVATE src/melon/libs/dirent/include)
endif(MSVC)


if (MINGW)
# On MinGW add static linking of system libraries so that the resulting
# executable is portable.
Expand Down
1 change: 0 additions & 1 deletion src/melon/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#warning Branch predition hinting disabled on this compiler
#define likely(x) do {} while(0)
#define unlikely(x) do {} while(0)
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/melon/core/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#elif defined(unix) || defined(__unix__) || defined(__unix)
#include <time.h>
#include <sys/time.h>
#elif defined(__MINGW32__)
#elif defined(__MINGW32__) || defined(_WIN32)
#include <windows.h>
#endif

Expand Down Expand Up @@ -655,7 +655,7 @@ void melGetTimeHD(MelTimeHD* out)
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
out->nanoSecs = ts.tv_nsec;
out->secs = ts.tv_sec;
#elif defined(__MINGW32__)
#elif defined(__MINGW32__) || defined(_WIN32)
LARGE_INTEGER li;

if(!QueryPerformanceFrequency(&li))
Expand Down
Loading