Skip to content

Commit a182177

Browse files
committed
Add CMake find_package support and CTest integration
1 parent 8a7c594 commit a182177

4 files changed

Lines changed: 85 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Gtests
1+
GTests
22
Sample
3+
build/
34

45
## Ignore Visual Studio temporary files, build results, and
56
## files generated by popular Visual Studio add-ons.

CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(CppGeometryLibrary VERSION 1.0.0 LANGUAGES CXX)
3+
4+
# Header-only interface target
5+
add_library(CppGeometryLibrary INTERFACE)
6+
add_library(CppGeometryLibrary::CppGeometryLibrary ALIAS CppGeometryLibrary)
7+
8+
target_include_directories(CppGeometryLibrary INTERFACE
9+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
10+
$<INSTALL_INTERFACE:include>
11+
)
12+
target_compile_features(CppGeometryLibrary INTERFACE cxx_std_17)
13+
14+
# Tests (optional, enabled when this is the top-level project)
15+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
16+
include(CTest)
17+
if(BUILD_TESTING)
18+
find_package(GTest REQUIRED)
19+
add_executable(cpp_geometry_tests tests/Tests.cpp)
20+
target_link_libraries(cpp_geometry_tests
21+
PRIVATE CppGeometryLibrary GTest::GTest GTest::Main
22+
)
23+
add_test(NAME cpp_geometry_tests COMMAND cpp_geometry_tests)
24+
endif()
25+
endif()
26+
27+
# Installation
28+
include(GNUInstallDirs)
29+
30+
install(DIRECTORY include/
31+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
32+
)
33+
install(TARGETS CppGeometryLibrary
34+
EXPORT CppGeometryLibraryTargets
35+
)
36+
install(EXPORT CppGeometryLibraryTargets
37+
FILE CppGeometryLibraryTargets.cmake
38+
NAMESPACE CppGeometryLibrary::
39+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CppGeometryLibrary
40+
)
41+
42+
include(CMakePackageConfigHelpers)
43+
44+
configure_package_config_file(
45+
cmake/CppGeometryLibraryConfig.cmake.in
46+
${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfig.cmake
47+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CppGeometryLibrary
48+
)
49+
write_basic_package_version_file(
50+
${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfigVersion.cmake
51+
VERSION ${PROJECT_VERSION}
52+
COMPATIBILITY AnyNewerVersion
53+
)
54+
install(FILES
55+
${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfig.cmake
56+
${CMAKE_CURRENT_BINARY_DIR}/CppGeometryLibraryConfigVersion.cmake
57+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CppGeometryLibrary
58+
)

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ C++ Geometry Library provides utility functions for the computation of geometric
2525
* [Spherical](https://developers.google.com/maps/documentation/javascript/reference#spherical) contains spherical geometry utilities allowing you to compute angles, distances and areas from latitudes and longitudes.
2626
* [Poly](https://developers.google.com/maps/documentation/javascript/reference#poly) utility functions for computations involving polygons and polylines.
2727

28+
## Installation
29+
30+
### CMake (recommended)
31+
32+
```cmake
33+
find_package(CppGeometryLibrary REQUIRED)
34+
target_link_libraries(your_target PRIVATE CppGeometryLibrary::CppGeometryLibrary)
35+
```
36+
37+
Or embed directly with `add_subdirectory`:
38+
39+
```cmake
40+
add_subdirectory(cpp-geometry-library)
41+
target_link_libraries(your_target PRIVATE CppGeometryLibrary::CppGeometryLibrary)
42+
```
43+
44+
### Manual
45+
46+
Copy the `include/` directory into your project and add it to your include path.
47+
2848
## Usage
2949

3050
You just need to include `SphericalUtil.hpp` or `PolyUtil.hpp`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/CppGeometryLibraryTargets.cmake")
4+
5+
check_required_components(CppGeometryLibrary)

0 commit comments

Comments
 (0)