On Debian, I've installed cmake and geographiclib like so:
stew@stewbian:~$apt-get install build-essential cmake libgeographic-dev
My CMakeLists.txt file looks like so:
cmake_minimum_required(VERSION 3.7)
project(geoexample)
find_package(GeographicLib REQUIRED)
add_executable(geoexample main.cpp)
target_include_directories(geoexample PRIVATE ${GeographicLib_INCLUDE_DIRS})
target_compile_definitions(geoexample PRIVATE ${GeographicLib_DEFINITIONS})
target_link_libraries (geoexample ${GeographicLib_LIBRARIES})
My main.cpp is also very simple (taken directly from examples):
#include <iostream>
#include <GeographicLib/Geodesic.hpp>
using namespace std;
using namespace GeographicLib;
int main() {
const Geodesic& geod = Geodesic::WGS84();
// Distance from JFK to LHR
double
lat1 = 40.6, lon1 = -73.8, // JFK Airport
lat2 = 51.6, lon2 = -0.5; // LHR Airport
double s12;
geod.Inverse(lat1, lon1, lat2, lon2, s12);
cout << s12 / 1000 << " km\n";
return 0;
}
When I run mkdir build && cd build && cmake ..
I get
stew@stewbian:~/src/geoexample/build$ cmake ..
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindGeographicLib.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"GeographicLib", but CMake did not find one.
I think that by default, cmake searches /usr/share/cmake-3.7/Modules
, but libgeographic-dev seems to have installed its Find*.cmake to /usr/share/cmake/geographiclib/FindGeographicLib.cmake
. That's frustrating, but myself (plus everyone who will ever need to compile my code) should be able to use a work-around for this simple case (it wouldn't work so well if I need to also include something like FindBoost.cmake from the old location).
stew@stewbian:~/src/geoexample/build$ cmake .. -DCMAKE_MODULE_PATH=/usr/share/cmake/geographiclib
CMake Error at /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find GeographicLib (missing: GeographicLib_LIBRARY_DIRS
GeographicLib_INCLUDE_DIRS)
Call Stack (most recent call first):
/usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake/geographiclib/FindGeographicLib.cmake:28 (find_package_handle_standard_args)
CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
Now I'm not sure what to do here. I can confirm that libgeographic-dev package installed /usr/lib/x86_64-linux-gnu/libGeographic.a
and /usr/lib/x86_64-linux-gnu/libGeographic.so