Skip to content

Commit

Permalink
Only attempt to link to igraph if it can be found.
Browse files Browse the repository at this point in the history
This allows us to handle situations where igraph is being made available
outside of Cmake, e.g., by manual addition of -I directories.
  • Loading branch information
LTLA committed Oct 6, 2024
1 parent 66ede09 commit 61c95ce
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 47 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/check-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@ jobs:
- name: Get latest CMake
uses: lukka/get-cmake@latest

- name: Cache installed igraph
id: cache-igraph
uses: actions/cache@v4
with:
path: _deps
key: libigraph

- name: Make and install igraph
if: ${{ steps.cache-igraph.outputs.cache-hit != 'true' }}
run: |
version=0.10.13
path=$(pwd)
wget https://github.com/igraph/igraph/releases/download/${version}/igraph-${version}.tar.gz
tar -xf igraph-${version}.tar.gz
cd igraph-${version}
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=${path}/_deps
cmake --build .
sudo cmake --install .
- name: Configure the build
run: cmake -S . -B build -DSCRAN_GRAPH_CLUSTER_TESTS=OFF -DCMAKE_PREFIX_PATH=_deps

Expand Down
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.14)

project(scran_graph_cluster
VERSION 0.1.1
VERSION 0.1.2
DESCRIPTION "Cluster cells using graph-based methods"
LANGUAGES CXX)

Expand All @@ -19,22 +19,22 @@ target_compile_features(scran_graph_cluster INTERFACE cxx_std_17)

# Dependencies
option(SCRAN_GRAPH_CLUSTER_FETCH_EXTERN "Automatically fetch scran_graph_cluster's external dependencies (except for igraph)." ON)
option(SCRAN_GRAPH_CLUSTER_FETCH_EXTERN_IGRAPH "Automatically fetch scran_graph_cluster's external igraph dependency." OFF)

if (NOT SCRAN_GRAPH_CLUSTER_FETCH_EXTERN_IGRAPH)
# igraph needs compilation so we just try to get it from the system by
# default, rather than pulling it down and building the whole thing.
find_package(igraph 0.10.0 CONFIG REQUIRED)
endif()

if(SCRAN_GRAPH_CLUSTER_FETCH_EXTERN)
add_subdirectory(extern)
else()
find_package(ltla_raiigraph 1.1.0 CONFIG REQUIRED)
find_package(knncolle_knncolle 2.0.0 CONFIG REQUIRED)
endif()

target_link_libraries(scran_graph_cluster INTERFACE igraph::igraph ltla::raiigraph knncolle::knncolle)
target_link_libraries(scran_graph_cluster INTERFACE ltla::raiigraph knncolle::knncolle)

option(SCRAN_GRAPH_CLUSTER_FIND_IGRAPH "Search for the igraph package." ON)
if(SCRAN_GRAPH_CLUSTER_FIND_IGRAPH)
find_package(igraph 0.10.0 CONFIG)
if (igraph_FOUND)
target_link_libraries(scran_graph_cluster INTERFACE igraph::igraph)
endif()
endif()

# Tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ target_link_libraries(myexe libscran::scran_graph_cluster)
target_link_libraries(mylib INTERFACE libscran::scran_graph_cluster)
```

This will fetch all external dependencies except for [**igraph**](https://igraph.org), which should already be installed.
We can instruct CMake to fetch and build **igraph** by setting `-DSCRAN_GRAPH_CLUSTER_FETCH_EXTERN_IGRAPH=ON`.
This will fetch all external dependencies except for [**igraph**](https://igraph.org), which should already be installed and available via `find_package()`.
Users can set the `SCRAN_GRAPH_CLUSTER_FIND_IGRAPH` option to disable **igraph** discovery (e.g., to supply a custom **igraph** installation),
in which case they will need to link to **igraph** manually in their `target_link_libraries()` call.

### CMake with `find_package()`

Expand All @@ -99,8 +100,9 @@ cmake --build . --target install
By default, this will use `FetchContent` to fetch all external dependencies.
If you want to install them manually, use `-DSCRAN_GRAPH_CLUSTER_FETCH_EXTERN=OFF`.
See the tags in [`extern/CMakeLists.txt`](extern/CMakeLists.txt) to find compatible versions of each dependency.
Again, **igraph** is assumed to be installed and available via `find_package()`.

### Manual

If you're not using CMake, the simple approach is to just copy the files in `include/` - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's `-I`.
This requires the external dependencies listed in [`extern/CMakeLists.txt`](extern/CMakeLists.txt), which also need to be made available during compilation.
This requires the external dependencies listed in [`extern/CMakeLists.txt`](extern/CMakeLists.txt) as well as the **igraph** library.
7 changes: 6 additions & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

include(CMakeFindDependencyMacro)
find_dependency(knncolle_knncolle 2.0.0 CONFIG REQUIRED)
find_dependency(igraph 0.10.0 CONFIG REQUIRED)
find_dependency(ltla_raiigraph 1.1.0 CONFIG REQUIRED)

if(@SCRAN_GRAPH_CLUSTER_FIND_IGRAPH@)
# Not REQUIRED, so don't use find_dependency according to
# https://stackoverflow.com/questions/64846805/how-do-i-specify-an-optional-dependency-in-a-cmake-package-configuration-file
find_package(igraph 0.10.0 CONFIG)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/libscran_scran_graph_clusterTargets.cmake")
13 changes: 0 additions & 13 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
include(FetchContent)

if (SCRAN_MARKERS_FETCH_EXTERN_IGRAPH)
FetchContent_Declare(
igraph
GIT_REPOSITORY https://github.com/igraph/igraph
GIT_TAG master # ^0.10.0
)
endif()

FetchContent_Declare(
knncolle
GIT_REPOSITORY https://github.com/knncolle/knncolle
Expand All @@ -21,10 +13,5 @@ FetchContent_Declare(
)

FetchContent_MakeAvailable(knncolle)

if (SCRAN_MARKERS_FETCH_EXTERN_IGRAPH)
FetchContent_MakeAvailable(igraph)
endif()

FetchContent_MakeAvailable(raiigraph)

0 comments on commit 61c95ce

Please sign in to comment.