-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make user provide standalone Asio library to use
Instead of fetching a specific version of Asio to use when building without boost, expect the user to provide a version to use similar to how boost is used. This is more flexible and probably what most users would expect.
- Loading branch information
Showing
3 changed files
with
66 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
include(FindPackageHandleStandardArgs) | ||
|
||
find_package(Threads QUIET) | ||
|
||
if (NOT Threads_FOUND) | ||
message(FATAL_ERROR "Asio requires Threads") | ||
endif() | ||
|
||
if(DEFINED ENV{ASIO_ROOT}) | ||
set(ASIO_DIR "$ENV{ASIO_ROOT}/asio/include/") | ||
else() | ||
set(ASIO_DIR "${CMAKE_CURRENT_BINARY_DIR}/asio/asio/include/") | ||
endif() | ||
|
||
find_path(ASIO_INCLUDE_DIR asio.hpp | ||
HINTS | ||
${ASIO_DIR} | ||
) | ||
|
||
if(ASIO_INCLUDE_DIR AND EXISTS "${ASIO_INCLUDE_DIR}/asio/version.hpp") | ||
file(STRINGS "${ASIO_INCLUDE_DIR}/asio/version.hpp" asio_version_str REGEX "^#define[ \t]+ASIO_VERSION[ \t]+.*") | ||
string(REGEX REPLACE "^#define[ \t]+ASIO_VERSION[ \t]+([0-9]+).*$" "\\1" asio_version_number "${asio_version_str}") | ||
math(EXPR asio_sub_minor_version "${asio_version_number} % 100") | ||
math(EXPR asio_minor_version "${asio_version_number} / 100 % 1000") | ||
math(EXPR asio_major_version "${asio_version_number} / 100000") | ||
set(ASIO_VERSION_STRING "${asio_major_version}.${asio_minor_version}.${asio_sub_minor_version}") | ||
endif() | ||
|
||
find_package_handle_standard_args( | ||
Asio | ||
REQUIRED_VARS ASIO_INCLUDE_DIR | ||
VERSION_VAR ASIO_VERSION_STRING | ||
) | ||
|
||
mark_as_advanced(ASIO_INCLUDE_DIR) | ||
|
||
if(ASIO_FOUND AND NOT TARGET Asio::Asio) | ||
add_library(Asio::Asio INTERFACE IMPORTED) | ||
target_include_directories(Asio::Asio | ||
INTERFACE | ||
${ASIO_INCLUDE_DIR} | ||
Threads::Threads | ||
) | ||
endif() |