Skip to content

Commit

Permalink
linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Nov 9, 2023
1 parent 3d61d71 commit 7ce344e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
8 changes: 8 additions & 0 deletions build/Build.Steps.Linux.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Serilog;
using static Nuke.Common.EnvironmentInfo;
using static Nuke.Common.IO.FileSystemTasks;
Expand Down Expand Up @@ -31,6 +32,13 @@ partial class Build
.OnlyWhenStatic(() => IsLinux)
.Executes(() =>
{
var buildDirectory = Solution.GetContinuousProfilerNativeDep().Directory.ToString();
CMake.Value(
arguments: "-S .",
workingDirectory: buildDirectory);
Make.Value(
arguments: $"",
workingDirectory: buildDirectory);
});

Target CompileNativeTestsLinux => _ => _
Expand Down
7 changes: 7 additions & 0 deletions build/Build.Steps.MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ partial class Build
.OnlyWhenStatic(() => IsOsx)
.Executes(() =>
{
var buildDirectory = Solution.GetContinuousProfilerNativeDep().Directory.ToString();
CMake.Value(
arguments: "-S .",
workingDirectory: buildDirectory);
Make.Value(
arguments: $"",
workingDirectory: buildDirectory);
});

Target PublishNativeProfilerMacOs => _ => _
Expand Down
2 changes: 1 addition & 1 deletion build/Build.Steps.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ partial class Build
.OnlyWhenStatic(() => IsWin)
.Executes(() =>
{
var continuousProfilerNativeDepProject = Solution.GetProjectByName(Projects.Tests.Applications.ContinuousProfilerNativeDep);
var continuousProfilerNativeDepProject = Solution.GetContinuousProfilerNativeDep();
PerformLegacyRestoreIfNeeded(continuousProfilerNativeDepProject);
// Can't use dotnet msbuild, as needs to use the VS version of MSBuild
MSBuild(s => s
Expand Down
5 changes: 5 additions & 0 deletions build/ProjectsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public static Project GetTestMock(this Solution solution)
return solution.GetProjectByName(Projects.Mocks.AutoInstrumentationMock);
}

public static Project GetContinuousProfilerNativeDep(this Solution solution)
{
return solution.GetProjectByName(Projects.Tests.Applications.ContinuousProfilerNativeDep);
}

public static IEnumerable<Project> GetNetFrameworkOnlyTestApplications(this Solution solution)
{
return solution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required (VERSION 3.8..3.19)
cmake_policy(SET CMP0015 NEW)

Expand All @@ -18,6 +21,9 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
message(STATUS "Preparing Linux build")
SET(ISLINUX true)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
message(STATUS "Preparing macOS build")
SET(ISMACOS true)
endif()

# Detect bitness of the build
Expand All @@ -44,17 +50,32 @@ endif()
# ******************************************************
# Detect prerequisites
# ******************************************************
find_program(FOUND_GIT git)
if (NOT FOUND_GIT)
message(FATAL_ERROR "GIT is required to build the project")
else()
message(STATUS "GIT found: ${FOUND_GIT}")
endif()

find_program(FOUND_GCC gcc)
if(NOT FOUND_GCC)
message(FATAL_ERROR "GCC is required to build the project's dependencies")
else()
message(STATUS "GCC found: ${FOUND_GCC}")
endif()

if (NOT EXISTS /usr/bin/clang)
find_program(FOUND_CLANG clang)
if(NOT FOUND_CLANG)
message(FATAL_ERROR "CLANG is required to build the project")
else()
message(STATUS "CLANG was found")
message(STATUS "CLANG found: ${FOUND_CLANG}")
endif()

if (NOT EXISTS /usr/bin/clang++)
find_program(FOUND_CLANGPP clang++)
if(NOT FOUND_CLANGPP)
message(FATAL_ERROR "CLANG++ is required to build the project")
else()
message(STATUS "CLANG++ was found")
message(STATUS "CLANG++ found: ${FOUND_CLANGPP}")
endif()

# ******************************************************
Expand All @@ -71,7 +92,6 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_BIN_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_BIN_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_BIN_DIR})


# ******************************************************
# Dependencies
# ******************************************************
Expand All @@ -81,16 +101,20 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_BIN_DIR})
# ******************************************************

# Sets the compiler
SET (CMAKE_C_COMPILER /usr/bin/clang)
SET (CMAKE_CXX_COMPILER /usr/bin/clang++)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
if(ISLINUX)
SET (CMAKE_C_COMPILER ${FOUND_CLANG})
SET (CMAKE_CXX_COMPILER ${FOUND_CLANGPP})
endif()

# Sets compiler options
add_compile_options(-std=c++17 -fPIC -fms-extensions)
add_compile_options(-DPAL_STDCPP_COMPAT -DPLATFORM_UNIX -DUNICODE)
add_compile_options(-Wno-invalid-noreturn -Wno-macro-redefined)
add_compile_options(-stdlib=libstdc++ -DLINUX -Wno-pragmas)
if (ISMACOS)
add_compile_options(-stdlib=libc++ -DMACOS -Wno-pragma-pack)
elseif(ISLINUX)
add_compile_options(-stdlib=libstdc++ -DLINUX -Wno-pragmas)
endif()
if (BIT64)
add_compile_options(-DBIT64 -DHOST_64BIT)
endif()
Expand All @@ -104,6 +128,21 @@ elseif (ISARM)
add_compile_options(-DARM)
endif()

# ******************************************************
# Suppress Warning on MacOS
# ******************************************************

# Only necessary with cmake 3.19.x on macos
# See https://stackoverflow.com/questions/4929255/building-static-libraries-on-mac-using-cmake-and-gcc#answer-4953904

if (ISMACOS)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()


# ******************************************************
# Define shared target
# ******************************************************
Expand Down

0 comments on commit 7ce344e

Please sign in to comment.