Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save romainreignier/5e2ba9657e9607c9c0ffd7e649ed1e71 to your computer and use it in GitHub Desktop.
Save romainreignier/5e2ba9657e9607c9c0ffd7e649ed1e71 to your computer and use it in GitHub Desktop.
GeographicLib CMake minimal
From 99c2d9fb36818f1a203477aab93f88d408bbf224 Mon Sep 17 00:00:00 2001
From: Romain Reignier <rre@robopec.com>
Date: Fri, 4 Sep 2020 11:57:41 +0200
Subject: [PATCH] Add CMake aliases to allow to use CMake targets
when GeographicLib is used as submodule/subdirectory.
See: https://cmake.org/cmake/help/v3.1/command/add_library.html#alias-libraries
In a CMake project including directly the GeographicLib source code as a
subdirectory with:
```
add_subdirectory(GeographicLib)
```
The GeographicLib targets are found properly with
`GeographicLib::GeographicLib`.
---
src/CMakeLists.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 941bac5b..1bffa8b6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,12 +9,15 @@ file (GLOB HEADERS
# Define the library and specify whether it is shared or not.
if (GEOGRAPHICLIB_SHARED_LIB)
add_library (${PROJECT_SHARED_LIBRARIES} SHARED ${SOURCES} ${HEADERS})
+ add_library(${PROJECT_NAME}::${PROJECT_SHARED_LIBRARIES} ALIAS ${PROJECT_SHARED_LIBRARIES})
endif ()
if (GEOGRAPHICLIB_STATIC_LIB)
add_library (${PROJECT_STATIC_LIBRARIES} STATIC ${SOURCES} ${HEADERS})
+ add_library(${PROJECT_NAME}::${PROJECT_STATIC_LIBRARIES} ALIAS ${PROJECT_STATIC_LIBRARIES})
endif ()
add_library (${PROJECT_INTERFACE_LIBRARIES} INTERFACE)
+add_library(${PROJECT_NAME}::${PROJECT_INTERFACE_LIBRARIES} ALIAS ${PROJECT_INTERFACE_LIBRARIES})
target_link_libraries (${PROJECT_INTERFACE_LIBRARIES}
INTERFACE ${PROJECT_LIBRARIES})
--
2.17.1
cmake_minimum_required(VERSION 3.1)
project(geographiclib_test)
add_subdirectory(GeographicLib)
add_executable(geo main.cpp)
target_link_libraries(geo GeographicLib::GeographicLib)
#include <iostream>
#include <GeographicLib/Geodesic.hpp>
int main()
{
const GeographicLib::Geodesic& geod = GeographicLib::Geodesic::WGS84();
double lat1 = 40.6, lon1 = -73.8, s12 = 5.5e6, azi1 = 51;
double lat2, lon2;
geod.Direct(lat1, lon1, azi1, s12, lat2, lon2);
std::cout << lat2 << " " << lon2 << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment