Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Simulation/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,21 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
if(ENABLE_OPENMP)

if (APPLE)
set(OPENMP_PATH "/usr/local/opt/libomp")
set(OPENMP_COMPILER_FLAGS "-Xpreprocessor -fopenmp -I${OPENMP_PATH}/include -lomp -L${OPENMP_PATH}/lib")
set(OPENMP_LOCAL_PATH "${PROJECT_SOURCE_DIR}/osx")
# Note we use `-rpath @loader_path` to ensure the produced binary includes the folder of the binary
# itself in the runtime search path for dynamic library load, regardless of environment settings.
# We don't use `@executable_path` because that takes into account recursive dependencies and will be
# the folder of the originally launched binary (root of the dependency tree) instead of loading binary
# (the immediate parent in the dependency tree), which will be the simulatory library itself.
# See https://www.man7.org/linux/man-pages/man1/ld.1.html and https://stackoverflow.com/questions/52981210/linking-with-dylib-library-from-the-command-line-using-clang
set(OPENMP_COMPILER_FLAGS "-Xpreprocessor -fopenmp -I${OPENMP_LOCAL_PATH}/include -L${OPENMP_LOCAL_PATH} -lomp -rpath @loader_path")
set(OPENMP_LIB_NAME "omp")

set(OpenMP_CXX_FLAGS "${OPENMP_COMPILER_FLAGS}")
set(OpenMP_C_FLAGS "${OPENMP_COMPILER_FLAGS}")
set(OpenMP_CXX_LIB_NAMES "${OPENMP_LIB_NAME}")
set(OpenMP_C_LIB_NAMES "${OPENMP_LIB_NAME}")
set(OpenMP_omp_LIBRARY "${OPENMP_PATH}/lib/libomp.dylib")
set(OpenMP_omp_LIBRARY "${OPENMP_LOCAL_PATH}/libomp.dylib")
endif()

find_package(OpenMP)
Expand Down
15 changes: 15 additions & 0 deletions src/Simulation/Native/build-native-simulator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

Write-Host "##[info]Build Native simulator for $Env:BUILD_CONFIGURATION"

if ($IsMacOS) {
# To ensure loading succeeds on Mac the install id of the library needs to be updated to use
# paths relative to target dynamic load path. Otherwise it will keep the full path encoding in the
# library from when it was built by homebrew.
# See https://stackoverflow.com/questions/52981210/linking-with-dylib-library-from-the-command-line-using-clang
Write-Host "##[info]Fixing binary dependencies with install_name_tool..."
install_name_tool -id "@rpath/libomp.dylib" (Join-Path $PSScriptRoot osx libomp.dylib)
}


$nativeBuild = (Join-Path $PSScriptRoot "build")
if (-not (Test-Path $nativeBuild)) {
Expand Down Expand Up @@ -72,6 +81,12 @@ else {
}
cmake --build . --config "$Env:BUILD_CONFIGURATION" --target install

if ($IsMacOS) {
Write-Host "##[info]Copying libomp..."
Copy-Item -Verbose (Join-Path $PSScriptRoot osx libomp.dylib) (Join-Path $PSScriptRoot build)
Copy-Item -Verbose (Join-Path $PSScriptRoot osx libomp.dylib) (Join-Path $PSScriptRoot build drop)
}

Pop-Location


Expand Down
1,376 changes: 1,376 additions & 0 deletions src/Simulation/Native/osx/include/omp-tools.h

Large diffs are not rendered by default.

Loading