|
1 |
| -# Copyright 2019-2020 by Cliff Green |
| 1 | +# Copyright (c) 2019-2024 by Cliff Green |
2 | 2 | #
|
3 | 3 | # https://github.com/connectivecpp/chops-net-ip
|
4 | 4 | #
|
| 5 | +# I'm still learning CMake, so improvement suggestions are always welcome. |
| 6 | +# |
| 7 | +# The Asio CMake code is taken from CPM.cmake examples/asio-standalone. |
| 8 | +# |
5 | 9 | # Distributed under the Boost Software License, Version 1.0.
|
6 | 10 | # (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
7 | 11 |
|
8 |
| -# CMake 3.8 required for cxx_std_17 target_compile_features |
9 |
| - |
10 |
| -cmake_minimum_required ( VERSION 3.12 ) |
11 |
| - |
12 |
| -option ( CHOPS_NET_IP_OPT_BUILD_TESTS "Build and perform chops-net-ip tests" ON ) |
13 |
| -option ( CHOPS_NET_IP_OPT_BUILD_EXAMPLES "Build and perform chops-net-ip examples" ON ) |
14 |
| -option ( CHOPS_NET_IP_OPT_BUILD_DOCS "Build doxygen documentation" OFF ) |
| 12 | +cmake_minimum_required ( VERSION 3.14 FATAL_ERROR ) |
15 | 13 |
|
16 |
| -set ( OPTIONS "" ) |
17 |
| -set ( DEFINITIONS "" ) |
| 14 | +project ( chops_net_ip |
| 15 | + LANGUAGES CXX |
| 16 | + DESCRIPTION "An asynchronous networking library based on Asio" |
| 17 | + HOMEPAGE_URL "https://github.com/connectivecpp/chops-net-ip/" ) |
18 | 18 |
|
19 |
| -project ( chops-net-ip VERSION 1.0 LANGUAGES CXX ) |
| 19 | +option ( CHOPS_NET_IP_BUILD_TESTS "Build unit tests" OFF ) |
| 20 | +option ( CHOPS_NET_IP_BUILD_EXAMPLES "Build examples" OFF ) |
| 21 | +option ( CHOPS_NET_IP_INSTALL "Install header only library" OFF ) |
20 | 22 |
|
21 |
| -set ( package_name "chops-net-ip" ) |
| 23 | +# add library targets |
22 | 24 |
|
23 |
| -set ( include_source_dir "${CMAKE_SOURCE_DIR}/include" ) |
24 |
| -set ( utility_rack_dir "${CMAKE_SOURCE_DIR}/../utility-rack" ) |
25 |
| -set ( utility_rack_include_source_dir "${utility_rack_dir}/include" ) |
26 |
| -set ( third_party_include_source_dir "${utility_rack_dir}/third_party" ) |
27 |
| -set ( cmake_include_dir "${CMAKE_SOURCE_DIR}/cmake" ) |
28 |
| -set ( cmake_all_repos_include_dir "${utility_rack_dir}/cmake/all_repos" ) |
| 25 | +add_library ( chops_net_ip INTERFACE ) |
| 26 | +add_library ( chops::chops_net_ip ALIAS chops_net_ip ) |
29 | 27 |
|
| 28 | +# thread support specified in Asio download |
30 | 29 |
|
31 |
| -# Interface library: |
| 30 | +include ( cmake/download_asio_cpm.cmake ) |
32 | 31 |
|
33 |
| -add_library ( ${package_name} INTERFACE ) |
| 32 | +# configure library target |
34 | 33 |
|
35 |
| -target_include_directories ( ${package_name} INTERFACE ${include_source_dir} ) |
36 |
| -target_include_directories ( ${package_name} INTERFACE ${third_party_include_source_dir} ) |
37 |
| -target_compile_features ( ${package_name} INTERFACE cxx_std_17) |
| 34 | +target_include_directories ( chops_net_ip INTERFACE |
| 35 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> |
| 36 | + $<INSTALL_INTERFACE:include/> ) |
| 37 | +target_compile_features ( chops_net_ip INTERFACE cxx_std_20 ) |
38 | 38 |
|
39 |
| -if ( CHOPS_NET_IP_OPT_BUILD_TESTS ) |
| 39 | +# check to build unit tests |
| 40 | +if ( ${CHOPS_NET_IP_BUILD_TESTS} ) |
40 | 41 | enable_testing()
|
41 | 42 | add_subdirectory ( test )
|
42 |
| -endif() |
| 43 | +endif () |
43 | 44 |
|
44 |
| -if ( CHOPS_NET_IP_OPT_BUILD_EXAMPLES ) |
| 45 | +# check to build example code |
| 46 | +if ( ${CHOPS_NET_IP_BUILD_EXAMPLES} ) |
45 | 47 | add_subdirectory ( example )
|
46 |
| -endif() |
| 48 | +endif () |
47 | 49 |
|
48 |
| -if ( CHOPS_NET_IP_OPT_BUILD_DOCS ) |
49 |
| - add_subdirectory ( doc ) |
50 |
| -endif() |
| 50 | +# check to install |
| 51 | +if ( ${CHOPS_NET_IP_INSTALL} ) |
| 52 | + set ( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt ) |
| 53 | + include ( CPack ) |
| 54 | +endif () |
51 | 55 |
|
52 | 56 | # end of file
|
53 | 57 |
|
0 commit comments