-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mcallet/fix-makefile-libgroupgcc' into 'main'
feat: fix libGroup option for Makefile and Gcc See merge request Sharpmake/sharpmake!491
- Loading branch information
Showing
12 changed files
with
294 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,9 @@ | |
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Sharpmake; | ||
using Sharpmake.Generators.FastBuild; | ||
|
||
|
@@ -43,6 +41,16 @@ private static void ConfigureAutoCleanup() | |
Directory.CreateDirectory(Util.FilesAutoCleanupDBPath); | ||
} | ||
|
||
public static void OverrideLinuxPlatformDescriptor() | ||
{ | ||
// Workaround for regression introduced in [email protected]. | ||
// Default value for IsLinkerInvokedViaCompiler should be true when generating makefile on Linux. | ||
// See Sharpmake commit e3142832edb3af7f5cc1401365d1e0c1c84fc08e. | ||
|
||
var platformDescriptor = (Linux.LinuxPlatform)PlatformRegistry.Get<IPlatformDescriptor>(Platform.linux); | ||
platformDescriptor.IsLinkerInvokedViaCompiler = true; | ||
} | ||
|
||
[Sharpmake.Main] | ||
public static void SharpmakeMain(Sharpmake.Arguments arguments) | ||
{ | ||
|
@@ -56,6 +64,8 @@ public static void SharpmakeMain(Sharpmake.Arguments arguments) | |
FastBuildSettings.FastBuildMonitor = true; | ||
FastBuildSettings.FastBuildAllowDBMigration = true; | ||
|
||
OverrideLinuxPlatformDescriptor(); | ||
|
||
// for the purpose of this sample, we'll reuse the FastBuild executables that live in the sharpmake source repo | ||
string sharpmakeFastBuildDir = Util.PathGetAbsolute(Globals.RootDirectory, @"..\..\..\tools\FastBuild"); | ||
switch (Util.GetExecutingPlatform()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
samples/HelloLinux/codebase/lib_group/lib_group.sharpmake.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Ubisoft. All Rights Reserved. | ||
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. | ||
|
||
using Sharpmake; | ||
|
||
namespace HelloLinux | ||
{ | ||
[Sharpmake.Generate] | ||
public class LibGroupProject : CommonProject | ||
{ | ||
public LibGroupProject() | ||
{ | ||
AddTargets(CommonTarget.GetDefaultTargets()); | ||
Name = "lib_group"; | ||
} | ||
|
||
public override void ConfigureAll(Configuration conf, CommonTarget target) | ||
{ | ||
base.ConfigureAll(conf, target); | ||
ConfigureLibraries(conf, target); | ||
|
||
conf.Output = Configuration.OutputType.Dll; | ||
conf.IncludePaths.Add(SourceRootPath); | ||
conf.SolutionFolder = "SharedLibs"; | ||
|
||
conf.PrecompHeader = "precomp.h"; | ||
conf.PrecompSource = "precomp.cpp"; | ||
|
||
conf.AdditionalCompilerOptions.Add("-fPIC"); | ||
|
||
conf.Defines.Add("UTIL_DLL_EXPORT"); | ||
conf.ExportDefines.Add("UTIL_DLL_IMPORT"); | ||
} | ||
|
||
public void ConfigureLibraries(Configuration conf, CommonTarget target) { | ||
|
||
// Enable library group with Clang and GCC to allow libraries that have circular dependencies. | ||
conf.Options.Add(Options.Makefile.Linker.LibGroup.Enable); | ||
|
||
conf.LibraryFiles.Add("m"); | ||
conf.AddPrivateDependency<StaticLib1Project>(target); | ||
conf.AddPrivateDependency<Dll1Project>(target); | ||
conf.AddPrivateDependency<ExternalLibProject>(target); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "precomp.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#include <vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "precomp.h" | ||
#include "util_dll.h" | ||
|
||
#include <cmath> | ||
#include <iostream> | ||
#include "src/util_static_lib1.h" | ||
|
||
int UtilDll1::ComputeMagicNumber(const std::vector<int>& someInts) | ||
{ | ||
int acc = 0; | ||
for (int item : someInts) | ||
acc += item; | ||
|
||
#if _DEBUG | ||
std::cout << "- Dll1 is built in Debug" | ||
# if USES_FASTBUILD | ||
" with FastBuild" | ||
# endif | ||
"!" << std::endl; | ||
#endif | ||
|
||
#if NDEBUG | ||
std::cout << "- Dll1 is built in Release" | ||
# if USES_FASTBUILD | ||
" with FastBuild" | ||
# endif | ||
"!" << std::endl; | ||
#endif | ||
|
||
acc += static_lib1_utils::GetRandomPosition(); | ||
|
||
acc += cosf(M_PI); | ||
|
||
return acc; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include <vector> | ||
|
||
#if defined(UTIL_DLL_EXPORT) && HAVE_VISIBILITY | ||
# define UTIL_DLL __attribute__((__visibility("default"))) | ||
#elif defined(UTIL_DLL_EXPORT) && defined(_MSC_VER) | ||
# define UTIL_DLL __declspec(dllexport) | ||
#elif defined(UTIL_DLL_IMPORT) && defined(_MSC_VER) | ||
#define UTIL_DLL __declspec(dllimport) | ||
#else | ||
#define UTIL_DLL | ||
#endif | ||
|
||
struct UtilDll1 | ||
{ | ||
UTIL_DLL int ComputeMagicNumber(const std::vector<int>& someInts); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
samples/HelloLinux/reference/codebase/temp/projects/lib_group/lib_group_linux_make.make
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# Generated by Sharpmake -- Do not edit ! | ||
ifndef config | ||
config=debug | ||
endif | ||
|
||
ifndef verbose | ||
SILENT = @ | ||
endif | ||
|
||
ifeq ($(config),debug) | ||
CXX = g++ | ||
AR = ar | ||
OBJDIR = ../../obj/linux_debug/lib_group | ||
TARGETDIR = ../../bin/linux_debug | ||
TARGET = $(TARGETDIR)/liblib_group.so | ||
DEFINES += -D "UTIL_DLL_EXPORT" -D "UTIL_DLL_IMPORT" -D "_DEBUG" | ||
INCLUDES += -I../../../dll1 -I../../../lib_group -I../../../static_lib1 | ||
CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) | ||
CFLAGS += $(CPPFLAGS) -g -Wall -fPIC | ||
CXXFLAGS += $(CFLAGS) -fno-exceptions -fno-rtti | ||
LDFLAGS += -L../../bin/linux_debug -L../../lib/linux_debug/curl -L../../lib/linux_debug/static_lib1 | ||
LDLIBS += -Wl,--start-group -l:libcurl.a -l:libdll1.so -l:libstatic_lib1.a -l:libm.a -Wl,--end-group | ||
RESFLAGS += $(DEFINES) $(INCLUDES) | ||
LDDEPS += ../../bin/linux_debug/libdll1.so ../../lib/linux_debug/static_lib1/libstatic_lib1.a | ||
LINKCMD = $(CXX) -shared -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDLIBS) | ||
PCH = ../../../lib_group/precomp.h | ||
PCHOUT = $(OBJDIR)/precomp.h | ||
GCH = $(OBJDIR)/precomp.h.gch | ||
PCHCMD = -include $(PCHOUT) | ||
define PREBUILDCMDS | ||
mkdir -p $(TARGETDIR)/../../package | ||
endef | ||
define PRELINKCMDS | ||
|
||
endef | ||
define POSTBUILDCMDS | ||
cp $(TARGET) $(TARGETDIR)/../../package | ||
endef | ||
define POSTFILECMDS | ||
endef | ||
endif | ||
|
||
ifeq ($(config),release) | ||
CXX = g++ | ||
AR = ar | ||
OBJDIR = ../../obj/linux_release/lib_group | ||
TARGETDIR = ../../bin/linux_release | ||
TARGET = $(TARGETDIR)/liblib_group.so | ||
DEFINES += -D "NDEBUG" -D "UTIL_DLL_EXPORT" -D "UTIL_DLL_IMPORT" | ||
INCLUDES += -I../../../dll1 -I../../../lib_group -I../../../static_lib1 | ||
CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) | ||
CFLAGS += $(CPPFLAGS) -g -O3 -Wall -fPIC | ||
CXXFLAGS += $(CFLAGS) -fno-exceptions -fno-rtti | ||
LDFLAGS += -L../../bin/linux_release -L../../lib/linux_release/curl -L../../lib/linux_release/static_lib1 | ||
LDLIBS += -Wl,--start-group -l:libcurl.a -l:libdll1.so -l:libstatic_lib1.a -l:libm.a -Wl,--end-group | ||
RESFLAGS += $(DEFINES) $(INCLUDES) | ||
LDDEPS += ../../bin/linux_release/libdll1.so ../../lib/linux_release/static_lib1/libstatic_lib1.a | ||
LINKCMD = $(CXX) -shared -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDLIBS) | ||
PCH = ../../../lib_group/precomp.h | ||
PCHOUT = $(OBJDIR)/precomp.h | ||
GCH = $(OBJDIR)/precomp.h.gch | ||
PCHCMD = -include $(PCHOUT) | ||
define PREBUILDCMDS | ||
mkdir -p $(TARGETDIR)/../../package | ||
endef | ||
define PRELINKCMDS | ||
|
||
endef | ||
define POSTBUILDCMDS | ||
cp $(TARGET) $(TARGETDIR)/../../package | ||
endef | ||
define POSTFILECMDS | ||
endef | ||
endif | ||
|
||
ifeq ($(config),debug) | ||
OBJECTS += $(OBJDIR)/precomp.o | ||
OBJECTS += $(OBJDIR)/util_dll.o | ||
endif | ||
|
||
ifeq ($(config),release) | ||
OBJECTS += $(OBJDIR)/precomp.o | ||
OBJECTS += $(OBJDIR)/util_dll.o | ||
endif | ||
|
||
RESOURCES := \ | ||
|
||
SHELLTYPE := msdos | ||
ifeq (,$(ComSpec)$(COMSPEC)) | ||
SHELLTYPE := posix | ||
endif | ||
ifeq (/bin,$(findstring /bin,$(SHELL))) | ||
SHELLTYPE := posix | ||
endif | ||
|
||
.PHONY: clean prebuild prelink | ||
|
||
all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) | ||
@: | ||
|
||
$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR) | ||
@echo Linking lib_group | ||
$(SILENT) $(LINKCMD) | ||
$(POSTBUILDCMDS) | ||
|
||
$(TARGETDIR): | ||
@echo Creating $(TARGETDIR) | ||
ifeq (posix,$(SHELLTYPE)) | ||
$(SILENT) mkdir -p $(TARGETDIR) | ||
else | ||
$(SILENT) if not exist $(subst /,\\,$(TARGETDIR)) mkdir $(subst /,\\,$(TARGETDIR)) | ||
endif | ||
|
||
ifneq ($(OBJDIR),$(TARGETDIR)) | ||
$(OBJDIR): | ||
@echo Creating $(OBJDIR) | ||
ifeq (posix,$(SHELLTYPE)) | ||
$(SILENT) mkdir -p $(OBJDIR) | ||
else | ||
$(SILENT) if not exist $(subst /,\\,$(OBJDIR)) mkdir $(subst /,\\,$(OBJDIR)) | ||
endif | ||
endif | ||
|
||
clean: | ||
@echo Cleaning lib_group | ||
ifeq (posix,$(SHELLTYPE)) | ||
$(SILENT) rm -f $(TARGET) | ||
$(SILENT) rm -rf $(OBJDIR) | ||
else | ||
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) | ||
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) | ||
endif | ||
|
||
prebuild: | ||
$(PREBUILDCMDS) | ||
|
||
prelink: | ||
$(PRELINKCMDS) | ||
|
||
ifneq (,$(PCH)) | ||
$(GCH): $(PCH) | $(OBJDIR) | ||
@echo $(notdir $<) | ||
-$(SILENT) cp $< $(OBJDIR) | ||
$(SILENT) $(CXX) $(CXXFLAGS) -xc++-header -o "$@" -c "$<" | ||
$(SILENT) $(POSTFILECMDS) | ||
endif | ||
|
||
$(OBJDIR)/precomp.o: ../../../lib_group/precomp.cpp $(GCH) | $(OBJDIR) | ||
@echo $(notdir $<) | ||
$(SILENT) $(CXX) $(CXXFLAGS) $(PCHCMD) -o "$@" -c "$<" | ||
$(SILENT) $(POSTFILECMDS) | ||
|
||
$(OBJDIR)/util_dll.o: ../../../lib_group/util_dll.cpp $(GCH) | $(OBJDIR) | ||
@echo $(notdir $<) | ||
$(SILENT) $(CXX) $(CXXFLAGS) $(PCHCMD) -o "$@" -c "$<" | ||
$(SILENT) $(POSTFILECMDS) | ||
|
||
-include $(OBJECTS:%.o=%.d) | ||
-include $(GCH:%.gch=%.d) |
Oops, something went wrong.