Skip to content

Commit

Permalink
Get peer building on a modern system, R libraries included
Browse files Browse the repository at this point in the history
  • Loading branch information
pettyalex committed Mar 5, 2024
1 parent 86b612e commit 9ad7518
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake on a single platform

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- uses: r-lib/actions/setup@v2
with:
r-version: '4.3.3'

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
28 changes: 17 additions & 11 deletions R/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (BUILD_R_PACKAGE)

find_package(Eigen3 REQUIRED)
link_libraries(Eigen3::Eigen)

include_directories(${PEER_SRC_DIR}/External/alglib)
include_directories(${PEER_SRC_DIR}/include)

Expand All @@ -28,36 +28,42 @@ if (BUILD_R_PACKAGE)
set_source_files_properties(peer.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(peer.i PROPERTIES SWIG_FLAGS "-includeall")
set_source_files_properties(peer.i PROPERTIES SWIG_FLAGS "-cpperraswarn")
swig_add_module(peer r peer.i)
swig_link_libraries(peer ${SWIGLINKLIBS})
swig_add_module(r-peer r peer.i)
swig_link_libraries(r-peer ${SWIGLINKLIBS})

ADD_CUSTOM_COMMAND(
TARGET peer POST_BUILD
TARGET r-peer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PEER_SOURCE_DIR}/R/peer
${PEER_SOURCE_DIR}/build/R/peer)

ADD_CUSTOM_COMMAND(
TARGET peer POST_BUILD
TARGET r-peer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PEER_SOURCE_DIR}/build/R/peerR_wrap.cxx
${PEER_SOURCE_DIR}/build/R/CmakeFiles/r-peer.dir/peerR_wrap.cxx
${PEER_SOURCE_DIR}/build/R/peer/src/peerR_wrap.cpp)

ADD_CUSTOM_COMMAND(
TARGET peer POST_BUILD
TARGET r-peer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PEER_SOURCE_DIR}/build/R/peer.R
${PEER_SOURCE_DIR}/build/R/peer/R/peer.R)

# CMAKE was putting a --jobserver-auth-string into MAKEFLAGS that breaks R CMD INSTALL

if (BUILD_UNIVERSAL)
ADD_CUSTOM_COMMAND(
TARGET peer POST_BUILD
COMMAND R CMD INSTALL --build ${PEER_SOURCE_DIR}/build/R/peer
TARGET r-peer POST_BUILD
COMMAND MAKEFLAGS=-j8 R CMD INSTALL --build ${PEER_SOURCE_DIR}/build/R/peer
COMMENT "Building and installing the peer R package")
else (BUILD_UNIVERSAL)
ADD_CUSTOM_COMMAND(
TARGET peer POST_BUILD
COMMAND R CMD INSTALL --no-multiarch --build ${PEER_SOURCE_DIR}/build/R/peer
TARGET r-peer POST_BUILD
COMMAND env
COMMENT "print env")
ADD_CUSTOM_COMMAND(
TARGET r-peer POST_BUILD
COMMAND MAKEFLAGS=-j8 R CMD INSTALL --no-multiarch --build ${PEER_SOURCE_DIR}/build/R/peer
COMMENT "Building and installing the peer R package")
endif (BUILD_UNIVERSAL)

Expand Down
2 changes: 1 addition & 1 deletion R/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all: peer_wrap.cpp
R CMD SHLIB peer_wrap.cpp

peer_wrap.cpp: peer.i
swig -c++ -r -o peer_wrap.cpp -I../include -I../External -I.. peer.i
swig -c++ -r -o peer_wrap.cpp -I../include -I.. peer.i

clean:
$(RM) ./peer_wrap.so
Expand Down
2 changes: 1 addition & 1 deletion R/Makevars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_LIBS=-L./lib -lpeer
PKG_CPPFLAGS= -I ./../External -I .. -DSWIG
PKG_CPPFLAGS=-I.. -DSWIG
2 changes: 1 addition & 1 deletion R/peer/src/Makevars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_LIBS=-L./../../../src -lpeerlib -L./../../../External/alglib/src -lalglib
PKG_CPPFLAGS=-I./../../../../include -I./../../../../External/alglib -I./../../../../External/alglib/src -I./../../../../External -DSWIG
PKG_CPPFLAGS=-I./../../../../include -I./../../../../External/alglib -I./../../../../External/alglib/src -I"${CONDA_PREFIX}"/include/eigen3 -DSWIG
5 changes: 5 additions & 0 deletions cmake/FindR.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_FIND_APPBUNDLE "LAST")
endif()

# find the R binary

MESSAGE(STATUS "Looking for R executable")
Expand Down

0 comments on commit 9ad7518

Please sign in to comment.