I'm trying to create a CMakeLists.txt file that will build a cross-platform library, I had no issues making it work on Linux and Windows, but making it work on iOS (real device and simulator) and Android is turning out to be a pain.
The main issue relies on my need to include a prebuilt external library that comes in the following directory structure:
├── lib
│   └── EXAMPLE
│       ├── include
│       │   └── EXAMPLE
│       │       ├── EXAMPLE_API.h
│       │       ├── EXAMPLE_Error.h
│       │       └── EXAMPLE_Type.h
│       └── lib
│           ├── Android_Static_All
│           │   ├── arm64-v8a
│           │   │   └── libEXAMPLE_API.a
│           │   ├── armeabi
│           │   │   └── libEXAMPLE_API.a
│           │   ├── armeabi-v7a
│           │   │   └── libEXAMPLE_API.a
│           │   ├── mips
│           │   │   └── libEXAMPLE_API.a
│           │   ├── mips64
│           │   │   └── libEXAMPLE_API.a
│           │   ├── x86
│           │   │   └── libEXAMPLE_API.a
│           │   └── x86_64
│           │       └── libEXAMPLE_API.a
│           ├── Linux
│           │   ├── x64
│           │   │   ├── libEXAMPLE_API.a
│           │   │   └── libEXAMPLE_API.so
│           │   └── x86
│           │       ├── libEXAMPLE_API.a
│           │       └── libEXAMPLE_API.so
│           ├── Windows
│           │   ├── x64
│           │   │   ├── EXAMPLE_API.dll
│           │   │   └── EXAMPLE_API.lib
│           │   └── x86
│           │       ├── EXAMPLE_API.dll
│           │       └── EXAMPLE_API.lib
│           ├── iOS64
│           │   ├── Release-iphoneos
│           │   │   └── libEXAMPLE_API.a
│           │   └── Release-iphonesimulator
│           │       └── libEXAMPLE_API.a
│           └── osX
│               ├── x64
│               │   ├── libEXAMPLE_API.a
│               │   └── libEXAMPLE_API.dylib
│               └── x86
│                   ├── libEXAMPLE_API.a
│                   └── libEXAMPLE_API.dylib
I've managed to build an Xcode project with the help of this great project (https://github.com/leetal/ios-cmake) by adjusting the following section of the CMake file:
# Comment one of the following line depending on what you are building
set(PPCS_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/EXAMPLE/lib/iOS64/Release-iphonesimulator")
# set(PPCS_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/EXAMPLE/lib/iOS64/Release-iphoneos")
# set(PPCS_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/EXAMPLE/lib/Android_Static_All/arm64-v8a")
# set(PPCS_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/EXAMPLE/lib/Android_Static_All/armeabi")
# etc...
find_library(EXAMPLE_API_LIBRARY 
    NAMES 
        EXAMPLE_API
        libEXAMPLE_API 
    HINTS 
        "${EXAMPLE_LIB_PATH}"
    NO_DEFAULT_PATH
)
target_link_libraries(${PROJECT_NAME} ${EXAMPLE_API_LIBRARY})
And then configuring the build folder with the command:
$ cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=0000000000
However this is not really feasible for a couple of reasons:
- Manually updating the CMake file isn't an option but there are ways to hardcode the correct path based on the build target.
 - When including a static library for a specific platform (e.g. iOS), multiple versions need to be included in the build project (e.g. both x86_64 and arm64) but this method only includes the fist one it finds, ignoring the other architectures for the said target.
 
Is there a way to automate the linking of the correct libraries (especially with iOS and iOSSimulator) and create an according Xcode and Android project?