diff --git a/.github/workflows/build-ios-mac.yml b/.github/workflows/build-ios-mac.yml new file mode 100644 index 000000000..114696247 --- /dev/null +++ b/.github/workflows/build-ios-mac.yml @@ -0,0 +1,54 @@ +name: C/C++ CI for iOS + +on: + push: + branches: + - master + - main + - dev + - dev/* + - release/* + - buildme/* + + pull_request: + branches: + - master + - main + - dev + + schedule: + - cron: 0 2 * * 1-5 + +jobs: + build: + strategy: + matrix: + os: [macos-13, macos-15] + config: [release, debug] + simulator: ["'iPhone 15'", "'iPad Pro (11-inch) (4th generation)'", "'iPhone 16'", "'iPad Air 11-inch (M2)'"] + exclude: + - os: macos-13 + simulator: "'iPhone 16'" + - os: macos-13 + simulator: "'iPad Air 11-inch (M2)'" + - os: macos-15 + simulator: "'iPhone 15'" + - os: macos-15 + simulator: "'iPad Pro (11-inch) (4th generation)'" + runs-on: ${{ matrix.os }} + steps: + - name: Grant write permissions to /usr/local + run: | + sudo chown -R $USER:staff /usr/local + - uses: actions/checkout@v2 + with: + submodules: 'true' + continue-on-error: true + - name: build + run: | + if [[ "${{ matrix.os }}" == "macos-13" ]]; then + export IOS_DEPLOYMENT_TARGET=13.0; + elif [[ "${{ matrix.os }}" == "macos-15" ]]; then + export IOS_DEPLOYMENT_TARGET=15.0; + fi + ./build-tests-ios.sh ${{ matrix.config }} ${{ matrix.simulator }} diff --git a/.github/workflows/build-ios-mac11.yml b/.github/workflows/build-ios-mac11.yml deleted file mode 100644 index 9c60f195a..000000000 --- a/.github/workflows/build-ios-mac11.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: C/C++ CI for iOS - -on: - push: - branches: - - master - - main - - dev - - dev/* - - release/* - - buildme/* - - pull_request: - branches: - - master - - main - - dev - - schedule: - - cron: 0 2 * * 1-5 - -jobs: - build: - runs-on: macOS-11 - strategy: - matrix: - config: [release, debug] - simulator: ["'iPhone 8'", "'iPad Air (3rd generation)'"] - steps: - - uses: actions/checkout@v2 - with: - submodules: 'true' - continue-on-error: true - - name: build - run: export IOS_DEPLOYMENT_TARGET=11.0 && ./build-tests-ios.sh ${{ matrix.config }} ${{ matrix.simulator }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 815834bc9..9bf34850d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,51 @@ cmake_minimum_required(VERSION 3.1.0) project(MSTelemetry) +# Set installation prefix for macOS and Linux +if(UNIX AND NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation directory prefix" FORCE) +endif() + + +# Set installation prefix for Unix systems (macOS and Linux) +if(UNIX AND NOT DEFINED CMAKE_INSTALL_PREFIX) + # First try /usr/local + set(TEST_FILE "/usr/local/.ci_write_test") + + # Try to create a test file + execute_process( + COMMAND ${CMAKE_COMMAND} -E touch "${TEST_FILE}" + RESULT_VARIABLE WRITE_RESULT + ) + + # Check if write was successful + if(WRITE_RESULT EQUAL 0) + # We have write access to /usr/local + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation directory prefix" FORCE) + message(STATUS "Using /usr/local as installation prefix (write access confirmed)") + # Clean up test file + execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${TEST_FILE}") + else() + # No write access, fall back to HOME directory + set(FALLBACK_DIR "$ENV{HOME}/mst_telemetry") + + # Create the mst_telemetry directory + execute_process( + COMMAND ${CMAKE_COMMAND} -E make_directory "${FALLBACK_DIR}" + RESULT_VARIABLE CREATE_DIR_RESULT + ) + + if(NOT CREATE_DIR_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to create directory: ${FALLBACK_DIR}") + endif() + + set(CMAKE_INSTALL_PREFIX "${FALLBACK_DIR}" CACHE PATH "Installation directory prefix" FORCE) + message(STATUS "No write access to /usr/local, created and using ${FALLBACK_DIR} instead") + endif() +endif() + + + set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") diff --git a/build-gtest.sh b/build-gtest.sh index c92c0f2dc..4c73f3382 100755 --- a/build-gtest.sh +++ b/build-gtest.sh @@ -27,19 +27,25 @@ fi echo "Add ios and arm64 build steps for googletest" cat > $GTEST_PATH/CMakeLists_temp.txt << EOF # If building for iOS, set all the iOS options -if(BUILD_IOS) +if(BUILD_IOS) + message("-- Building for iOS simulator..") + message("-- CMAKE_OSX_DEPLOYMENT_TARGET \${CMAKE_OSX_DEPLOYMENT_TARGET}") + message("-- CMAKE_SYSTEM_NAME \${CMAKE_SYSTEM_NAME}") + message("-- CMAKE_OSX_ARCHITECTURES \${CMAKE_OSX_ARCHITECTURES}") set(TARGET_ARCH "APPLE") set(IOS True) set(APPLE True) - set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) + set(CMAKE_SYSTEM_NAME iOS) + set(CMAKE_OSX_DEPLOYMENT_TARGET "12.2" CACHE STRING "Force set of the deployment target for iOS" FORCE) set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -miphoneos-version-min=10.0") set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -miphoneos-version-min=10.0 -std=c++11") set(IOS_PLATFORM "iphonesimulator") set(CMAKE_SYSTEM_PROCESSOR x86_64) execute_process(COMMAND xcodebuild -version -sdk \${IOS_PLATFORM} Path - OUTPUT_VARIABLE CMAKE_OSX_SYSROOT + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_OUT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CMAKE_OSX_SYSROOT \${CMAKE_OSX_SYSROOT_OUT} CACHE STRING "Force set of the sysroot for iOS" FORCE) message("-- CMAKE_OSX_SYSROOT \${CMAKE_OSX_SYSROOT}") elseif(\${ARCH} STREQUAL "arm64") set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -arch arm64") @@ -67,6 +73,7 @@ cmake -Dgtest_build_samples=OFF \ -DARCH=$ARCH \ .. make + popd # CTEST_OUTPUT_ON_FAILURE=1 make test # make install diff --git a/build-tests-ios.sh b/build-tests-ios.sh index fb48b4ea7..bf29a50b3 100755 --- a/build-tests-ios.sh +++ b/build-tests-ios.sh @@ -4,9 +4,16 @@ SKU=${1:-release} SIMULATOR=${2:-iPhone 8} set -e + ./build-ios.sh ${SKU} +# dyld_info /Users/runner/work/cpp_client_telemetry/cpp_client_telemetry/out/lib/libmat.a + cd tests/unittests + +xcrun simctl list devices available +echo 'End of xcrun simctl list devices available' + xcodebuild test -scheme iOSUnitTests -destination "platform=iOS Simulator,name=$SIMULATOR" cd ../functests diff --git a/tests/functests/CMakeLists.txt b/tests/functests/CMakeLists.txt index 0a3b280a5..2551230c1 100644 --- a/tests/functests/CMakeLists.txt +++ b/tests/functests/CMakeLists.txt @@ -108,6 +108,8 @@ else() message("Current Dir: ${CMAKE_CURRENT_SOURCE_DIR}") message("Binary Dir: ${CMAKE_BINARY_DIR}") + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + find_file(LIBGTEST NAMES libgtest.a PATHS diff --git a/tests/functests/functests-ios.xcodeproj/project.pbxproj b/tests/functests/functests-ios.xcodeproj/project.pbxproj index f1ebd5249..e6d00eb35 100644 --- a/tests/functests/functests-ios.xcodeproj/project.pbxproj +++ b/tests/functests/functests-ios.xcodeproj/project.pbxproj @@ -317,6 +317,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, + ../.., ../../lib/, ../../lib/include/, ../../lib/include/mat/, @@ -326,7 +327,7 @@ ../../third_party/googletest/googlemock/include/, ../common/, ); - IPHONEOS_DEPLOYMENT_TARGET = 11.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.2; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; @@ -380,6 +381,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( ../, + ../.., ../../lib/, ../../lib/include/, ../../lib/include/mat/, @@ -389,7 +391,7 @@ ../../third_party/googletest/googlemock/include/, ../common/, ); - IPHONEOS_DEPLOYMENT_TARGET = 11.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.2; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index 8edfca017..df6e6a0e6 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -147,6 +147,8 @@ else() include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/ ) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + find_file(LIBGTEST NAMES libgtest.a PATHS @@ -159,6 +161,9 @@ else() ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/build/lib/ ) + message("GTEST: ${LIBGTEST}") + message("GMOCK: ${LIBGMOCK}") + target_link_libraries(UnitTests ${LIBGTEST} ${LIBGMOCK}