Fix build with MS Visual Studio

This commit is contained in:
Stephen Seo 2020-08-09 16:14:33 +09:00
parent 674ffce5d4
commit 9c7c423247
2 changed files with 39 additions and 5 deletions

View file

@ -34,19 +34,29 @@ set(Triangles_LIB_SOURCES
third_party/imgui-sfml/imgui-SFML.cpp third_party/imgui-sfml/imgui-SFML.cpp
) )
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 "-Wall -Wextra -Wpedantic -Wsuggest-override")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D NDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D NDEBUG")
endif()
add_library(TrianglesLib STATIC ${Triangles_LIB_SOURCES}) add_library(TrianglesLib STATIC ${Triangles_LIB_SOURCES})
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_executable(Triangles WIN32 ${Triangles_MAIN_SOURCES})
else()
add_executable(Triangles ${Triangles_MAIN_SOURCES}) add_executable(Triangles ${Triangles_MAIN_SOURCES})
endif()
target_link_libraries(Triangles PUBLIC TrianglesLib) target_link_libraries(Triangles PUBLIC TrianglesLib)
target_compile_features(TrianglesLib PUBLIC cxx_std_17) 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 find_package(SFML 2 REQUIRED
COMPONENTS audio network graphics window system) COMPONENTS audio network graphics window system)
else() else()
@ -55,10 +65,17 @@ else()
add_definitions(-DSFML_STATIC) add_definitions(-DSFML_STATIC)
endif() 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 target_link_libraries(TrianglesLib PUBLIC
sfml-graphics sfml-window sfml-system sfml-graphics sfml-window sfml-system
GL GL
) )
endif()
target_include_directories(TrianglesLib PUBLIC target_include_directories(TrianglesLib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src

View file

@ -7,6 +7,22 @@
#include "state.hpp" #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) { int main(int argc, char **argv) {
// init // init
Tri::State state(argc, argv); Tri::State state(argc, argv);
@ -20,3 +36,4 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
#endif