Skip to content

Commit

Permalink
Fix cmake build on windows. (#34214)
Browse files Browse the repository at this point in the history
This fixes several minor issues:

- platform_win.h needs to be included before SDL stuff, otherwise
  you get seemingly unrelated errors. This happened to work in VS
  solution because it force-includes stdafx.h everywhere. However
  stdafx.h should only be used as an optimization measure, and not
  to guarantee correctness

- The binary currently does not use SDL2main helper, and instead
  defines all initialization in WinMain itself. I didn't try searching
  for the specific commit, but according to comments in Makefile,
  this is a deliberate change.
  VS solution defines USE_WINMAIN unconditionally, so let's use it
  in cmake as well.

- WinMain, as defined currently, has its arguments unused, which
  makes g++ complain, and fail due to -Werror.
  Removed the comments

- Mostly unrelated, and not strictly necessary: the "idiomatic"
  way to require a C++ standard in cmake is
  `SET(CMAKE_CXX_STANDARD 14)`, which is very slightly preferred over
  `SET(CMAKE_CXX_FLAGS -std=c++14)` due to cross-platform
  considerations.
  The option is present since at least CMake 3.1.3, released
  in february 2015. This is only 3 months later than C++14 release,
  so the version bump should not be problematic.
  • Loading branch information
moxian authored and kevingranade committed Sep 25, 2019
1 parent 3ba9027 commit 01c0399
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Main project build script
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.1.4)

PROJECT(CataclysmDDA)

Expand Down Expand Up @@ -225,10 +225,12 @@ ELSE()
-Wpedantic")
# Compact the whitespace in the warning string
string(REGEX REPLACE "[\t ]+" " " CATA_WARNINGS "${CATA_WARNINGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CATA_WARNINGS} -std=c++14")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CATA_WARNINGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
ENDIF()

SET(CMAKE_CXX_STANDARD 14)

# Force out-of-source build
IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
MESSAGE(FATAL_ERROR
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ IF(TILES)
target_include_directories(libcataclysm-tiles INTERFACE ${CMAKE_SOURCE_DIR}/src)

IF(WIN32)
ADD_DEFINITIONS(-DUSE_WINMAIN)
ADD_EXECUTABLE(cataclysm-tiles WIN32
${MAIN_CPP}
${RESOURCE_RC}
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ void printHelpMessage( const arg_handler *first_pass_arguments, size_t num_first
} // namespace

#if defined(USE_WINMAIN)
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
int APIENTRY WinMain( HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */,
LPSTR /* lpCmdLine */, int /* nCmdShow */ )
{
int argc = __argc;
char **argv = __argv;
Expand Down
1 change: 1 addition & 0 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <type_traits>
#include <tuple>

#include "platform_win.h"
#if defined(_MSC_VER) && defined(USE_VCPKG)
# include <SDL2/SDL_image.h>
# include <SDL2/SDL_syswm.h>
Expand Down

0 comments on commit 01c0399

Please sign in to comment.