Skip to content

Instantly share code, notes, and snippets.

@mguludag
Last active June 3, 2022 22:24
Show Gist options
  • Select an option

  • Save mguludag/f10d18582c56c449382bc8b05513fe35 to your computer and use it in GitHub Desktop.

Select an option

Save mguludag/f10d18582c56c449382bc8b05513fe35 to your computer and use it in GitHub Desktop.
Download https://github.com/chriskohlhoff/asio library with CMake
if(NOT CMAKE_VERSION VERSION_LESS 3.10)
include_guard()
endif()
if(NOT COMMAND FetchContent_Populate)
if(CMAKE_VERSION VERSION_LESS 3.11)
message(STATUS "Fetching FetchContent.cmake")
file(DOWNLOAD
"https://gitlab.kitware.com/cmake/cmake/raw/v3.11.3/Modules/FetchContent.cmake"
"${CMAKE_BINARY_DIR}/Modules/FetchContent.cmake"
)
file(DOWNLOAD
"https://gitlab.kitware.com/cmake/cmake/raw/v3.11.3/Modules/FetchContent/CMakeLists.cmake.in"
"${CMAKE_BINARY_DIR}/Modules/FetchContent/CMakeLists.cmake.in"
)
include(${CMAKE_BINARY_DIR}/Modules/FetchContent.cmake)
else()
include(FetchContent)
endif()
endif()
function(fetch_asio)
cmake_parse_arguments(_ OPTIONAL "TAG" "" ${ARGN})
if(__UNPARSED_ARGUMENTS)
list(GET __UNPARSED_ARGUMENTS 0 __TAG)
list(REMOVE_AT __UNPARSED_ARGUMENTS 0)
endif()
if(__UNPARSED_ARGUMENTS)
message(AUTHOR_WARNING "asio_fetch: extra arguments ignored: ${__UNPARSED_ARGUMENTS}")
endif()
if(NOT __TAG)
set(__TAG master)
endif()
if(CMAKE_VERSION VERSION_LESS 3.6)
FetchContent_Declare(asio QUIET GIT_REPOSITORY "https://github.com/chriskohlhoff/asio" GIT_TAG ${__TAG})
else()
FetchContent_Declare(asio QUIET GIT_REPOSITORY "https://github.com/chriskohlhoff/asio" GIT_TAG ${__TAG} GIT_SHALLOW 1)
endif()
add_compile_definitions(BOOST_DATETIME_NO_LIB BOOST_REGEX_NO_LIB BOOST_SYSTEM_NO_LIB)
FetchContent_GetProperties(asio)
if(NOT asio_POPULATED)
FetchContent_Populate(asio)
include_directories("${asio_SOURCE_DIR}/asio/include")
endif()
endfunction(fetch_asio)
@mguludag
Copy link
Author

mguludag commented Jun 3, 2022

Example:

include("cmake/FetchAsio.cmake")
fetch_asio() # or fetch_asio(TAG asio-1-20-0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment