Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOSX support #1419

Merged
merged 3 commits into from Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 21 additions & 11 deletions Makefile
@@ -1,6 +1,10 @@
.SECONDEXPANSION:
PERCENT := %

# detect OS
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

CXX := clang++

# TODO(egg): build benchmarks
Expand Down Expand Up @@ -47,11 +51,17 @@ ADAPTER_BUILD_DIR := ksp_plugin_adapter/obj/
ADAPTER_CONFIGURATION := Release
FINAL_PRODUCTS_DIR := Release/
ADAPTER := $(ADAPTER_BUILD_DIR)$(ADAPTER_CONFIGURATION)/ksp_plugin_adapter.dll
PLUGIN_DIRECTORY := $(FINAL_PRODUCTS_DIR)GameData/Principia/Linux64/

ifeq ($(UNAME_S),Linux)
PLUGIN_DIRECTORY := $(FINAL_PRODUCTS_DIR)GameData/Principia/Linux64/
endif
ifeq ($(UNAME_S),Darwin)
PLUGIN_DIRECTORY := $(FINAL_PRODUCTS_DIR)GameData/Principia/MacOS64/
endif

TEST_LIBS := $(DEP_DIR)benchmark/src/libbenchmark.a $(DEP_DIR)/protobuf/src/.libs/libprotobuf.a
LIBS := $(DEP_DIR)/protobuf/src/.libs/libprotobuf.a \
$(DEP_DIR)/glog/.libs/libglog.a -lpthread -lc++ -lc++abi -lsupc++
$(DEP_DIR)/glog/.libs/libglog.a -lpthread -lc++ -lc++abi
TEST_INCLUDES := \
-I$(DEP_DIR)googletest/googlemock/include -I$(DEP_DIR)googletest/googletest/include \
-I$(DEP_DIR)googletest/googlemock/ -I$(DEP_DIR)googletest/googletest/ -I$(DEP_DIR)benchmark/include
Expand All @@ -65,20 +75,21 @@ SHARED_ARGS := \
-DTEMP_DIR='std::experimental::filesystem::path("/tmp")' \
-DNDEBUG

# detect OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
SHARED_ARGS += -m64
else
SHARED_ARGS += -m32
endif
MDTOOL := mdtool
LIBS += -lsupc++
TEST_LIBS += -lsupc++
SHAREDFLAG := -shared
endif
ifeq ($(UNAME_S),Darwin)
SHARED_ARGS += -mmacosx-version-min=10.7 -arch i386
SHARED_ARGS += -mmacosx-version-min=10.7 -arch x86_64
MDTOOL ?= "/Applications/Xamarin Studio.app/Contents/MacOS/mdtool"
SHAREDFLAG := -dynamiclib
endif

COMPILER_OPTIONS := -c $(SHARED_ARGS) $(INCLUDES)
Expand Down Expand Up @@ -184,7 +195,7 @@ KSP_PLUGIN := $(PLUGIN_DIRECTORY)principia.so

$(KSP_PLUGIN) : $(PROTO_OBJECTS) $(PLUGIN_OBJECTS) $(JOURNAL_LIB_OBJECTS) $(BASE_LIB_OBJECTS)
@mkdir -p $(@D)
$(CXX) -shared $(LDFLAGS) $^ $(LIBS) -o $@
$(CXX) $(SHAREDFLAG) $(LDFLAGS) $^ $(LIBS) -o $@

##### Tests

