Skip to content

Commit fac019c

Browse files
committed
MacOS support
MacOS support - fix Makefiles
1 parent b5ccc39 commit fac019c

File tree

25 files changed

+151
-339
lines changed

25 files changed

+151
-339
lines changed

Release/Makefile

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
TOP ?= $(shell pwd)
2+
13
SUBDIRS = src tests samples
24

35
bad:
46
@echo "Please 'make' one of: release, debug, all, or clean."
57

6-
#CXX=clang
7-
#CXX=/usr/lib/gcc-snapshot/bin/g++
8-
CXX=g++-4.8
8+
UNAME_S := $(shell uname -s)
9+
ifeq ($(UNAME_S),Linux)
10+
UNAME=LINUX
11+
CXX=g++-4.8
12+
endif
13+
ifeq ($(UNAME_S),Darwin)
14+
UNAME=APPLE
15+
CXX=clang++
16+
endif
17+
18+
export UNAME
919
export CXX
1020

1121
mk_out_dir:
@@ -18,45 +28,68 @@ release: mk_out_dir tests samples
1828

1929
debug: OPTIMIZATION_LEVEL = -O0 -g -ggdb
2030
debug: MODE = Debug$(shell getconf LONG_BIT)
21-
debug: OUTPUT_DIR = $(PWD)/../Binaries/$(MODE)
31+
debug: OUTPUT_DIR = $(TOP)/../Binaries/$(MODE)
2232
debug: mk_out_dir tests samples
2333

2434
clean: RMODE = Release$(shell getconf LONG_BIT)
2535
clean: DMODE = Debug$(shell getconf LONG_BIT)
26-
clean: ROUTPUT_DIR = $(PWD)/../Binaries/$(RMODE)
27-
clean: DOUTPUT_DIR = $(PWD)/../Binaries/$(DMODE)
36+
clean: ROUTPUT_DIR = $(TOP)/../Binaries/$(RMODE)
37+
clean: DOUTPUT_DIR = $(TOP)/../Binaries/$(DMODE)
2838

2939
export MODE
3040

3141
WARNINGS=-Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code
32-
SUPPRESSIONS=-Wno-deprecated -Wno-unknown-pragmas -Wno-reorder -Wno-unused-function -Wno-char-subscripts -Wno-switch -Wno-unused-but-set-parameter -Wno-deprecated -Wno-unused-value -Wno-unused-local-typedefs
3342

43+
ifeq ($(UNAME),LINUX)
44+
SUPPRESSIONS=-Wno-deprecated -Wno-unknown-pragmas -Wno-reorder -Wno-unused-function -Wno-char-subscripts -Wno-switch -Wno-unused-but-set-parameter -Wno-deprecated -Wno-unused-value -Wno-unused-local-typedefs
3445
# C++11 excludes GCC < 4.7, which is desired anyway
3546
OTHER_OPTIONS=-std=c++11 -fno-strict-aliasing
47+
endif
48+
ifeq ($(UNAME),APPLE)
49+
SUPPRESSIONS=-Wno-overloaded-virtual -Wno-sign-conversion -Wno-deprecated -Wno-unknown-pragmas -Wno-reorder -Wno-unused-function -Wno-char-subscripts -Wno-switch -Wno-unused-parameter -Wno-unused-variable -Wno-deprecated -Wno-unused-value -Wno-unknown-warning-option -Wno-return-type-c-linkage
50+
OTHER_OPTIONS=-stdlib=libc++ -std=c++11 -fno-strict-aliasing
51+
endif
3652

3753
STRICT_BASE_CXXFLAGS=$(OPTIMIZATION_LEVEL) $(OTHER_OPTIONS) $(WARNINGS) $(SUPPRESSIONS) -Werror -pedantic
3854
export STRICT_BASE_CXXFLAGS
3955

4056
BASE_CXXFLAGS=$(OPTIMIZATION_LEVEL) $(OTHER_OPTIONS) $(WARNINGS) $(SUPPRESSIONS) -Werror
4157
export BASE_CXXFLAGS
4258

