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