From 4b161eb3a63649554f96f4b2e9a302445f5383fe Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Tue, 25 Jun 2019 22:41:33 +0200 Subject: [PATCH] Fix build under Visual Studio 2017 Add a few defines and make 'main' functions extern "C" (see SDL_main.h) to fix the build under Visual Studio 2017. Signed-off-by: Paul Cercueil --- CMakeLists.txt | 12 ++++++++++++ src/main.cpp | 2 +- src/modelcompiler.cpp | 2 +- src/savegamedump.cpp | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0597b33cb..5018ed520 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,14 @@ if (WIN32) set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX}) endif (WIN32) +if (MSVC) + # Avoid annoying warnings from Visual Studio + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + + # Use M_PI/M_E macros from math.h + add_definitions(-D_USE_MATH_DEFINES -DHAVE_M_PI) +endif (MSVC) + if (APPLE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gnu") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu") @@ -171,6 +179,10 @@ if (NOT USE_SYSTEM_LIBGLEW) add_subdirectory(contrib/glew) add_library(GLEW::GLEW ALIAS glew) include_directories(contrib/glew) + + # Specify that we compile against a static build of Glew + # (required on Windows) + add_definitions(-DGLEW_STATIC) endif (NOT USE_SYSTEM_LIBGLEW) add_subdirectory(contrib/imgui) add_subdirectory(contrib/jenkins) diff --git a/src/main.cpp b/src/main.cpp index a37a4407b..2bcb1e14e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ enum RunMode { MODE_USAGE_ERROR }; -int main(int argc, char **argv) +extern "C" int main(int argc, char **argv) { #ifdef PIONEER_PROFILER Profiler::detect(argc, argv); diff --git a/src/modelcompiler.cpp b/src/modelcompiler.cpp index c205ac982..bd65df9e2 100644 --- a/src/modelcompiler.cpp +++ b/src/modelcompiler.cpp @@ -158,7 +158,7 @@ enum RunMode { static FileSystem::FileSourceFS customDataDir("."); -int main(int argc, char **argv) +extern "C" int main(int argc, char **argv) { #ifdef PIONEER_PROFILER Profiler::detect(argc, argv); diff --git a/src/savegamedump.cpp b/src/savegamedump.cpp index d41e00855..20eb9c044 100644 --- a/src/savegamedump.cpp +++ b/src/savegamedump.cpp @@ -4,8 +4,9 @@ #include "FileSystem.h" #include "GZipFormat.h" #include "Json.h" +#include -int main(int argc, const char **argv) +extern "C" int main(int argc, char **argv) { if (argc < 2 || argc > 3) { printf(