Skip to content

Commit

Permalink
Add CMake support
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
phcerdan committed Oct 9, 2019
1 parent 9127f1b commit eab305d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
75 changes: 75 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${aabbcc_include_dir}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

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
)

5 changes: 5 additions & 0 deletions cmake/aabbccConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(hard_disc hard_disc.cc)
target_link_libraries(hard_disc PUBLIC aabbcc)

0 comments on commit eab305d

Please sign in to comment.