使用cmake生成ios 的xcode工程,支持Objective-C,c++混合编程

 如果想在macOS上用CMake编译ios 的Objective-C,可以这样:

cmake_minimum_required(VERSION 3.21)

project(testSDK  LANGUAGES CXX)

set(NAME testSDK)

set(
    SOURCES
    main.m
    CallBackHandler.mm
)

add_executable(
    ${NAME}
    ${SOURCES}	
)
set_target_properties(${NAME} PROPERTIES
        #FRAMEWORK TRUE
        #FRAMEWORK_VERSION C
        #MACOSX_FRAMEWORK_IDENTIFIER com.cmake.${NAME}
        MACOSX_BUNDLE TRUE
        MACOSX_BUNDLE_INFO_PLIST Info.plist
        # "current version" in semantic format in Mach-O binary file
        VERSION 1.0.0
        # "compatibility version" in semantic format in Mach-O binary file
        SOVERSION 1.0.0
        #PUBLIC_HEADER WebSocketClientFactory.h
        XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
        DEVELOPMENT_TEAM  "xxxx"
        CODE_SIGN_IDENTITY "yyy"
      )
target_link_libraries( # Specifies the target library.
        ${NAME}
        "-framework UIKit -framework Foundation  -framework AVFoundation -framework AudioToolbox  -framework CoreMedia -framework CoreGraphics"
        #"-framework AudioUnit"
                       )

target_compile_options(
    ${NAME}
    PUBLIC
    -fobjc-arc
)

主意 :FRAMEWORK TRUE可以生成动态库

执行以下命令可以生成xcode可以编译的工程文件,ios.toolchain.cmake从这里下载:

https://github.com/ygmtx/ios-cmakehttps://github.com/ygmtx/ios-cmake

cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64 -DENABLE_BITCODE=FALSE

然后使用xcode打开工程编译

你可能感兴趣的:(xcode,objective-c,ios,cmake)