Skip to content

Commit 61c95ce

Browse files
committed
Only attempt to link to igraph if it can be found.
This allows us to handle situations where igraph is being made available outside of Cmake, e.g., by manual addition of -I directories.
1 parent 66ede09 commit 61c95ce

File tree

5 files changed

+21
-47
lines changed

5 files changed

+21
-47
lines changed

.github/workflows/check-install.yaml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ jobs:
1616
- name: Get latest CMake
1717
uses: lukka/get-cmake@latest
1818

19-
- name: Cache installed igraph
20-
id: cache-igraph
21-
uses: actions/cache@v4
22-
with:
23-
path: _deps
24-
key: libigraph
25-
26-
- name: Make and install igraph
27-
if: ${{ steps.cache-igraph.outputs.cache-hit != 'true' }}
28-
run: |
29-
version=0.10.13
30-
path=$(pwd)
31-
wget https://github.com/igraph/igraph/releases/download/${version}/igraph-${version}.tar.gz
32-
tar -xf igraph-${version}.tar.gz
33-
cd igraph-${version}
34-
mkdir build && cd build
35-
cmake .. -DCMAKE_INSTALL_PREFIX=${path}/_deps
36-
cmake --build .
37-
sudo cmake --install .
38-
3919
- name: Configure the build
4020
run: cmake -S . -B build -DSCRAN_GRAPH_CLUSTER_TESTS=OFF -DCMAKE_PREFIX_PATH=_deps
4121

CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22

33
project(scran_graph_cluster
4-
VERSION 0.1.1
4+
VERSION 0.1.2
55
DESCRIPTION "Cluster cells using graph-based methods"
66
LANGUAGES CXX)
77

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

2020
# Dependencies
2121
option(SCRAN_GRAPH_CLUSTER_FETCH_EXTERN "Automatically fetch scran_graph_cluster's external dependencies (except for igraph)." ON)
22-
option(SCRAN_GRAPH_CLUSTER_FETCH_EXTERN_IGRAPH "Automatically fetch scran_graph_cluster's external igraph dependency." OFF)
23-
24-
if (NOT SCRAN_GRAPH_CLUSTER_FETCH_EXTERN_IGRAPH)
25-
# igraph needs compilation so we just try to get it from the system by
26-
# default, rather than pulling it down and building the whole thing.
27-
find_package(igraph 0.10.0 CONFIG REQUIRED)
28-
endif()
29-
3022
if(SCRAN_GRAPH_CLUSTER_FETCH_EXTERN)
3123
add_subdirectory(extern)
3224
else()
3325
find_package(ltla_raiigraph 1.1.0 CONFIG REQUIRED)
3426
find_package(knncolle_knncolle 2.0.0 CONFIG REQUIRED)
3527
endif()
3628

37-
target_link_libraries(scran_graph_cluster INTERFACE igraph::igraph ltla::raiigraph knncolle::knncolle)
29+
target_link_libraries(scran_graph_cluster INTERFACE ltla::raiigraph knncolle::knncolle)
30+
31+
option(SCRAN_GRAPH_CLUSTER_FIND_IGRAPH "Search for the igraph package." ON)
32+
if(SCRAN_GRAPH_CLUSTER_FIND_IGRAPH)
33+
find_package(igraph 0.10.0 CONFIG)
34+
if (igraph_FOUND)
35+
target_link_libraries(scran_graph_cluster INTERFACE igraph::igraph)
36+
endif()
37+
endif()
3838

3939
# Tests
4040
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ target_link_libraries(myexe libscran::scran_graph_cluster)
7878
target_link_libraries(mylib INTERFACE libscran::scran_graph_cluster)
7979
```
8080

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

8485
### CMake with `find_package()`
8586

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

103105
### Manual
104106

105107
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`.
106-
This requires the external dependencies listed in [`extern/CMakeLists.txt`](extern/CMakeLists.txt), which also need to be made available during compilation.
108+
This requires the external dependencies listed in [`extern/CMakeLists.txt`](extern/CMakeLists.txt) as well as the **igraph** library.

cmake/Config.cmake.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
include(CMakeFindDependencyMacro)
44
find_dependency(knncolle_knncolle 2.0.0 CONFIG REQUIRED)
5-
find_dependency(igraph 0.10.0 CONFIG REQUIRED)
65
find_dependency(ltla_raiigraph 1.1.0 CONFIG REQUIRED)
76

7+
if(@SCRAN_GRAPH_CLUSTER_FIND_IGRAPH@)
8+
# Not REQUIRED, so don't use find_dependency according to
9+
# https://stackoverflow.com/questions/64846805/how-do-i-specify-an-optional-dependency-in-a-cmake-package-configuration-file
10+
find_package(igraph 0.10.0 CONFIG)
11+
endif()
12+
813
include("${CMAKE_CURRENT_LIST_DIR}/libscran_scran_graph_clusterTargets.cmake")

extern/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
include(FetchContent)
22

3-
if (SCRAN_MARKERS_FETCH_EXTERN_IGRAPH)
4-
FetchContent_Declare(
5-
igraph
6-
GIT_REPOSITORY https://github.com/igraph/igraph
7-
GIT_TAG master # ^0.10.0
8-
)
9-
endif()
10-
113
FetchContent_Declare(
124
knncolle
135
GIT_REPOSITORY https://github.com/knncolle/knncolle
@@ -21,10 +13,5 @@ FetchContent_Declare(
2113
)
2214

2315
FetchContent_MakeAvailable(knncolle)
24-
25-
if (SCRAN_MARKERS_FETCH_EXTERN_IGRAPH)
26-
FetchContent_MakeAvailable(igraph)
27-
endif()
28-
2916
FetchContent_MakeAvailable(raiigraph)
3017

0 commit comments

Comments
 (0)