From b965b6bab194f8be2b46c1ca5de79951c43056cb Mon Sep 17 00:00:00 2001 From: RemiHelleboid Date: Fri, 14 Jan 2022 01:45:51 +0100 Subject: [PATCH] Modernization of the main CMakeLists.txt. It now support automatic fetching of nanoflan lib if it is not found on the system --- CMakeLists.txt | 64 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee342ab..296ee18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,58 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) + +project( + KernelDensityEstimation + VERSION "1.0.0" + DESCRIPTION "" + LANGUAGES C CXX) + +include(FetchContent) + +option(ENABLE_BUILD_TEST "Build the tests of the project" OFF) +option(ENABLE_BUILD_BENCHMARKS "Build the tests of the project" OFF) +option(ENABLE_BUILD_DEMO "Build the tests of the project" OFF) # Guard against in-source builds (got this from Eigen) -IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) - message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ") -ENDIF() +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message( + FATAL_ERROR + "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. " + ) +endif() set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -FIND_PACKAGE(Eigen3 REQUIRED) -find_package(nanoflann REQUIRED) +FetchContent_Declare( + nanoflann + GIT_REPOSITORY "https://github.com/jlblancoc/nanoflann" + GIT_TAG "b3e81831b847a77473e0da2ad7ee266b4f4e0d9a") + +# Get nanoflan lib +find_package(nanoflann) +if(NOT nanoflann_FOUND) + message("Fetching ynanoflann lib ...") + FetchContent_MakeAvailable(nanoflann) +endif() + +find_package(Eigen3 REQUIRED) + +set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra -Wfatal-errors") -include_directories(${EIGEN3_INCLUDE_DIR}) -include_directories(${NANOFLANN_INCLUDE_DIR}) -include_directories(${CMAKE_SOURCE_DIR}) +if(ENABLE_BUILD_TEST) + enable_testing() + add_subdirectory(test) +endif(ENABLE_BUILD_TEST) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra -Wfatal-errors") +if(ENABLE_BUILD_BENCHMARKS) + add_subdirectory(bench) +endif(ENABLE_BUILD_BENCHMARKS) -ENABLE_TESTING() +if(ENABLE_BUILD_DEMO) + add_subdirectory(data) + add_subdirectory(demo) +endif(ENABLE_BUILD_DEMO) -add_subdirectory(test) -add_subdirectory(bench) -add_subdirectory(data) -add_subdirectory(demo) +add_library(KernelDensityEstimation INTERFACE) +target_include_directories(KernelDensityEstimation INTERFACE src/) +target_link_libraries(KernelDensityEstimation INTERFACE Eigen3 nanoflann)