From 9c7c423247f0dc8da20c584069ef9fb574659564 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sun, 9 Aug 2020 16:14:33 +0900 Subject: [PATCH] Fix build with MS Visual Studio --- CMakeLists.txt | 27 ++++++++++++++++++++++----- src/main.cpp | 17 +++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index baf554b..475ed07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,19 +34,29 @@ set(Triangles_LIB_SOURCES third_party/imgui-sfml/imgui-SFML.cpp ) -set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wsuggest-override") -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") -set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D NDEBUG") +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "/Od /Zi") + set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG") +else() + set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wsuggest-override") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D NDEBUG") +endif() add_library(TrianglesLib STATIC ${Triangles_LIB_SOURCES}) -add_executable(Triangles ${Triangles_MAIN_SOURCES}) +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + add_executable(Triangles WIN32 ${Triangles_MAIN_SOURCES}) +else() + add_executable(Triangles ${Triangles_MAIN_SOURCES}) +endif() target_link_libraries(Triangles PUBLIC TrianglesLib) target_compile_features(TrianglesLib PUBLIC cxx_std_17) -if(BUILD_SHARED_LIBS OR (UNIX AND NOT CYGWIN)) +if(BUILD_SHARED_LIBS OR (UNIX AND NOT CYGWIN) OR (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) find_package(SFML 2 REQUIRED COMPONENTS audio network graphics window system) else() @@ -55,10 +65,17 @@ else() add_definitions(-DSFML_STATIC) endif() +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") +target_link_libraries(TrianglesLib PUBLIC + sfml-graphics sfml-window sfml-system + opengl32 +) +else() target_link_libraries(TrianglesLib PUBLIC sfml-graphics sfml-window sfml-system GL ) +endif() target_include_directories(TrianglesLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src diff --git a/src/main.cpp b/src/main.cpp index 14a1153..8daddfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,22 @@ #include "state.hpp" +#ifdef _MSC_VER +#include "windows.h" + +int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { + // init + Tri::State state(0, nullptr); + + // main loop + while(state.get_flags().test(1)) { + state.handle_events(); + state.update(); + state.draw(); + } + return 0; +} +#else int main(int argc, char **argv) { // init Tri::State state(argc, argv); @@ -20,3 +36,4 @@ int main(int argc, char **argv) { return 0; } +#endif