Skip to content

Commit

Permalink
Merge pull request #1 from TheNetos/make-cmake-great-again
Browse files Browse the repository at this point in the history
Make CMake configuration great again
  • Loading branch information
vadimvinnik authored Aug 21, 2023
2 parents 552f4b3 + 89f41a5 commit 8a0bce3
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 14 deletions.
80 changes: 78 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.25)

add_subdirectory(demo)
project(async_notification
VERSION 0.1.0
DESCRIPTION ""
HOMEPAGE_URL https://github.com/vadimvinnik/async_notification
LANGUAGES CXX
)

include(GNUInstallDirs)

set(ASYNC_NOTIFICATION_BASE_ALIAS ${PROJECT_NAME} CACHE INTERNAL "Base targets alias" FORCE)
set(ASYNC_NOTIFICATION_CXX_STANDART 17 CACHE INTERNAL "Project c++ standart version" FORCE)

option(async_notification_BUILD_DEMO "Enable build demo target" OFF)

add_library(${PROJECT_NAME} INTERFACE)
add_library(${ASYNC_NOTIFICATION_BASE_ALIAS}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_sources(${PROJECT_NAME}
INTERFACE
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include
FILES
include/async_notification/optional.hpp
include/async_notification/queue.hpp
include/async_notification/simple_variable.hpp
include/async_notification/unique_ptr.hpp
include/async_notification.hpp
)

set_target_properties(${PROJECT_NAME}
PROPERTIES
CXX_STANDARD ${ASYNC_NOTIFICATION_CXX_STANDART}
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF
)

if (async_notification_BUILD_DEMO)
add_subdirectory(demo)
endif()

if(NOT CMAKE_SKIP_INSTALL_RULES)
include(CMakePackageConfigHelpers)

install(TARGETS ${PROJECT_NAME}
EXPORT ${ASYNC_NOTIFICATION_BASE_ALIAS}Targets
FILE_SET HEADERS
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT ${ASYNC_NOTIFICATION_BASE_ALIAS}Targets
FILE ${ASYNC_NOTIFICATION_BASE_ALIAS}Targets.cmake
NAMESPACE ${ASYNC_NOTIFICATION_BASE_ALIAS}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ASYNC_NOTIFICATION_BASE_ALIAS}
)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${ASYNC_NOTIFICATION_BASE_ALIAS}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${ASYNC_NOTIFICATION_BASE_ALIAS}"
NO_SET_AND_CHECK_MACRO
)

write_basic_package_version_file("${ASYNC_NOTIFICATION_BASE_ALIAS}ConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${ASYNC_NOTIFICATION_BASE_ALIAS}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${ASYNC_NOTIFICATION_BASE_ALIAS}ConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${ASYNC_NOTIFICATION_BASE_ALIAS}
)
endif()
4 changes: 4 additions & 0 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
21 changes: 14 additions & 7 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.25)

project(demo)
project(demo
LANGUAGES CXX
)

add_executable(${PROJECT_NAME} main.cpp)
set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(Threads REQUIRED)

target_include_directories(${PROJECT_NAME} PRIVATE ../include)
add_executable(${PROJECT_NAME} main.cpp)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(demo Threads::Threads)

target_link_libraries(${PROJECT_NAME}
PRIVATE
async_notification::async_notification
Threads::Threads
)

10 changes: 5 additions & 5 deletions demo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "manager.h"
#include "buffers/optional.h"
#include "buffers/queue.h"
#include "buffers/simple_variable.h"
#include "buffers/unique_ptr.h"
#include <async_notification.hpp>
#include <async_notification/optional.hpp>
#include <async_notification/queue.hpp>
#include <async_notification/simple_variable.hpp>
#include <async_notification/unique_ptr.hpp>

#include <chrono>
#include <iostream>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8a0bce3

Please sign in to comment.