Skip to content

Commit

Permalink
Compatibility with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
slak44 committed Nov 27, 2016
1 parent 7dae13b commit ee2d2c1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 41 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ExternalProject_Add(
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
PATCH_COMMAND patch -p1 < ${PROJECT_SOURCE_DIR}/stringstream_segfault_hack.patch
PATCH_COMMAND patch -p1 < ${PROJECT_SOURCE_DIR}/windows_include_issues.patch
)
include_directories(SYSTEM ${TERMCOLOR_PREFIX}/src/termcolor/include)

Expand Down Expand Up @@ -90,13 +90,19 @@ set(COMMON_SOURCES
${PROJECT_SOURCE_DIR}/runtime/src/io.cpp
)
set(COMMON_DEPS rapidxml termcolor tclap)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -pedantic \
-Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wfloat-equal -Wold-style-cast \
-Wswitch-default -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs \
-Wnoexcept -Woverloaded-virtual -Wredundant-decls -Wstrict-null-sentinel -Wundef \
-Wstrict-overflow=5 -Wuseless-cast -Wzero-as-null-pointer-constant")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -pedantic \
-Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wfloat-equal -Wold-style-cast \
-Wswitch-default -Winit-self -Wlogical-op -Wmissing-declarations \
-Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls \
-Wstrict-null-sentinel -Wundef -Wstrict-overflow=5 -Wuseless-cast \
-Wzero-as-null-pointer-constant")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14 /Wall")
endif()

find_package(LLVM)
if(NOT LLVM_FOUND)
message(FATAL_ERROR "LLVM package can't be found. Set CMAKE_PREFIX_PATH variable to LLVM's installation prefix.")
Expand Down
5 changes: 5 additions & 0 deletions include/llvm/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ friend class OperatorCodegen;
llvm::BasicBlock* compileBlock(Node<BlockNode>::Link node, const std::string& name);
};

#ifdef _MSC_VER
#define __attribute__
#define unused
#endif

/// Used to generate IR for operators
class OperatorCodegen {
friend class CompileVisitor;
Expand Down
10 changes: 8 additions & 2 deletions include/utils/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
#include "util.hpp"
#include "trace.hpp"

#define GET_ERR_METADATA __FILE__, __PRETTY_FUNCTION__, __LINE__
#ifdef _MSC_VER
#define CURRENT_FUNCTION __FUNCSIG__
#else
#define CURRENT_FUNCTION __PRETTY_FUNCTION__
#endif

#define GET_ERR_METADATA __FILE__, CURRENT_FUNCTION, __LINE__
#define ERR_METADATA_TYPES(arg1, arg2, arg3) std::string arg1, std::string arg2, int arg3
#define METADATA_PAIRS_FROM(file, func, line) {"file", file}, {"function", func}, {"line", std::to_string(line)}
#define METADATA_PAIRS {"file", __FILE__}, {"function", __PRETTY_FUNCTION__}, {"line", std::to_string(__LINE__)}
#define METADATA_PAIRS {"file", __FILE__}, {"function", CURRENT_FUNCTION}, {"line", std::to_string(__LINE__)}

/**
\brief Thrown when there is an issue in the user's code.
Expand Down
20 changes: 11 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
add_executable(release_bin ${COMMON_SOURCES} main.cpp)

target_compile_options(release_bin PRIVATE -O3 -g0 -Wdisabled-optimization)
target_link_libraries(release_bin ${REQ_LLVM_LIBRARIES})

add_dependencies(release_bin ${COMMON_DEPS})

make_exe_symlink(release)

add_executable(debug_bin ${COMMON_SOURCES} main.cpp)

target_compile_options(debug_bin PRIVATE -D CRASH_ON_INTERNAL_ERROR -O0 -g3)
if(UNIX)
target_compile_options(release_bin PRIVATE -O3 -g0 -Wdisabled-optimization)
target_compile_options(debug_bin PRIVATE -D CRASH_ON_INTERNAL_ERROR -O0 -g3)
elseif(MSVC)
target_compile_options(release_bin PRIVATE)
target_compile_options(debug_bin PRIVATE /DCRASH_ON_INTERNAL_ERROR )
endif()

target_link_libraries(release_bin ${REQ_LLVM_LIBRARIES})
target_link_libraries(debug_bin ${REQ_LLVM_LIBRARIES})

add_dependencies(release_bin ${COMMON_DEPS})
add_dependencies(debug_bin ${COMMON_DEPS})

make_exe_symlink(release)
make_exe_symlink(debug)
24 changes: 0 additions & 24 deletions stringstream_segfault_hack.patch

This file was deleted.

67 changes: 67 additions & 0 deletions windows_include_issues.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/include/termcolor/termcolor.hpp b/include/termcolor/termcolor.hpp
index 4659afd..6be0a25 100644
--- a/include/termcolor/termcolor.hpp
+++ b/include/termcolor/termcolor.hpp
@@ -26,18 +26,6 @@
#endif


-// This headers provides the `isatty()`/`fileno()` functions,
-// which are used for testing whether a standart stream refers
-// to the terminal. As for Windows, we also need WinApi funcs
-// for changing colors attributes of the terminal.
-#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
-# include <unistd.h>
-#elif defined(TERMCOLOR_OS_WINDOWS)
-# include <io.h>
-# include <windows.h>
-#endif
-
-
#include <iostream>
#include <cstdio>

@@ -45,6 +33,18 @@

namespace termcolor
{
+
+ // This headers provides the `isatty()`/`fileno()` functions,
+ // which are used for testing whether a standart stream refers
+ // to the terminal. As for Windows, we also need WinApi funcs
+ // for changing colors attributes of the terminal.
+ #if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
+ # include <unistd.h>
+ #elif defined(TERMCOLOR_OS_WINDOWS)
+ # include <io.h>
+ # include <windows.h>
+ #endif
+
// Forward declaration of the `_internal` namespace.
// All comments are below.
namespace _internal
@@ -444,12 +444,13 @@ namespace termcolor
inline
bool is_atty(const std::ostream& stream)
{
+ return true;
FILE* std_stream = get_standard_stream(stream);

#if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
- return ::isatty(fileno(std_stream));
+ return isatty(fileno(std_stream));
#elif defined(TERMCOLOR_OS_WINDOWS)
- return ::_isatty(_fileno(std_stream));
+ return _isatty(_fileno(std_stream));
#endif
}

@@ -457,7 +458,7 @@ namespace termcolor
#if defined(TERMCOLOR_OS_WINDOWS)
//! Change Windows Terminal colors attribute. If some
//! parameter is `-1` then attribute won't changed.
- void win_change_attributes(std::ostream& stream, int foreground, int background)
+ inline void win_change_attributes(std::ostream& stream, int foreground, int background)
{
// yeah, i know.. it's ugly, it's windows.
static WORD defaultAttributes = 0;

0 comments on commit ee2d2c1

Please sign in to comment.