Improve MSVC builds
This commit is contained in:
parent
0babf5193b
commit
412e0355a4
6 changed files with 47 additions and 9 deletions
|
@ -3,9 +3,13 @@
|
||||||
########################################################################
|
########################################################################
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
# Fix behavior of CMAKE_C_STANDARD when targeting macOS.
|
# Fix behavior of CMAKE_C_STANDARD when targeting macOS.
|
||||||
if (POLICY CMP0025)
|
if(POLICY CMP0025)
|
||||||
cmake_policy(SET CMP0025 NEW)
|
cmake_policy(SET CMP0025 NEW)
|
||||||
endif ()
|
endif()
|
||||||
|
# Only interpret if() arguments as variables or keywords when unquoted.
|
||||||
|
if(POLICY CMP0054)
|
||||||
|
cmake_policy(SET CMP0054 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
project(rtl433 C)
|
project(rtl433 C)
|
||||||
|
|
||||||
|
@ -40,7 +44,7 @@ endif()
|
||||||
########################################################################
|
########################################################################
|
||||||
set(CMAKE_C_EXTENSIONS OFF)
|
set(CMAKE_C_EXTENSIONS OFF)
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
if (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") AND NOT WIN32)
|
if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") AND NOT WIN32)
|
||||||
ADD_DEFINITIONS(-Wall)
|
ADD_DEFINITIONS(-Wall)
|
||||||
ADD_DEFINITIONS(-Wextra)
|
ADD_DEFINITIONS(-Wextra)
|
||||||
ADD_DEFINITIONS(-Wsign-compare)
|
ADD_DEFINITIONS(-Wsign-compare)
|
||||||
|
@ -59,11 +63,18 @@ if (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES
|
||||||
# CMake Debug default for GCC/Clang is "-g -DNDEBUG"
|
# CMake Debug default for GCC/Clang is "-g -DNDEBUG"
|
||||||
# set(CMAKE_C_FLAGS_DEBUG -g3 -O0)
|
# set(CMAKE_C_FLAGS_DEBUG -g3 -O0)
|
||||||
endif()
|
endif()
|
||||||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
||||||
# make sure we don't accidentally copy more than an int
|
# make sure we don't accidentally copy more than an int
|
||||||
ADD_DEFINITIONS(-Wlarge-by-value-copy=8)
|
ADD_DEFINITIONS(-Wlarge-by-value-copy=8)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Shut MSVC up about strdup and strtok
|
||||||
|
if(MSVC)
|
||||||
|
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
|
||||||
|
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
ADD_DEFINITIONS(-DNOMINMAX)
|
||||||
|
endif()
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# Find build dependencies
|
# Find build dependencies
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -104,7 +115,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Profile")
|
||||||
ADD_DEFINITIONS(-fno-builtin-free)
|
ADD_DEFINITIONS(-fno-builtin-free)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MINGW)
|
if(MINGW OR MSVC)
|
||||||
list(APPEND NET_LIBRARIES ws2_32 mswsock)
|
list(APPEND NET_LIBRARIES ws2_32 mswsock)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
// Helper macros
|
// Helper macros, collides with MSVC's stdlib.h unless NOMINMAX is used
|
||||||
#ifndef max
|
#ifndef max
|
||||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -125,13 +125,18 @@ add_executable(rtl_433
|
||||||
devices/x10_sec.c
|
devices/x10_sec.c
|
||||||
)
|
)
|
||||||
|
|
||||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||||
SET_SOURCE_FILES_PROPERTIES(mongoose.c PROPERTIES COMPILE_FLAGS "-Wno-format")
|
SET_SOURCE_FILES_PROPERTIES(mongoose.c PROPERTIES COMPILE_FLAGS "-Wno-format")
|
||||||
endif()
|
endif()
|
||||||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
||||||
SET_SOURCE_FILES_PROPERTIES(mongoose.c PROPERTIES COMPILE_FLAGS "-Wno-format-pedantic -Wno-large-by-value-copy")
|
SET_SOURCE_FILES_PROPERTIES(mongoose.c PROPERTIES COMPILE_FLAGS "-Wno-format-pedantic -Wno-large-by-value-copy")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
# needs CMake 3.1 but Windows builds should have that
|
||||||
|
target_sources(rtl_433 PRIVATE getopt/getopt.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(data data.c abuf.c term_ctl.c mongoose.c)
|
add_library(data data.c abuf.c term_ctl.c mongoose.c)
|
||||||
target_link_libraries(data ${NET_LIBRARIES})
|
target_link_libraries(data ${NET_LIBRARIES})
|
||||||
|
|
||||||
|
|
|
@ -766,6 +766,8 @@ static void data_output_csv_start(struct data_output *output, const char **field
|
||||||
csv->separator = ",";
|
csv->separator = ",";
|
||||||
|
|
||||||
allowed = calloc(num_fields, sizeof(const char *));
|
allowed = calloc(num_fields, sizeof(const char *));
|
||||||
|
if (!allowed)
|
||||||
|
goto alloc_error;
|
||||||
memcpy(allowed, fields, sizeof(const char *) * num_fields);
|
memcpy(allowed, fields, sizeof(const char *) * num_fields);
|
||||||
|
|
||||||
qsort(allowed, num_fields, sizeof(char *), compare_strings);
|
qsort(allowed, num_fields, sizeof(char *), compare_strings);
|
||||||
|
|
|
@ -50,13 +50,17 @@
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include "getopt/getopt.h"
|
|
||||||
#define F_OK 0
|
#define F_OK 0
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#else
|
||||||
|
#include "getopt/getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GIT_VERSION
|
#ifdef GIT_VERSION
|
||||||
|
|
|
@ -15,7 +15,23 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <BaseTsd.h>
|
||||||
|
typedef SSIZE_T ssize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define F_OK 0
|
||||||
|
#define R_OK (1 << 2)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifndef _MSC_VER
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "baseband.h"
|
#include "baseband.h"
|
||||||
|
|
Loading…
Add table
Reference in a new issue