diff --git a/CMakeLists.txt b/CMakeLists.txt index 72ef501..8fddf69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,132 @@ -cmake_minimum_required( VERSION 3.2.2 ) -project( mio ) +cmake_minimum_required(VERSION 3.8) -### Standard -set( CMAKE_CXX_STANDARD 11 ) +# +# Here we check whether frozen is being configured in isolation or as a component +# of a larger proeject. To do so, we query whether the `PROJECT_NAME` CMake +# variable has been defined. In the case it has, we can conclude mio is a +# subproject. +# +# This convention has been borrowed from the Catch C++ unit testing library. +# +if(DEFINED PROJECT_NAME) + set(subproject ON) +else() + set(subproject OFF) +endif() + +project(mio VERSION 1.0.0 LANGUAGES C CXX) +include (CTest) +include (CMakeDependentOption) # Generate 'compile_commands.json' for clang_complete -set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -### Flags/Options -option( BUILD_TESTS "Enable the building of mio unit tests" OFF ) +# +# The `mio.testing` options only appear as cmake-gui and ccmake options iff +# mio is the highest level project. In the case that mio is a subproject, these +# options are hidden from the user interface and set to `OFF` +# +# Iff mio is the highest level project, this option is defaulted to the value +# of the traditional course grain testing option `BUILD_TESTING` established by +# the CTest module +# +CMAKE_DEPENDENT_OPTION(mio.tests + "Build the frozen tests and integrate with ctest" + ${BUILD_TESTING} "NOT subproject" OFF) -### Library targets -add_library( mio INTERFACE) -target_include_directories( mio INTERFACE include ) -install( - DIRECTORY include/ - DESTINATION include -) +# +# mio has no compiled components. As such, we declare it as an `INTERFACE` +# library, which denotes a collection of target properties to be applied +# transitively to linking targets. In our case, this amounts to an include +# directory and project header files. +# +add_library(mio INTERFACE) +add_library(mio::mio ALIAS mio) -### Test targets -if( BUILD_TESTS ) - ## test - add_executable( - test - test/test.cpp - ) - target_link_libraries( test PRIVATE mio ) - - ## example - add_executable( - example - test/example.cpp - ) - target_link_libraries( example PRIVATE mio ) +# +# mio requires C++ 11 support, at a minimum. Setting the `cxx_std_11` compile +# features ensures that the corresponding C++ standard flag is populated in +# targets linking to mio +# +target_compile_features(mio INTERFACE cxx_std_11) + +# +# The include directory for mio can be expected to vary between build +# and installaion. Here we use a CMake generator expression to dispatch +# on how the configuration under which this library is being consumed. +# +target_include_directories(mio INTERFACE + $ + $) + +add_subdirectory(include/mio) + +if(mio.tests) + add_subdirectory(test) endif() + +# +# Non-testing header files (preserving relative paths) are installed to the +# `include` subdirectory of the `$INSTALL_DIR/${CMAKE_INSTALL_PREFIX}` +# directory. Source file permissions preserved. +# +install(DIRECTORY include/ + DESTINATION include + USE_SOURCE_PERMISSIONS + FILES_MATCHING PATTERN "*.*pp") + +# +# As a header-only library, there are no target components to be installed +# directly (the PUBLIC_HEADER property is not white listed for INTERFACE +# targets for some reason). +# +# However, it is worthwhile export our target description in order to later +# generate a CMake configuration file for consumption by CMake's `find_package` +# intrinsic +# +install(TARGETS mio EXPORT mioConfig) +install(EXPORT mioConfig + FILE mioConfig.cmake + NAMESPACE mio:: + DESTINATION share/cmake/mio + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) + +include(CMakePackageConfigHelpers) # provides `write_basic_package_version_file` +write_basic_package_version_file("mioConfigVersion.cmake" + VERSION ${mio_VERSION} + COMPATIBILITY SameMajorVersion) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mioConfigVersion.cmake" + DESTINATION share/cmake/mio + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) + +# +# Rudimentary CPack support. +# +# CPack provides a mechanism to generate installation packaging for a project, +# e.g., self-extracting shell scripts, compressed tarballs, Debian Package files, +# RPM Package Manager files, Windows NSIS installation wizards, +# Apple Disk Images (.dmg), etc. +# +# Any system libraries required (runtimes, threading, etc) should be bundled +# with the project for this type of installation. The +# `InstallRequiredSystemLibraries` CMake module attempts to provide this +# functionality in an automated way. Additional libraries may be specified as +# +# ```cmake +# list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ) +# ``` +# +# A packaged installation can be generated by calling +# +# ```sh +# cpack -G --config CPackConfig.cmake +# ``` +# +# See `cpack --help` or the CPack documentation for more information. +# +include( InstallRequiredSystemLibraries ) +set( CPACK_PACKAGE_VENDOR "mandreyel" ) +set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" ) +set( CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/mandreyel/mio" ) +include( CPack ) diff --git a/include/mio/CMakeLists.txt b/include/mio/CMakeLists.txt new file mode 100644 index 0000000..00b89a7 --- /dev/null +++ b/include/mio/CMakeLists.txt @@ -0,0 +1,11 @@ +target_sources(mio INTERFACE + $ + $) + +add_subdirectory(detail) diff --git a/include/mio/detail/CMakeLists.txt b/include/mio/detail/CMakeLists.txt new file mode 100644 index 0000000..1a678c0 --- /dev/null +++ b/include/mio/detail/CMakeLists.txt @@ -0,0 +1,7 @@ +if(NOT subproject) + target_sources(mio INTERFACE + $) +endif() diff --git a/include/mio/detail/basic_mmap.hpp b/include/mio/detail/basic_mmap.hpp index f5d3303..4582626 100644 --- a/include/mio/detail/basic_mmap.hpp +++ b/include/mio/detail/basic_mmap.hpp @@ -21,7 +21,7 @@ #ifndef MIO_BASIC_MMAP_HEADER #define MIO_BASIC_MMAP_HEADER -#include "../page.hpp" +#include "mio/page.hpp" #include #include @@ -159,6 +159,6 @@ bool operator>=(const basic_mmap& a, const basic_mmap& b); } // namespace detail } // namespace mio -#include "basic_mmap.ipp" +#include "mio/detail/basic_mmap.ipp" #endif // MIO_BASIC_MMAP_HEADER diff --git a/include/mio/detail/basic_mmap.ipp b/include/mio/detail/basic_mmap.ipp index 835e9f1..cfd5c50 100644 --- a/include/mio/detail/basic_mmap.ipp +++ b/include/mio/detail/basic_mmap.ipp @@ -21,9 +21,9 @@ #ifndef MIO_BASIC_MMAP_IMPL #define MIO_BASIC_MMAP_IMPL -#include "basic_mmap.hpp" -#include "string_util.hpp" -#include "../page.hpp" +#include "mio/detail/basic_mmap.hpp" +#include "mio/detail/string_util.hpp" +#include "mio/page.hpp" #include #include diff --git a/include/mio/shared_mmap.hpp b/include/mio/shared_mmap.hpp index 015f7d5..2d58a30 100644 --- a/include/mio/shared_mmap.hpp +++ b/include/mio/shared_mmap.hpp @@ -21,7 +21,7 @@ #ifndef MIO_SHARED_MMAP_HEADER #define MIO_SHARED_MMAP_HEADER -#include "mmap.hpp" +#include "mio/mmap.hpp" #include // std::error_code #include // std::shared_ptr