43-
LAX_BASE_CXXFLAGS=$(OPTIMIZATION_LEVEL) $(SUPPRESSIONS) $(OTHER_OPTIONS) -fpermissive
59+
LAX_BASE_CXXFLAGS=$(OPTIMIZATION_LEVEL) $(SUPPRESSIONS) $(OTHER_OPTIONS)
4460
export LAX_BASE_CXXFLAGS
4561

46-
BASE_LDFLAGS=-Wl,-z,defs
62+
#Disallows undefined symbols in object files (not supported on MacOS)
63+
ifeq ($(UNAME),LINUX)
64+
BASE_LDFLAGS=-Wl,-z,defs
65+
endif
4766
export BASE_LDFLAGS
4867

4968
export OUTPUT_DIR
5069

51-
CASABLANCA_INCLUDE_DIR=$(PWD)/include/
70+
CASABLANCA_INCLUDE_DIR=$(TOP)/include/
5271
export CASABLANCA_INCLUDE_DIR
5372

54-
CASABLANCA_DIR=$(PWD)/
73+
CASABLANCA_DIR=$(TOP)/
5574
export CASABLANCA_DIR
5675

57-
CASABLANCA_TESTS_DIR=$(PWD)/tests
76+
CASABLANCA_TESTS_DIR=$(TOP)/tests
5877
export CASABLANCA_TESTS_DIR
5978

79+
# boost libraries: use '-mt' suffix for Apple
80+
ifeq ($(UNAME),LINUX)
81+
export BOOST_SYSTEM=boost_system
82+
export BOOST_THREAD=boost_thread
83+
export BOOST_LOCALE=boost_locale
84+
export BOOST_REGEX=boost_regex
85+
endif
86+
ifeq ($(UNAME),APPLE)
87+
export BOOST_SYSTEM=boost_system-mt
88+
export BOOST_THREAD=boost_thread-mt
89+
export BOOST_LOCALE=boost_locale-mt
90+
export BOOST_REGEX=boost_regex-mt
91+
endif
92+
6093
tests: src
6194
samples: src
6295

