1include(ExternalProject) 2 3if(${CMAKE_VERSION} VERSION_LESS "3.8.0") 4 set(_UPDATE_DISCONNECTED 0) 5else() 6 set(_UPDATE_DISCONNECTED 1) 7endif() 8 9set(IWNET_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}") 10file(MAKE_DIRECTORY ${IWNET_INCLUDE_DIR}) 11 12if("${IWNET_URL}" STREQUAL "") 13 if(EXISTS ${CMAKE_SOURCE_DIR}/iwnet.zip) 14 set(IWNET_URL ${CMAKE_SOURCE_DIR}/iwnet.zip) 15 elseif(EXISTS ${CMAKE_SOURCE_DIR}/extra/iwnet/CMakeLists.txt) 16 set(IWNET_URL ${CMAKE_SOURCE_DIR}/extra/iwnet) 17 else() 18 set(IWNET_URL 19 https://github.com/Softmotions/iwnet/archive/refs/heads/master.zip) 20 endif() 21endif() 22 23message("IWNET_URL: ${IWNET_URL}") 24 25if(APPLE) 26 set(BYPRODUCT "${CMAKE_BINARY_DIR}/lib/libiwnet-1.a") 27else() 28 set(BYPRODUCT "${CMAKE_BINARY_DIR}/src/extern_iwnet-build/src/libiwnet-1.a") 29endif() 30 31# In order to properly pass owner project CMAKE variables than contains 32# semicolons, we used a specific separator for 'ExternalProject_Add', using the 33# LIST_SEPARATOR parameter. This allows building fat binaries on macOS, etc. 34# (ie: -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64") Otherwise, semicolons get 35# replaced with spaces and CMake isn't aware of a multi-arch setup. 36set(SSUB "^^") 37 38set(CMAKE_ARGS 39 -DOWNER_PROJECT_NAME=${PROJECT_NAME} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 40 -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DASAN=${ASAN} 41 -DBUILD_SHARED_LIBS=OFF -DBUILD_EXAMPLES=OFF) 42 43set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_INSTALL_PREFIX}) 44 45foreach( 46 extra 47 CMAKE_FIND_ROOT_PATH 48 CMAKE_OSX_ARCHITECTURES 49 CMAKE_C_COMPILER 50 CMAKE_TOOLCHAIN_FILE 51 ANDROID_PLATFORM 52 ANDROID_ABI 53 TEST_TOOL_CMD 54 PLATFORM 55 ENABLE_BITCODE 56 ENABLE_ARC 57 ENABLE_VISIBILITY 58 ENABLE_STRICT_TRY_COMPILE 59 ARCHS) 60 if(DEFINED ${extra}) 61 # Replace occurences of ";" with our custom separator and append to 62 # CMAKE_ARGS 63 string(REPLACE ";" "${SSUB}" extra_sub "${${extra}}") 64 list(APPEND CMAKE_ARGS "-D${extra}=${extra_sub}") 65 endif() 66endforeach() 67 68message("IWNET CMAKE_ARGS: ${CMAKE_ARGS}") 69 70ExternalProject_Add( 71 extern_iwnet 72 URL ${IWNET_URL} 73 DOWNLOAD_NAME iwnet.zip 74 TIMEOUT 360 75 PREFIX ${CMAKE_BINARY_DIR} 76 BUILD_IN_SOURCE OFF 77 UPDATE_COMMAND "" 78 UPDATE_DISCONNECTED ${_UPDATE_DISCONNECTED} 79 LIST_SEPARATOR "${SSUB}" 80 CMAKE_ARGS ${CMAKE_ARGS} 81 BUILD_BYPRODUCTS ${BYPRODUCT}) 82 83if(DO_INSTALL_CORE) 84 install(FILES "${BYPRODUCT}" DESTINATION ${CMAKE_INSTALL_LIBDIR}) 85endif() 86 87add_library(IWNET::static STATIC IMPORTED GLOBAL) 88set_target_properties( 89 IWNET::static 90 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" 91 IMPORTED_LOCATION ${BYPRODUCT} 92 IMPORTED_LINK_INTERFACE_LIBRARIES "IOWOW::static") 93 94add_dependencies(IWNET::static IOWOW::static extern_iwnet) 95 96list(PREPEND PROJECT_LLIBRARIES IWNET::static) 97list(APPEND PROJECT_INCLUDE_DIRS ${IWNET_INCLUDE_DIR}) 98