Expand Down Expand Up @@ -214,7 +225,7 @@ $(PLUGIN_INDEPENDENT_PACKAGE_TEST_BINS) $(PLUGIN_INDEPENDENT_TEST_BINS) : $(GMOC

$(PRINCIPIA_TEST_BIN) $(PLUGIN_DEPENDENT_PACKAGE_TEST_BINS) $(PLUGIN_DEPENDENT_TEST_BINS) : $(MOCK_OBJECTS) $(GMOCK_OBJECTS) $(KSP_PLUGIN)
@mkdir -p $(@D)
$(CXX) $(LDFLAGS) $^ $(TEST_LIBS) -lpthread -lsupc++ -o $@
$(CXX) $(LDFLAGS) $^ $(TEST_LIBS) -lpthread -o $@

########## Testing

Expand Down Expand Up @@ -297,7 +308,7 @@ iwyu_generate_mappings:

%.cpp!!iwyu: iwyu_generate_mappings
$(IWYU) $(CXXFLAGS) $(subst !SLASH!,/, $*.cpp) $(IWYU_FLAGS) 2>&1 | tee $(subst !SLASH!,/, $*.iwyu) | $(IWYU_CHECK_ERROR)
$(REMOVE_BOM)
$(REMOVE_BOM)
$(FIX_INCLUDES) < $(subst !SLASH!,/, $*.iwyu) | cat
$(RESTORE_BOM)

Expand All @@ -306,7 +317,7 @@ iwyu: $(subst /,!SLASH!, $(addsuffix !!iwyu, $(IWYU_TARGETS)))

%.cpp!!iwyu_unsafe: iwyu_generate_mappings
$(IWYU) $(CXXFLAGS) $(subst !SLASH!,/, $*.cpp) $(IWYU_FLAGS) 2>&1 | tee $(subst !SLASH!,/, $*.iwyu) | $(IWYU_CHECK_ERROR)
$(REMOVE_BOM)
$(REMOVE_BOM)
$(FIX_INCLUDES) $(IWYU_NOSAFE_HEADERS) < $(subst !SLASH!,/, $*.iwyu) | cat
$(RESTORE_BOM)

Expand All @@ -315,4 +326,3 @@ iwyu_unsafe: $(subst /,!SLASH!, $(addsuffix !!iwyu_unsafe, $(IWYU_TARGETS)))

iwyu_clean:
$(IWYU_CLEAN)

14 changes: 11 additions & 3 deletions generate_version_translation_unit.sh
Expand Up @@ -13,9 +13,17 @@ char const Version[] =
} // namespace base
} // namespace principia"

echo -e "$VERSION_TEMPLATE" |
sed "s/%%DATE%%/`date -d $(git log -1 --format=%cd --date=iso-strict) -u +%Y-%m-%dT%H:%M:%SZ`/" |
sed "s/%%VERSION%%/`git describe --tags --always --dirty --abbrev=40 --long`/" > $TEMPORARY_FILE
PLATFORM=$(uname -s)
if [ "$PLATFORM" == "Darwin" ]; then
echo -e "$VERSION_TEMPLATE" |
sed "s/%%DATE%%/`date -j -u -f \"%Y-%m-%d %H:%M:%S %z\" -u +%Y-%m-%dT%H:%M:%SZ \"$(git log -1 --format=%cd --date=iso)\"`/" |
sed "s/%%VERSION%%/`git describe --tags --always --dirty --abbrev=40 --long`/" > $TEMPORARY_FILE
else
echo -e "$VERSION_TEMPLATE" |
sed "s/%%DATE%%/`date -d $(git log -1 --format=%cd --date=iso-strict) -u +%Y-%m-%dT%H:%M:%SZ`/" |
sed "s/%%VERSION%%/`git describe --tags --always --dirty --abbrev=40 --long`/" > $TEMPORARY_FILE
fi

if cmp -s base/version.generated.cc $TEMPORARY_FILE
then
echo "No change to git describe, leaving base/version.generated.cc untouched"
Expand Down
54 changes: 46 additions & 8 deletions install_deps.sh
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

echo "Required prerequisites for build: build-essential clang libc++-dev libc++abi-dev monodevelop subversion git"
echo "Required runtime dependencies: libc++1"
Expand All @@ -10,7 +11,7 @@ BASE_FLAGS="-fPIC -O3 -g"

