From 052a7244620f3ed7a55a6be521b84762315555f3 Mon Sep 17 00:00:00 2001
From: TheNumbat <mjslater@andrew.cmu.edu>
Date: Tue, 16 Feb 2021 11:50:52 -0500
Subject: [PATCH] improve build system

---
 CMU462/CMakeLists.txt              | 13 ++++++-------
 CMU462/deps/glew/CMakeLists.txt    |  3 +--
 CMU462/deps/glfw/CMakeLists.txt    |  8 ++++----
 CMU462/src/color.cpp               | 16 ++++++++--------
 CMakeLists.txt                     |  7 ++++---
 runcmake_win.bat                   |  8 +++++++-
 src/CMakeLists.txt                 | 14 +++++++++++++-
 src/hardware/hardware_renderer.cpp | 12 ++++--------
 8 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/CMU462/CMakeLists.txt b/CMU462/CMakeLists.txt
index d0252c7..53c105c 100644
--- a/CMU462/CMakeLists.txt
+++ b/CMU462/CMakeLists.txt
@@ -45,7 +45,7 @@ if(APPLE)
 
       set(CLANG_CXX_FLAGS "-std=c++11 -m64")
 
-      if(CMU462_BUILD_DEBUG)
+      if(CMU462_BUILD_DEBUG OR CMAKE_BUILD_TYPE MATCHES "Debug")
         set(CMAKE_BUILD_TYPE Debug)
       else(CMU462_BUILD_DEBUG)
         set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -O3")
@@ -63,7 +63,7 @@ if(APPLE)
 
       set(GCC_CXX_FLAGS "-std=gnu++11 -m64")
 
-      if(CMU462_BUILD_DEBUG)
+      if(CMU462_BUILD_DEBUG OR CMAKE_BUILD_TYPE MATCHES "Debug")
         set(CMAKE_BUILD_TYPE Debug)
       else(CMU462_BUILD_DEBUG)
         set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -O3")
@@ -81,7 +81,10 @@ endif(APPLE)
 ##################
 # Build on Linux #
 ##################
-set(LINUX UNIX AND NOT APPLE)
+if(UNIX AND NOT APPLE)
+  set(LINUX)
+endif()
+
 if(LINUX)
 
   # GCC only
@@ -126,8 +129,6 @@ if(WIN32)
 
   if(MSVC)
 
-    set(MSVC_CXX_FLAGS "-std=gnu++11")
-
     if(CMU462_BUILD_DEBUG)
         set(CMAKE_BUILD_TYPE Debug)
     else(CMU462_BUILD_DEBUG)
@@ -141,8 +142,6 @@ if(WIN32)
 
   if(MINGW)
 
-    set(MSVC_CXX_FLAGS "-std=gnu++11")
-
     if(CMU462_BUILD_DEBUG)
         set(CMAKE_BUILD_TYPE Debug)
     else(CMU462_BUILD_DEBUG)
diff --git a/CMU462/deps/glew/CMakeLists.txt b/CMU462/deps/glew/CMakeLists.txt
index bc0afce..1fa28e2 100644
--- a/CMU462/deps/glew/CMakeLists.txt
+++ b/CMU462/deps/glew/CMakeLists.txt
@@ -7,8 +7,7 @@ include_directories(${GLEW_HEADER_DIR})
 
 add_library(glew 
 ${GLEW_SOURCE_DIR}/glew.c
-${GLEW_SOURCE_DIR}/glewinfo.c
-${GLEW_SOURCE_DIR}/visualinfo.c)
+${GLEW_SOURCE_DIR}/glewinfo.c)
 
 set(GLEW_LIBRARIES glew PARENT_SCOPE)
 set(GLEW_INCLUDE_DIRS ${GLEW_HEADER_DIR} PARENT_SCOPE)
diff --git a/CMU462/deps/glfw/CMakeLists.txt b/CMU462/deps/glfw/CMakeLists.txt
index b1476bd..b915b58 100644
--- a/CMU462/deps/glfw/CMakeLists.txt
+++ b/CMU462/deps/glfw/CMakeLists.txt
@@ -21,10 +21,10 @@ set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
 option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
-option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON)
-option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON)
-option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON)
-option(GLFW_INSTALL "Generate installation target" ON)
+option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
+option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
+option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF)
+option(GLFW_INSTALL "Generate installation target" OFF)
 option(GLFW_VULKAN_STATIC "Use the Vulkan loader statically linked into application" OFF)
 option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF)
 