Release/collateral/Samples/BlackJack/BlackJack_Server/messagetypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct BJHand
169169
{
170170
web::json::value result = web::json::value::object();
171171
result[STATE] = web::json::value::number(state);
172-
result[RESULT] = web::json::value::number(this->result);
172+
result[RESULT] = web::json::value::number(this->result);
173173
result[BET] = web::json::value::number(bet);
174174
result[INSURANCE] = web::json::value::number(insurance);
175175

@@ -186,7 +186,7 @@ struct BJHand
186186
else
187187
{
188188
int idx = 0;
189-
for (auto iter = cards.begin(); iter != cards.end(); ++iter)
189+
for (auto iter = cards.begin(); iter != cards.end();)
190190
{
191191
jCards[idx++] = iter->AsJSON();
192192
break;

Release/include/cpprest/http_client_impl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ namespace web { namespace http { namespace client { namespace details
341341
{
342342
// First see if client needs to be opened.
343343
auto error = open_if_required();
344-
345344
if (error != S_OK)
346345
{
347346
// Failed to open
@@ -359,7 +358,7 @@ namespace web { namespace http { namespace client { namespace details
359358
unsigned long open_if_required()
360359
{
361360
unsigned long error = S_OK;
362-
361+
363362
if( !m_opened )
364363
{
365364
pplx::extensibility::scoped_critical_section_t l(m_open_lock);
@@ -368,7 +367,6 @@ namespace web { namespace http { namespace client { namespace details
368367
if ( !m_opened )
369368
{
370369
error = open();
371-
372370
if (error == S_OK)
373371
{
374372
m_opened = true;

Release/include/cpprest/xxpublic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ typedef UINT_PTR SOCKET;
6060
#endif
6161
#endif
6262

63+
#define UNREACHABLE __assume(0)
64+
6365
// for winhttp.h
6466
typedef void * HINTERNET;
6567

Release/samples/BingRequest/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
$(OUTPUT_DIR)/BingRequest: ../../collateral/Samples/BingRequest/bingrequest.cpp
2-
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -lboost_system -lboost_thread -Wno-sign-compare -Wno-unused-parameter
2+
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -l$(BOOST_SYSTEM) -l$(BOOST_THREAD) -Wno-sign-compare -Wno-unused-parameter

Release/samples/BlackJack/BlackJack_Client/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $(OUTPUT_DIR)/blackjackclient: blackjackclient
22
cp blackjackclient $@
33

44
blackjackclient: ../../../collateral/Samples/BlackJack/BlackJack_Client/BlackJackClient.cpp ../../../collateral/Samples/BlackJack/BlackJack_Client/stdafx.cpp
5-
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) -include ../../../collateral/Samples/BlackJack/BlackJack_Client/stdafx.h $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -I$(shell pkg-config libxml++-2.6 --cflags) -lboost_system -Wno-missing-include-dirs -Wno-unused-parameter -Wno-attributes -Wno-sign-compare -Wno-enum-compare
5+
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) -include ../../../collateral/Samples/BlackJack/BlackJack_Client/stdafx.h $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -l$(BOOST_SYSTEM) -Wno-missing-include-dirs -Wno-unused-parameter -Wno-attributes -Wno-sign-compare -Wno-enum-compare
66

77

88

Release/samples/BlackJack/BlackJack_Server/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $(OUTPUT_DIR)/blackjackserver: blackjackserver
22
cp blackjackserver $@
33

44
blackjackserver: ../../../collateral/Samples/BlackJack/BlackJack_Server/BlackJack_Server.cpp ../../../collateral/Samples/BlackJack/BlackJack_Server/Dealer.cpp ../../../collateral/Samples/BlackJack/BlackJack_Server/stdafx.cpp ../../../collateral/Samples/BlackJack/BlackJack_Server/Table.cpp
5-
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) -include ../../../collateral/Samples/BlackJack/BlackJack_Server/stdafx.h $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -I$(shell pkg-config libxml++-2.6 --cflags) -lboost_system -Wno-missing-include-dirs -Wno-unused-parameter -Wno-attributes -Wno-sign-compare -Wno-enum-compare
5+
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) -include ../../../collateral/Samples/BlackJack/BlackJack_Server/stdafx.h $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -l$(BOOST_SYSTEM) -Wno-missing-include-dirs -Wno-unused-parameter -Wno-attributes -Wno-sign-compare -Wno-enum-compare
66

77

88

Release/samples/SearchFile/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
$(OUTPUT_DIR)/SearchFile: ../../collateral/Samples/SearchFile/searchfile.cpp
2-
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -lboost_system -lboost_thread -Wno-sign-compare -Wno-unused-parameter
2+
$(CXX) $(BASE_CXXFLAGS) -I$(CASABLANCA_INCLUDE_DIR) $^ -o $@ -L$(OUTPUT_DIR) -lcasablanca -l$(BOOST_SYSTEM) -l$(BOOST_THREAD) -Wno-sign-compare -Wno-unused-parameter

Release/src/Makefile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ SOURCES = \
44
streams/linux/fileio_linux.cpp \
55
json/json.cpp \
66
utilities/asyncrt_utils.cpp \
7-
pplx/linux/pplxlinux.cpp \
87
pplx/pplx.cpp \
98
pplx/threadpool.cpp \
109
http/uri/uri.cpp \
@@ -21,6 +20,13 @@ SOURCES = \
2120
http/logging/log.cpp \
2221
utilities/base64.cpp
2322

23+
ifeq ($(UNAME),APPLE)
24+
SOURCES += pplx/apple/pplxapple.cpp
25+
else
26+
SOURCES += pplx/apple/pplxlinux.cpp
27+
endif
28+
29+
2430
HEADERS = \
2531
../include/cpprest/astreambuf.h \
2632
../include/cpprest/streams.h \
@@ -57,11 +63,16 @@ HEADERS = \
5763
../include/cpprest/uri_builder.h \
5864
../include/cpprest/uri_parser.h \
5965
../include/cpprest/xxpublic.h \
60-
../include/compat/linux_compat.h \
6166
../include/compat/SafeInt3.hpp \
6267
../include/pplx/threadpool.h \
6368
../src/pch/stdafx.h
6469

70+
ifeq ($(UNAME),APPLE)
71+
HEADERS += ../include/compat/apple_compat.h
72+
else
73+
HEADERS += ../include/compat/linux_compat.h
74+
endif
75+
6576
PCH = ./pch/stdafx.h
6677

6778
PRECOMPILED_HEADERS = $(addsuffix .gch, $(PCH))
@@ -70,13 +81,16 @@ CPP_DEPENDENCIES = $(addsuffix .d, $(basename $(SOURCES)))
7081

7182
# flags for the C++ compiler
7283

73-
PKGCONFIG_CFLAGS = $(shell pkg-config libxml++-2.6 --cflags)
84+
ifeq ($(UNAME),LINUX)
85+
PKGCONFIG_CFLAGS = $(shell pkg-config libxml++-2.6 --cflags)
7486
PKGCONFIG_LIBS = $(shell pkg-config libxml++-2.6 --libs) $(shell pkg-config libssl --libs)
87+
endif
7588

7689
#-fpch-deps -MMD not useful with a single monolithic PCH
7790

7891
CXXFLAGS = -fPIC -std=c++11 $(STRICT_BASE_CXXFLAGS) -I../include -I./pch $(WARNINGS) $(PKGCONFIG_CFLAGS)
79-
LIBS = $(PKGCONFIG_LIBS) -lboost_system -lboost_thread -lboost_locale -lboost_regex -pthread -lstdc++ -lm # these are explicit for clang
92+
# Use "mt" version of boost for Apple, and no-mt for Linux
93+
LIBS = $(PKGCONFIG_LIBS) -framework CoreFoundation -l$(BOOST_SYSTEM) -l$(BOOST_THREAD) -l$(BOOST_LOCALE) -l$(BOOST_REGEX) -lstdc++ -lm # these are explicit for clang
8094
LDFLAGS = $(BASE_LDFLAGS)
8195

8296
ifeq ($(OUTPUT_DIR),)

Release/src/http/common/http_helpers.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ namespace details
224224
return convert_utf16be_to_utf8(src, false);
225225
}
226226

227-
// Compiler complains about not returning in all cases.
228-
throw std::runtime_error("Better never hit here.");
227+
UNREACHABLE;
229228
}
230229

231230
utf16string convert_utf8_to_utf16(const unsigned char *src, size_t src_size)
@@ -247,8 +246,7 @@ namespace details
247246
return convert_utf16be_to_utf8(convert_bytes_to_wstring(src), false);
248247
}
249248

250-
// Compiler complains about not returning in all cases.
251-
throw std::runtime_error("Better never hit here.");
249+
UNREACHABLE;
252250
}
253251

254252
utf16string convert_utf16_to_utf16(const unsigned char *src, size_t src_size)
@@ -273,8 +271,7 @@ namespace details
273271
return convert_utf16be_to_utf16le(src, false);
274272
}
275273

276-
// Compiler complains about not returning in all cases.
277-
throw std::runtime_error("Better never hit here.");
274+
UNREACHABLE;
278275
}
279276

280277
utf16string convert_utf16_to_utf16(const std::vector<unsigned char> &src)
@@ -296,9 +293,8 @@ namespace details
296293
// unknown defaults to big endian.
297294
return convert_utf16be_to_utf16le(src, false);
298295
}
299-
300-
// Compiler complains about not returning in all cases.
301-
throw std::runtime_error("Better never hit here.");
296+
297+
UNREACHABLE;
302298
}
303299

304300
utf16string convert_utf8_to_utf16(const std::vector<unsigned char> &src)

0 commit comments

Comments
 (0)