Skip to content

Commit 60ea4b2

Browse files
committed
Merge pull request ReadyTalk#317 from joshuawarner32/cmake-vs
Get cmake build working with visual studio 2013
2 parents 9f182d4 + e92230c commit 60ea4b2

File tree

20 files changed

+117
-194
lines changed

20 files changed

+117
-194
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ add_definitions (
1616
-D__STDC_CONSTANT_MACROS
1717
)
1818

19-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -fno-exceptions -std=c++0x")
20-
2119
include ("cmake/Platform.cmake")
20+
21+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}")
22+
2223
include (CTest)
2324

2425
# Sadly, we can't use the 'test' target, as that's coopted by ctest

classpath/java-lang.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
There is NO WARRANTY for this software. See license.txt for
99
details. */
1010

11-
#include "math.h"
1211
#include "stdlib.h"
1312
#include "time.h"
1413
#include "string.h"
@@ -19,6 +18,11 @@
1918
#include "fcntl.h"
2019
#include "ctype.h"
2120

21+
// Make sure M_* constants (in particular M_E) are exposed in math.h.
22+
// This was a problem on the default mingw install on ubuntu precise
23+
#undef __STRICT_ANSI__
24+
#include "math.h"
25+
2226
#ifdef PLATFORM_WINDOWS
2327

2428
#include "windows.h"

cmake/Platform.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ IF (APPLE)
66

77
SET(PLATFORM_LIBS ${CORE_FOUNDATION_LIBRARY})
88
ENDIF()
9+
10+
IF (MSVC)
11+
SET(PLATFORM_CXX_FLAGS "/Wall")
12+
ELSE()
13+
SET(PLATFORM_CXX_FLAGS "-Wall -Werror -fno-exceptions -std=c++0x")
14+
SET(PLATFORM_LIBS ${PLATFORM_LIBS} pthread dl)
15+
ENDIF()
16+
17+
find_package(ZLIB REQUIRED)
18+
include_directories(${ZLIB_INCLUDE_DIRS})

include/avian/codegen/compiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ class Args {
3232

3333
template <class... Ts>
3434
Args(Ts... ts)
35+
#ifndef _MSC_VER
3536
: values{ts...}
37+
#endif
3638
{
39+
#ifdef _MSC_VER
40+
setArrayElements(values, ts...);
41+
#endif
3742
}
3843

3944
operator util::Slice<ir::Value*>()

include/avian/util/cpp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ struct ArgumentCount<> {
4444
enum { Result = 0 };
4545
};
4646

47+
template<class T>
48+
void setArrayElements(T*) {
49+
}
50+
51+
template<class T, class... Ts>
52+
void setArrayElements(T* arr, T elem, Ts... ts) {
53+
*arr = elem;
54+
setArrayElements(arr, ts...);
55+
}
56+
4757
} // namespace util
4858
} // namespace avian
4959

src/avian/common.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,9 @@
3939

4040
#define strncasecmp _strnicmp
4141

42-
#define FP_NAN 0
43-
#define FP_INFINITE 1
4442
#define FP_UNDEF 2
4543

46-
inline int fpclassify(double d)
47-
{
48-
switch (_fpclass(d)) {
49-
case _FPCLASS_SNAN:
50-
case _FPCLASS_QNAN:
51-
return FP_NAN;
52-
case _FPCLASS_PINF:
53-
case _FPCLASS_NINF:
54-
return FP_INFINITE;
55-
}
56-
return FP_UNDEF;
57-
}
58-
59-
inline int signbit(double d)
60-
{
61-
return _copysign(1.0, d) < 0;
62-
}
63-
64-
#define not!
44+
#define not !
6545
#define or ||
6646
#define and &&
6747
#define xor ^

src/codegen/target/x86/detect.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,39 @@
1313

1414
#include "context.h"
1515

