Skip to content
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
19 changes: 7 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@

cmake_minimum_required(VERSION 3.10...4.3)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/PeriDEM_Apple_LLVM.cmake")
peridem_apple_llvm_before_project()

#----------------------------------#
#<<<<<<<<<< Project name >>>>>>>>>>#
#----------------------------------#
project(PeriDEM VERSION 0.2.1 LANGUAGES CXX C)

# Homebrew LLVM on macOS: default CMAKE_AR is /usr/bin/ar while CMAKE_RANLIB may be
# llvm-ranlib; mixing them produces invalid .a archives (bogus members like "/").
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
get_filename_component(_PDEM_LLVM_BIN "${CMAKE_CXX_COMPILER}" DIRECTORY)
if(EXISTS "${_PDEM_LLVM_BIN}/llvm-ar" AND EXISTS "${_PDEM_LLVM_BIN}/llvm-ranlib")
set(CMAKE_AR "${_PDEM_LLVM_BIN}/llvm-ar" CACHE FILEPATH "Archiver for static libraries" FORCE)
set(CMAKE_RANLIB "${_PDEM_LLVM_BIN}/llvm-ranlib" CACHE FILEPATH "Ranlib for static libraries" FORCE)
endif()
endif()

set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/prashjha/PeriDEM")
set(CMAKE_PROJECT_DESCRIPTION "PeriDEM -- Peridynamics-based high-fidelity model for granular media")

Expand Down Expand Up @@ -82,8 +75,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif ()

# set standard to 23
set(CMAKE_CXX_STANDARD 23)
peridem_apple_llvm_after_project()

# C++20: std::format and related library facilities; no C++23-only features required in-tree.
set(CMAKE_CXX_STANDARD 20)