PLATFORM=$(uname -s)
if [ "$PLATFORM" == "Darwin" ]; then
C_FLAGS="$BASE_FLAGS -mmacosx-version-min=10.7 -arch i386"
C_FLAGS="$BASE_FLAGS -mmacosx-version-min=10.7 -arch x86_64"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only line in this file that is strictly necessary to fix for MacOSX -- all the rest of the diff in install_deps.sh here i just found more useful, but it could all be dropped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other changes look good to me too.

elif [ "$PLATFORM" == "Linux" ]; then
BITNESS=$(uname -m)
if [ "$BITNESS" == "x86_64" ]; then
Expand All @@ -28,8 +29,12 @@ CXX_FLAGS="-std=c++14 $LD_FLAGS"
mkdir -p deps
cd deps

git clone "https://github.com/mockingbirdnest/protobuf"
if [ ! -d "protobuf" ]; then
git clone "https://github.com/mockingbirdnest/protobuf"
fi
pushd protobuf
git checkout master
git pull
./autogen.sh
if [ "$PLATFORM" == "Linux" ]; then
./autogen.sh # Really definitely needs to run twice on Ubuntu for some reason.
Expand All @@ -38,26 +43,59 @@ fi
make -j8
popd

git clone "https://github.com/mockingbirdnest/glog"
if [ ! -d "glog" ]; then
git clone "https://github.com/mockingbirdnest/glog"
fi
pushd glog
git checkout master
git pull
aclocal
automake
./configure CC=clang CXX=clang++ CFLAGS="$C_FLAGS" CXXFLAGS="$CXX_FLAGS" LDFLAGS="$LD_FLAGS" LIBS="-lc++ -lc++abi"
make -j8
popd

# googlemock/googletest don't need to be compiled
git clone "https://github.com/mockingbirdnest/googlemock"
git clone "https://github.com/mockingbirdnest/googletest"
if [ ! -d "googlemock" ]; then
git clone "https://github.com/mockingbirdnest/googlemock"
fi
pushd googlemock
git checkout master
git pull
popd

if [ ! -d "googletest" ]; then
git clone "https://github.com/mockingbirdnest/googletest"
fi
pushd googletest
git checkout master
git pull
popd

git clone "https://github.com/Norgg/eggsperimental_filesystem.git"
if [ ! -d "eggsperimental_filesystem" ]; then
git clone "https://github.com/Norgg/eggsperimental_filesystem.git"
fi
pushd eggsperimental_filesystem
git checkout master
git pull
popd

# Optional doesn't need to be compiled either
git clone "https://github.com/mockingbirdnest/Optional.git"
if [ ! -d "Optional" ]; then
git clone "https://github.com/mockingbirdnest/Optional.git"
fi
pushd Optional
git checkout master
git pull
popd

# TODO(egg): This probably needs to be compiled
git clone "https://github.com/mockingbirdnest/benchmark"
if [ ! -d "benchmark" ]; then
git clone "https://github.com/mockingbirdnest/benchmark"
fi
pushd benchmark
git checkout master
git pull
cmake -DCMAKE_C_COMPILER:FILEPATH=`which clang` -DCMAKE_CXX_COMPILER:FILEPATH=`which clang++` -DCMAKE_C_FLAGS="${C_FLAGS}" -DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DCMAKE_LD_FLAGS="${LD_FLAGS}"
make -j8
popd
1 change: 1 addition & 0 deletions ksp_plugin_adapter/ksp_plugin_adapter.dll.config
@@ -1,4 +1,5 @@
<configuration>
<dllmap dll="principia" os="windows" cpu="x86-64" target="GameData/Principia/x64/principia.dll"/>
<dllmap dll="principia" os="linux" cpu="x86-64" target="GameData/Principia/Linux64/principia.so"/>
<dllmap dll="principia" os="osx" cpu="x86-64" target="GameData/Principia/MacOS64/principia.so" />
</configuration>