From eab305d6835b2eee507965d5989b4791c91ca8d3 Mon Sep 17 00:00:00 2001 From: Pablo Hernandez-Cerdan Date: Tue, 8 Oct 2019 19:45:54 +0200 Subject: [PATCH] Add CMake support - Creates aabbcc library - Creates Targets and Config file for easy usage by third party libraries using find_package(aabbcc) - Add option to build the demo/hard_disc Missing/TODO: - Add option to build python wrapping - Add target to create the header-only version --- CMakeLists.txt | 75 +++++++++++++++++++++++++++++++++++++ cmake/aabbccConfig.cmake.in | 5 +++ demos/CMakeLists.txt | 2 + 3 files changed, 82 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/aabbccConfig.cmake.in create mode 100644 demos/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..059461f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.9) +project(aabbcc + VERSION 0.1.0 + LANGUAGES CXX) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +set(CMAKE_INCLUDE_CURRENT_DIR ON) +include(GNUInstallDirs) # Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR + +option(AABBCC_BUILD_DEMOS "Build demos" OFF) +mark_as_advanced(AABBCC_BUILD_DEMOS) + +add_library(aabbcc src/AABB.cc) +set(aabbcc_include_dir src) +set(aabbcc_export_file "${PROJECT_BINARY_DIR}/aabbccTargets.cmake") + +target_include_directories(aabbcc PUBLIC + $ + $) + +install(TARGETS aabbcc + EXPORT aabbccTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${aabbcc_include_dir}/AABB.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aabbcc) + +# export to the build tree +export( TARGETS aabbcc + NAMESPACE aabbcc:: + APPEND FILE ${aabbcc_export_file}) + +if(AABBCC_BUILD_DEMOS) + add_subdirectory(demos) +endif() + +# Install targets and config files +set(install_cmake_dir "${CMAKE_INSTALL_LIBDIR}/cmake/aabbcc") +install (EXPORT aabbccTargets + NAMESPACE aabbcc:: + DESTINATION ${install_cmake_dir} ) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/aabbccConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/aabbccConfigVersion.cmake + DESTINATION ${install_cmake_dir} ) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file(aabbccConfigVersion.cmake + VERSION ${aabbcc_VERSION} + COMPATIBILITY SameMajorVersion) + +# Build tree +set(aabbcc_TARGETS_FILE ${aabbcc_export_file}) +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/aabbccConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/aabbccConfig.cmake + INSTALL_DESTINATION ${install_cmake_dir} + PATH_VARS aabbcc_TARGETS_FILE + NO_CHECK_REQUIRED_COMPONENTS_MACRO # aabbcc does not provide components + INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR} + ) + +# Install tree +set(aabbcc_TARGETS_FILE ${CMAKE_INSTALL_PREFIX}/${install_cmake_dir}/aabbccTargets.cmake) +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/aabbccConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/aabbccConfig.cmake + INSTALL_DESTINATION ${install_cmake_dir} + PATH_VARS aabbcc_TARGETS_FILE + NO_CHECK_REQUIRED_COMPONENTS_MACRO # aabbcc does not provide components + ) + diff --git a/cmake/aabbccConfig.cmake.in b/cmake/aabbccConfig.cmake.in new file mode 100644 index 0000000..1dd3a8c --- /dev/null +++ b/cmake/aabbccConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ +get_filename_component(aabbcc_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +if(NOT TARGET aabbcc) + include ("${aabbcc_CMAKE_DIR}/aabbccTargets.cmake") +endif() diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt new file mode 100644 index 0000000..ca33a09 --- /dev/null +++ b/demos/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(hard_disc hard_disc.cc) +target_link_libraries(hard_disc PUBLIC aabbcc)