diff --git a/CMU462/src/color.cpp b/CMU462/src/color.cpp
index 703a842..0c8ef6d 100644
--- a/CMU462/src/color.cpp
+++ b/CMU462/src/color.cpp
@@ -14,11 +14,11 @@ const Color Color::White  = Color(1,1,1,1);
 const Color Color::Black  = Color(0,0,0,1);
 
 Color::Color( const unsigned char* arr ) {
-  float inv = 1.0 / 255.0;
+  float inv = 1.0f / 255.0f;
   r = arr[0] * inv;
   g = arr[1] * inv;
   b = arr[2] * inv;
-  a = 1.0;
+  a = 1.0f;
 }
 
 Color Color::fromHex( const char* s ) {
@@ -44,18 +44,18 @@ Color Color::fromHex( const char* s ) {
 
   // Extract 8-byte chunks and normalize.
   Color c;
-  c.r = (float)( ( rgb & 0xFF0000 ) >> 16 ) / 255.0;
-  c.g = (float)( ( rgb & 0x00FF00 ) >>  8 ) / 255.0;
-  c.b = (float)( ( rgb & 0x0000FF ) >>  0 ) / 255.0;
+  c.r = (float)( ( rgb & 0xFF0000 ) >> 16 ) / 255.0f;
+  c.g = (float)( ( rgb & 0x00FF00 ) >>  8 ) / 255.0f;
+  c.b = (float)( ( rgb & 0x0000FF ) >>  0 ) / 255.0f;
   c.a = 1.0; // set alpha to 1 (opaque) by default
 
   return c;
 }
 
 string Color::toHex( void ) const {
-  int R = (unsigned char) max( 0., min( 255.0, 255.0 * r ));
-  int G = (unsigned char) max( 0., min( 255.0, 255.0 * g ));
-  int B = (unsigned char) max( 0., min( 255.0, 255.0 * b ));
+  int R = (unsigned char) max( 0.f, min( 255.0f, 255.0f * r ));
+  int G = (unsigned char) max( 0.f, min( 255.0f, 255.0f * g ));
+  int B = (unsigned char) max( 0.f, min( 255.0f, 255.0f * b ));
 
   stringstream ss;
   ss << hex;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2e1ca7c..5186b72 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,7 +33,7 @@ if(APPLE)
 
     set(CLANG_CXX_FLAGS "-std=c++11 -m64")
 
-    if(BUILD_DEBUG)
+    if(BUILD_DEBUG OR CMAKE_BUILD_TYPE MATCHES "Debug")
       set(CMAKE_BUILD_TYPE Debug)
     else(BUILD_DEBUG)
       set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -O3")
@@ -67,7 +67,9 @@ endif(APPLE)
 ##################
 # Build on Linux #
 ##################
-set(LINUX UNIX AND NOT APPLE)
+if(UNIX AND NOT APPLE)
+  set(LINUX)
+endif()
 if(LINUX)
 
   # GCC only
@@ -112,7 +114,6 @@ if(WIN32)
 
   if(MSVC)
 
-    set(MSVC_CXX_FLAGS "-std=gnu++11")
     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD")
 
diff --git a/runcmake_win.bat b/runcmake_win.bat
index fd39383..cf53c06 100644
--- a/runcmake_win.bat
+++ b/runcmake_win.bat
@@ -1,8 +1,14 @@
 @echo off
+if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" (
 call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" > NUL 2> NUL
+) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat" (
+call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat" > NUL 2> NUL
+) else (
+  rem "Could not find visual studio C++ build environment."
+)
 mkdir build
 pushd build
-cmake ..
+cmake -A x64 ..
 if "%1"=="configure" exit
 if [%1]==[] (cmake --build . --config RelWithDebInfo)
 if not [%1]==[] (cmake --build . --config %1)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0e58716..9a992db 100755
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -83,7 +83,19 @@ if (APPLE) # Frameworks required on osx
     ${IOKIT_LIBRARIES}
     ${COREVIDEO_LIBRARIES}
   )
-else(UNIX)  #LINUX
+endif()
+
+if(WIN32)
+target_link_libraries( drawsvg drawsvg_hdwr drawsvg_ref
+    ${CMU462_LIBRARIES}
+    ${GLEW_LIBRARIES}
+    ${GLFW_LIBRARIES}
+    ${FREETYPE_LIBRARIES}
+    ${OPENGL_LIBRARIES}
+)
+endif()
+
+if(UNIX AND NOT APPLE)  #LINUX
 target_link_libraries( drawsvg drawsvg_hdwr drawsvg_ref
     ${CMU462_LIBRARIES}
     ${GLEW_LIBRARIES}
diff --git a/src/hardware/hardware_renderer.cpp b/src/hardware/hardware_renderer.cpp
index 580986e..654fdb5 100755
--- a/src/hardware/hardware_renderer.cpp
+++ b/src/hardware/hardware_renderer.cpp
@@ -63,16 +63,12 @@ void HardwareRenderer::draw_svg( SVG& svg ) {
   Vector2D c = transform(Vector2D(    0    ,svg.height)); c.x--; c.y++;
   Vector2D d = transform(Vector2D(svg.width,svg.height)); d.x++; d.y++;
 
-  rasterize_line(a.x, a.y, b.x, b.y, Color::Black);
-  rasterize_line(a.x, a.y, c.x, c.y, Color::Black);
-  rasterize_line(d.x, d.y, b.x, b.y, Color::Black);
-  rasterize_line(d.x, d.y, c.x, c.y, Color::Black);
-
-  // resolve and send to render target
-  // resolve();
+  rasterize_line((float)a.x, (float)a.y, (float)b.x, (float)b.y, Color::Black);
+  rasterize_line((float)a.x, (float)a.y, (float)c.x, (float)c.y, Color::Black);
+  rasterize_line((float)d.x, (float)d.y, (float)b.x, (float)b.y, Color::Black);
+  rasterize_line((float)d.x, (float)d.y, (float)c.x, (float)c.y, Color::Black);
 
   leave2DDrawing();
-
 }
 
 void HardwareRenderer::draw_element( SVGElement* element ) {
-- 
GitLab