From ad2cb5b7eabd0e4803bdb9402258f0f75c7bd507 Mon Sep 17 00:00:00 2001 From: Zach Hindes Date: Tue, 4 Sep 2018 14:25:15 -0500 Subject: [PATCH] Enable build and test on Windows --- .gitattributes | 2 ++ CMakeLists.txt | 2 ++ tests/CMakeLists.txt | 5 ++++- tests/cjson_add.c | 8 +++++++- tests/unity_setup.c | 3 +++ 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 tests/unity_setup.c diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6e5ee10 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text=auto +/tests/inputs/* text eol=lf \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b347ac9..c9d2db9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,8 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS) /Za /sdl /W4 + /wd4001 + /D_CRT_SECURE_NO_WARNINGS ) endif() endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7967292..6f1688d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ if(ENABLE_CJSON_TEST) - add_library(unity "${CJSON_LIBRARY_TYPE}" unity/src/unity.c) + add_library(unity STATIC unity/src/unity.c) # Disable -Werror for Unity if (FLAG_SUPPORTED_Werror) @@ -72,6 +72,9 @@ if(ENABLE_CJSON_TEST) foreach(unity_test ${unity_tests}) add_executable("${unity_test}" "${unity_test}.c") + if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") + target_sources(${unity_test} PRIVATE unity_setup.c) + endif() target_link_libraries("${unity_test}" "${CJSON_LIB}" unity) if(MEMORYCHECK_COMMAND) add_test(NAME "${unity_test}" diff --git a/tests/cjson_add.c b/tests/cjson_add.c index 01668a9..eb9def2 100644 --- a/tests/cjson_add.c +++ b/tests/cjson_add.c @@ -34,9 +34,15 @@ static void *failing_malloc(size_t size) return NULL; } +/* work around MSVC error C2322: '...' address of dillimport '...' is not static */ +static void CJSON_CDECL normal_free(void *pointer) +{ + free(pointer); +} + static cJSON_Hooks failing_hooks = { failing_malloc, - free + normal_free }; static void cjson_add_null_should_add_null(void) diff --git a/tests/unity_setup.c b/tests/unity_setup.c new file mode 100644 index 0000000..99b6897 --- /dev/null +++ b/tests/unity_setup.c @@ -0,0 +1,3 @@ +// msvc doesn't support weak-linking, so we need to define these functions. +void setUp(void) { } +void tearDown(void) { } \ No newline at end of file