if (${Enable_CMAKE_Debug_Build})
message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ Following dependencies are included in the `PeriDEM` library in `external` folde
- [doxygen-awesome-css](https://github.com/jothepro/doxygen-awesome-css) (>= v2.3.3)
- [nlohmann_json](https://github.com/nlohmann/json) (>= 3.12.0)

### Pixi: Easiest method to build the library on ubuntu and mac

```sh
# run ubuntu using docker (we are using the same image we use to test the library)
docker run -it prashjha/peridem-base-noble

# we install pixi and add it to the path
curl -fsSL https://pixi.sh/install.sh | sh
export PATH="/root/.pixi/bin:$PATH"

# assuming we are now in root of docker image
cd user/
git clone git@github.com:prashjha/PeriDEM.git
cd PeriDEM/
pixi run test
```

### Building the code

If all the dependencies are installed on the global path (e.g., `/usr/local/`),
Expand Down Expand Up @@ -323,22 +340,6 @@ repository.
```
- External dependencies required on the target system: MPI, Threads, yaml-cpp, VTK (CommonCore/DataModel/IOXML), BLAS/LAPACK (Accelerate on macOS), Metis (found via bundled `FindMetis.cmake`), plus their transitive libraries. Ensure these are installed and discoverable (e.g., via `CMAKE_PREFIX_PATH` or system paths) when configuring consumers.

### Using docker to test the library
```sh
# run ubuntu using docker (we are using the same image we use to test the library)
docker run -it prashjha/peridem-base-noble

# we install pixi and add it to the path
curl -fsSL https://pixi.sh/install.sh | sh
export PATH="/root/.pixi/bin:$PATH"

# assuming we are now in root of docker image
cd user/
git clone git@github.com:prashjha/PeriDEM.git
cd PeriDEM/
pixi run test
```

### Future plans

We are trying to make PeriDEM MPI-friendly so that we can target large problems.
Expand Down
64 changes: 64 additions & 0 deletions cmake/PeriDEM_Apple_LLVM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -------------------------------------------
# PeriDEM — macOS + Homebrew LLVM helpers
# -------------------------------------------
# AppleClang (Xcode) builds skip most of this. Homebrew /opt/homebrew/opt/llvm/bin/clang++
# is CMAKE_CXX_COMPILER_ID "Clang" and needs consistent ar/ranlib, SDK, and libc++ linking.
#
# Usage from top-level CMakeLists.txt:
# include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/PeriDEM_Apple_LLVM.cmake")
# peridem_apple_llvm_before_project()
# project(...)
# peridem_apple_llvm_after_project()

macro(peridem_apple_llvm_before_project)
# CMake may use /usr/bin/ar with llvm-ranlib for upstream Clang, corrupting .a archives.
# Set AR/RANLIB before project() so generated static-library rules use llvm-ar consistently.
if(APPLE)
set(_pdem_cxx_for_ar "$ENV{CXX}")
if(NOT _pdem_cxx_for_ar AND DEFINED CMAKE_CXX_COMPILER)
set(_pdem_cxx_for_ar "${CMAKE_CXX_COMPILER}")
endif()
if(_pdem_cxx_for_ar)
get_filename_component(_PDEM_LLVM_BIN "${_pdem_cxx_for_ar}" DIRECTORY)
if(EXISTS "${_PDEM_LLVM_BIN}/llvm-ar" AND EXISTS "${_PDEM_LLVM_BIN}/llvm-ranlib")
set(CMAKE_AR "${_PDEM_LLVM_BIN}/llvm-ar" CACHE FILEPATH "Archiver for static libraries" FORCE)
set(CMAKE_RANLIB "${_PDEM_LLVM_BIN}/llvm-ranlib" CACHE FILEPATH "Ranlib for static libraries" FORCE)
endif()
unset(_PDEM_LLVM_BIN)
endif()
unset(_pdem_cxx_for_ar)
endif()

# clang-scan-deps (Ninja) may not get -isysroot; libc++ then misses system C headers (e.g. time.h).
if(APPLE AND NOT CMAKE_OSX_SYSROOT)
execute_process(
COMMAND xcrun --sdk macosx --show-sdk-path
OUTPUT_VARIABLE _pdem_osx_sysroot
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(_pdem_osx_sysroot)
set(CMAKE_OSX_SYSROOT "${_pdem_osx_sysroot}" CACHE PATH "macOS SDK root" FORCE)
endif()
unset(_pdem_osx_sysroot)
endif()
endmacro()

macro(peridem_apple_llvm_after_project)
# Link Homebrew libc++ when using upstream Clang + explicit SDK (avoids missing std::__1::__hash_memory).
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
get_filename_component(_PDEM_LLVM_BIN "${CMAKE_CXX_COMPILER}" DIRECTORY)
get_filename_component(_PDEM_LLVM_ROOT "${_PDEM_LLVM_BIN}" DIRECTORY)
set(_PDEM_LLVM_LIBCXX "${_PDEM_LLVM_ROOT}/lib/c++")
if(EXISTS "${_PDEM_LLVM_LIBCXX}/libc++.dylib")
set(_PDEM_LLVM_LIBCXX_LINK "-L${_PDEM_LLVM_LIBCXX} -Wl,-rpath,${_PDEM_LLVM_LIBCXX}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_PDEM_LLVM_LIBCXX_LINK}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_PDEM_LLVM_LIBCXX_LINK}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_PDEM_LLVM_LIBCXX_LINK}")
endif()
unset(_PDEM_LLVM_LIBCXX_LINK)
unset(_PDEM_LLVM_LIBCXX)
unset(_PDEM_LLVM_ROOT)
unset(_PDEM_LLVM_BIN)
endif()
endmacro()
2 changes: 1 addition & 1 deletion src/rw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AUX_SOURCE_DIRECTORY(./ SOURCES)

add_library(RW ${SOURCES})

target_link_libraries(RW PUBLIC ${VTK_LIBRARIES})
target_link_libraries(RW PUBLIC Util ${VTK_LIBRARIES})

target_include_directories(RW
PUBLIC
Expand Down
Loading
Loading