asio
asio copied to clipboard
Add cmake/ pkg-config integration
Hi! I'm packaging a few packages for Arch Linux that require asio. Unfortunately those seem to have a hard time detecting asio reliably, as there is neither pkg-config nor cmake integration available.
Providing this integration would help all downstream consumers of this project to reliably detect its version and location and prevent writing boilerplate that test-compiles e.g. asio/version.h to retrieve the current version string.
We also have asio package in MSYS2 distro. And we have PR #128 for long time.
I would suggest to simply use this PR https://github.com/chriskohlhoff/asio/pull/1105
@ClausKlein hm, your PR seems to add the kitchen sink of project development. This ticket is about adding pkg-config integration only.
As @chriskohlhoff has neither reacted to this ticket nor to #128 (from 2016!) yet, I have a hard time believing anything will ever be merged in regards to this. It also makes me wonder what the point of this issue tracker is, if it is ignored anyways.
@dvzrv it is easy to extent my project to export pkg-config a package too
-- Installing: /Users/clausklein/Workspace/cpp/asio/asio/stage/share/asio/asioConfig.cmake
-- Installing: /Users/clausklein/Workspace/cpp/asio/asio/stage/share/asio/asioConfigVersion.cmake
-- Installing: /Users/clausklein/Workspace/cpp/asio/asio/stage/share/asio/asioTargets.cmake
-- Installing: /Users/clausklein/Workspace/cpp/asio/asio/stage/lib/pkgconfig/asio.pc
+ rm -rf ./cmake-build-asio-x86_64-Debug/install
+ '[' -f tests/CMakeLists.txt -o -f tests/CMakeLists.txt ']'
+ cmake -S tests -B ./cmake-build-asio-x86_64-Debug/test -G Ninja -D CMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/ccache -D CMAKE_EXPORT_COMPILE_COMMANDS=1 -D CMAKE_BUILD_TYPE=Debug -D CMAKE_PREFIX_PATH=/Users/clausklein/Workspace/cpp/asio/asio/stage -D BUILD_TESTING=1 -D CMAKE_CXX_STANDARD=20 -D TEST_INSTALLED_VERSION=1
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_TESTING
TEST_INSTALLED_VERSION
-- Build files have been written to: /Users/clausklein/Workspace/cpp/asio/asio/cmake-build-asio-x86_64-Debug/test
+ cmake --build ./cmake-build-asio-x86_64-Debug/test
[2/2] Linking CXX executable asio_test
+ cmake --build ./cmake-build-asio-x86_64-Debug/test --target test
[0/1] Running tests...
Test project /Users/clausklein/Workspace/cpp/asio/asio/cmake-build-asio-x86_64-Debug/test
Start 1: asio_test
1/1 Test #1: asio_test ........................ Passed 0.17 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.18 sec
+ '[' -f all/CMakeLists.txt ']'
+ '[' -f standalone/CMakeLists.txt ']'
Claus-iMac:asio clausklein$ cat /Users/clausklein/Workspace/cpp/asio/asio/stage/lib/pkgconfig/asio.pc
prefix=/Users/clausklein/Workspace/cpp/asio/asio/stage
exec_prefix=
includedir=/Users/clausklein/Workspace/cpp/asio/asio/stage/include
Name: asio
Description: A cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.
Version: 1.23.0
Cflags: -I/Users/clausklein/Workspace/cpp/asio/asio/stage/include -DASIO_NO_DEPRECATED
Lflags:
Requires:
Requires.private:
Claus-iMac:asio clausklein$
see https://github.com/chriskohlhoff/asio/pull/1105/commits/618bddb9d69ace2a66f8dab282790c0b415e0347
I personally now use the following in my project to add Asio standalone library to my CMake project:
find_package(Threads REQUIRED)
include(FetchContent)
# Download external dependencies
# Asio
include(FetchContent)
FetchContent_Declare(asio
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
GIT_TAG asio-1-29-0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(asio)
add_library(asio INTERFACE)
target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include)
# Use as standalone library and do not allow deprecated features
target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
# Link threads as dependency
target_link_libraries(asio INTERFACE Threads::Threads)
# Link Asio library to your target (`your_target` is your target name)
target_link_libraries(your_target asio)