16+
#ifndef _MSC_VER
17+
#include <cpuid.h>
18+
#else
19+
// MSVC implementation:
20+
static int __get_cpuid(unsigned int __level,
21+
unsigned int* __eax,
22+
unsigned int* __ebx,
23+
unsigned int* __ecx,
24+
unsigned int* __edx)
25+
{
26+
_asm
27+
{
28+
mov eax, __level;
29+
cpuid;
30+
mov[__eax], eax;
31+
mov[__ebx], ebx;
32+
mov[__ecx], ecx;
33+
mov[__edx], edx;
34+
}
35+
return 1;
36+
}
37+
#define bit_SSE (1 << 25)
38+
#define bit_SSE2 (1 << 26)
39+
40+
#endif
41+
1642
namespace avian {
1743
namespace codegen {
1844
namespace x86 {
1945

20-
extern "C" bool detectFeature(unsigned ecx, unsigned edx);
46+
// TODO: this should be moved such that it's called by the client (e.g. whatever
47+
// allocates the Archivecture). That way, we can link the x86 code generator on
48+
// another architecture (e.g. arm).
2149

2250
bool useSSE(ArchitectureContext* c)
2351
{
@@ -27,8 +55,11 @@ bool useSSE(ArchitectureContext* c)
2755
} else if (c->useNativeFeatures) {
2856
static int supported = -1;
2957
if (supported == -1) {
30-
supported = detectFeature(0, 0x2000000) // SSE 1
31-
and detectFeature(0, 0x4000000); // SSE 2
58+
unsigned eax;
59+
unsigned ebx;
60+
unsigned ecx;
61+
unsigned edx;
62+
supported = __get_cpuid(1, &eax, &ebx, &ecx, &edx) && (edx & bit_SSE) && (edx & bit_SSE2);
3263
}
3364
return supported;
3465
} else {

src/interpret.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ object interpret3(Thread* t, const int base)
12881288
}
12891289
goto loop;
12901290

1291-
case dup: {
1291+
case vm::dup: {
12921292
if (DebugStack) {
12931293
fprintf(stderr, "dup\n");
12941294
}
@@ -1323,7 +1323,7 @@ object interpret3(Thread* t, const int base)
13231323
}
13241324
goto loop;
13251325

1326-
case dup2: {
1326+
case vm::dup2: {
13271327
if (DebugStack) {
13281328
fprintf(stderr, "dup2\n");
13291329
}

src/lzma/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string.h>
55
#include <sys/types.h>
66
#include <sys/stat.h>
7-
#ifdef WIN32
7+
#ifdef _WIN32
88
#include <windows.h>
99
#else
1010
#include <sys/mman.h>
@@ -65,7 +65,7 @@ int main(int argc, const char** argv)
6565
struct stat s;
6666
int r = fstat(fd, &s);
6767
if (r != -1) {
68-
#ifdef WIN32
68+
#ifdef _WIN32
6969
HANDLE fm;
7070
HANDLE h = (HANDLE)_get_osfhandle(fd);
7171

@@ -178,7 +178,7 @@ int main(int argc, const char** argv)
178178
fprintf(stderr, "unable to determine uncompressed size\n");
179179
}
180180

181-
#ifdef WIN32
181+
#ifdef _WIN32
182182
UnmapViewOfFile(data);
183183
#else
184184
munmap(data, size);

src/system/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11

2-
# TODO: use posix.cpp or windows.cpp, depending on platform
3-
add_library(avian_system posix.cpp posix/crash.cpp)
2+
if (MSVC)
3+
#todo: support mingw compiler
4+
add_library(avian_system windows.cpp windows/crash.cpp)
5+
else()
6+
add_library(avian_system posix.cpp posix/crash.cpp)
7+
endif()

src/tools/binary-to-object/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <sys/stat.h>
1717
#ifdef _WIN32
1818
#include <windows.h>
19+
#include <io.h>
1920
#else
2021
#include <sys/mman.h>
2122
#include <unistd.h>
@@ -90,7 +91,7 @@ void usageAndExit(const char* name)
9091

9192
int main(int argc, const char** argv)
9293
{
93-
if (argc < 7 or argc > 10) {
94+
if (argc < 7 || argc > 10) {
9495
usageAndExit(argv[0]);
9596
}
9697

@@ -119,7 +120,7 @@ int main(int argc, const char** argv)
119120
struct stat s;
120121
int r = fstat(fd, &s);
121122
if (r != -1) {
122-
#ifdef WIN32
123+
#ifdef _WIN32
123124
HANDLE fm;
124125
HANDLE h = (HANDLE)_get_osfhandle(fd);
125126

@@ -156,7 +157,7 @@ int main(int argc, const char** argv)
156157
fprintf(stderr, "unable to open %s\n", argv[2]);
157158
}
158159

159-
#ifdef WIN32
160+
#ifdef _WIN32
160161
UnmapViewOfFile(data);
161162
#else
162163
munmap(data, size);

src/tools/object-writer/pe.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ namespace {
4040
#define IMAGE_SCN_MEM_WRITE 0x80000000
4141
#define IMAGE_SCN_CNT_CODE 32
4242

43+
#ifdef _MSC_VER
44+
#define PACKED_STRUCT _declspec(align(1))
45+
#else
46+
#define PACKED_STRUCT __attribute__((packed))
47+
#endif
48+
4349
struct IMAGE_FILE_HEADER {
4450
uint16_t Machine;
4551
uint16_t NumberOfSections;
@@ -48,7 +54,7 @@ struct IMAGE_FILE_HEADER {
4854
uint32_t NumberOfSymbols;
4955
uint16_t SizeOfOptionalHeader;
5056
uint16_t Characteristics;
51-
} __attribute__((packed));
57+
} PACKED_STRUCT;
5258

5359
struct IMAGE_SECTION_HEADER {
5460
uint8_t Name[IMAGE_SIZEOF_SHORT_NAME];
@@ -64,7 +70,7 @@ struct IMAGE_SECTION_HEADER {
6470
uint16_t NumberOfRelocations;
6571
uint16_t NumberOfLinenumbers;
6672
uint32_t Characteristics;
67-
} __attribute__((packed));
73+
} PACKED_STRUCT;
6874

6975
struct IMAGE_SYMBOL {
7076
union {
@@ -78,7 +84,7 @@ struct IMAGE_SYMBOL {
7884
uint16_t Type;
7985
uint8_t StorageClass;
8086
uint8_t NumberOfAuxSymbols;
81-
} __attribute__((packed));
87+
} PACKED_STRUCT;
8288
// --- winnt.h ----
8389

8490
inline unsigned pad(unsigned n)

src/tools/object-writer/tools.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ Platform* Platform::first = 0;
9494

9595
PlatformInfo::Format PlatformInfo::formatFromString(const char* format)
9696
{
97-
if (strcmp(format, "elf") == 0 or strcmp(format, "linux") == 0
98-
or strcmp(format, "freebsd") == 0 or strcmp(format, "qnx") == 0) {
97+
if (strcmp(format, "elf") == 0 || strcmp(format, "linux") == 0
98+
|| strcmp(format, "freebsd") == 0 || strcmp(format, "qnx") == 0) {
9999
return Elf;
100-
} else if (strcmp(format, "pe") == 0 or strcmp(format, "windows") == 0) {
100+
} else if (strcmp(format, "pe") == 0 || strcmp(format, "windows") == 0) {
101101
return Pe;
102-
} else if (strcmp(format, "macho") == 0 or strcmp(format, "darwin") == 0
103-
or strcmp(format, "ios") == 0 or strcmp(format, "macosx") == 0) {
102+
} else if (strcmp(format, "macho") == 0 || strcmp(format, "darwin") == 0
103+
|| strcmp(format, "ios") == 0 || strcmp(format, "macosx") == 0) {
104104
return MachO;
105105
} else {
106106
return UnknownFormat;
@@ -110,13 +110,13 @@ PlatformInfo::Format PlatformInfo::formatFromString(const char* format)
110110
PlatformInfo::Architecture PlatformInfo::archFromString(const char* arch)
111111
{
112112
if (strcmp(arch, "i386") == 0) {
113-
return x86;
113+
return Architecture::x86;
114114
} else if (strcmp(arch, "x86_64") == 0) {
115-
return x86_64;
115+
return Architecture::x86_64;
116116
} else if (strcmp(arch, "arm") == 0) {
117-
return Arm;
117+
return Architecture::Arm;
118118
} else {
119-
return UnknownArch;
119+
return Architecture::UnknownArch;
120120
}
121121
}
122122

src/tools/type-generator/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ target_link_libraries(type_generator
44
avian_jvm_finder
55
avian_system
66
avian_util
7-
z
8-
pthread
9-
dl
7+
${ZLIB_LIBRARIES}
108
${PLATFORM_LIBS}
119
)

src/tools/type-generator/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Output {
124124
{
125125
static const int Size = 32;
126126
char s[Size];
127-
int c UNUSED = ::snprintf(s, Size, "%d", i);
127+
int c UNUSED = vm::snprintf(s, Size, "%d", i);
128128
assert(c > 0 and c < Size);
129129
write(s);
130130
}

src/tools/type-generator/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class Class {
172172
return ss.str();
173173
}
174174

175-
void dumpToStdout() const AVIAN_EXPORT
175+
void dumpToStdout() const
176176
{
177177
printf("%s\n", dump().c_str());
178178
}
@@ -615,13 +615,14 @@ const char* fieldType(const char* spec)
615615

616616
void parseJavaClass(Module& module, ClassParser& clparser, Stream* s)
617617
{
618-
uint32_t magic UNUSED = s->read4();
618+
uint32_t magic = s->read4();
619619
assert(magic == 0xCAFEBABE);
620+
(void)magic;
620621
s->read2(); // minor version
621622
s->read2(); // major version
622623

623624
unsigned poolCount = s->read2() - 1;
624-
uintptr_t pool[poolCount];
625+
std::vector<uintptr_t> pool(poolCount, -1);
625626
for (unsigned i = 0; i < poolCount; ++i) {
626627
unsigned c = s->read1();
627628

0 commit comments

Comments
 (0)