Skip to content

Commit d394fc5

Browse files
Add PackageProject installation for find_package support (#553)
* Add Project Interface Library + PackageProject install configuration * Added build-time configuration of version.h * clang-format * Add Major, Minor, Patch versions back to version.h.in * Make test_exe link to the new project interface target * Link benchmark_exe to new project interface target * Add .cache ignore
1 parent 8f05442 commit d394fc5

File tree

8 files changed

+70
-21
lines changed

8 files changed

+70
-21
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ packaging/
4040
.code-workspace
4141
CXXGraph.code-workspace
4242
# ignore visual studio files
43-
.vs
43+
.vs
44+
45+
# cache directories
46+
.cache

CMakeLists.txt

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required(VERSION 3.9)
22

33
# set the project name and version
44
project(CXXGraph VERSION 4.1.0)
5-
6-
configure_file(CXXGraphConfig.h.in ${PROJECT_SOURCE_DIR}/include/CXXGraph/CXXGraphConfig.h)
7-
5+
set(PROJECT_NAMESPACE ${PROJECT_NAME})
86
# specify the C++ standard
97
set(CMAKE_CXX_STANDARD 17)
108
set(CMAKE_CXX_STANDARD_REQUIRED True)
@@ -56,4 +54,52 @@ add_subdirectory(test)
5654
add_subdirectory(benchmark)
5755
add_subdirectory(examples)
5856

59-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)
57+
configure_file(${PROJECT_SOURCE_DIR}/include/CXXGraph/version.h.in ${PROJECT_BINARY_DIR}/include/CXXGraph/version.h)
58+
59+
include(${CPM_DOWNLOAD_LOCATION})
60+
add_library(${PROJECT_NAME} INTERFACE)
61+
target_include_directories(${PROJECT_NAME} INTERFACE
62+
#Main include dir
63+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
64+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
65+
#Version include dir:
66+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
67+
)
68+
CPMAddPackage("gh:TheLartians/[email protected]")
69+
70+
packageProject(
71+
# the name of the target to export
72+
NAME ${PROJECT_NAME}
73+
# the version of the target to export
74+
VERSION ${PROJECT_VERSION}
75+
# a temporary directory to create the config files
76+
BINARY_DIR ${PROJECT_BINARY_DIR}
77+
# location of the target's public headers
78+
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
79+
# should match the target's INSTALL_INTERFACE include directory
80+
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
81+
# (optional) option to install only header files with matching pattern
82+
INCLUDE_HEADER_PATTERN "*.h *.hpp"
83+
# semicolon separated list of the project's dependencies
84+
DEPENDENCIES ""
85+
# (optional) create a header containing the version info
86+
VERSION_HEADER "${PROJECT_NAME}/version.h"
87+
# (optional) create a export header using GenerateExportHeader module
88+
EXPORT_HEADER "${PROJECT_NAME}/export.h"
89+
# (optional) install your library with a namespace (Note: do NOT add extra '::')
90+
NAMESPACE ${PROJECT_NAMESPACE}
91+
# (optional) define the project's version compatibility, defaults to `AnyNewerVersion`
92+
# supported values: `AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion`
93+
COMPATIBILITY AnyNewerVersion
94+
# (optional) option to disable the versioning of install destinations
95+
DISABLE_VERSION_SUFFIX YES
96+
# (optional) option to ignore target architecture for package resolution
97+
# defaults to YES for header only (i.e. INTERFACE) libraries
98+
ARCH_INDEPENDENT YES
99+
# (optional) option to generate CPack variables
100+
CPACK YES
101+
# (optional) relative install directory for runtimes: bins, libs, archives
102+
# by default libs will be installed to <...>/lib/<packagename-version>/
103+
# / - means relative to <...>/lib, i.e. install libs to <...>/lib/, bins to <...>/bin/, etc
104+
RUNTIME_DESTINATION /
105+
)

CXXGraphConfig.h.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

benchmark/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ if(BENCHMARK)
4242
PUBLIC WITH_COMPRESSION
4343
)
4444
target_include_directories(benchmark_exe PUBLIC
45-
PUBLIC ${PROJECT_SOURCE_DIR}/include
4645
PUBLIC ${zlib_BINARY_DIR}
4746
PUBLIC ${zlib_SOURCE_DIR}
4847
)
4948
target_link_libraries(benchmark_exe
50-
PUBLIC GTest::gtest
51-
PUBLIC benchmark::benchmark
52-
PUBLIC zlibstatic
49+
PUBLIC
50+
GTest::gtest
51+
benchmark::benchmark
52+
zlibstatic
53+
${PROJECT_NAME}
5354
)
5455

5556
# Ensure benchmark_exe itself is built in Release mode

include/CXXGraph/CXXGraph.hpp

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef __CXXGRAPH_H__
22
#define __CXXGRAPH_H__
33

4-
#include "CXXGraph/CXXGraphConfig.h"
54
#include "CXXGraph/Edge/DirectedEdge.h"
65
#include "CXXGraph/Edge/DirectedWeightedEdge.h"
76
#include "CXXGraph/Edge/Edge.h"
@@ -24,5 +23,6 @@
2423
#include "CXXGraph/Partitioning/PartitionerThread.hpp"
2524
#include "CXXGraph/Partitioning/PartitioningStats.hpp"
2625
#include "CXXGraph/Partitioning/Record.hpp"
26+
#include "CXXGraph/version.h"
2727

2828
#endif // __CXXGRAPH_H__

include/CXXGraph/CXXGraphConfig.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

include/CXXGraph/version.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#define CXXGraph_VERSION "@PROJECT_VERSION@"
4+
#define CXXGraph_VERSION_MAJOR "@PROJECT_VERSION_MAJOR"
5+
#define CXXGraph_VERSION_MINOR "@PROJECT_VERSION_MINOR"
6+
#define CXXGraph_VERSION_PATCH "@PROJECT_VERSION_PATCH"

test/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ if(TEST)
6666
PUBLIC WITH_COMPRESSION
6767
)
6868
target_include_directories(test_exe
69-
PUBLIC "${PROJECT_SOURCE_DIR}/include"
7069
PUBLIC ${zlib_BINARY_DIR}
7170
PUBLIC ${zlib_SOURCE_DIR}
7271
)
7372

7473
target_link_libraries(test_exe
75-
PUBLIC GTest::gtest_main
76-
PUBLIC zlibstatic
74+
PUBLIC
75+
GTest::gtest_main
76+
zlibstatic
77+
${PROJECT_NAME}
7778
)
7879

7980
if(NOT gtest_disable_pthreads)

0 commit comments

Comments
 (0)