Mac cmake生成xcode项目工程

    科技2026-02-07  2

    https://www.jianshu.com/p/4fccc8fc2321

    https://blog.csdn.net/Song_Esther/article/details/105419945

     

    最近在研究clang插件的实现,编辑cpp文件的时候不像之前使用IDE那么方便,动态库的链接路径也不方便,于是想如果生成xocde的工程呢?在xcode下编写c系列的代码总应该可以吧!

    于是再次研究了下cmake命令,cmake是一个跨平台的安装/编译工具,可以用简单的语句来描述所有平台的安装(编译过程)。

    使用cmake生成xcode工程

    1.准备main.cpp文件

    #include

    int main()

    {

            std::cout<<"Hello word!"<<std::endl;

            return0;

    }

     

    2.编辑CMakeLists.txt

    PROJECT(main)

    CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

    AUX_SOURCE_DIRECTORY(. DIR_SRCS)

    ADD_EXECUTABLE(main ${DIR_SRCS})

     

    3.执行命令:

    cmake -G "Xcode" .

     

    Clang 插件开发工程

    1.编辑CMakeLists.txt

    set(LLVM_LINK_COMPONENTS

    Support

    )

    add_clang_executable(main

    main.cpp

    )

    target_link_libraries(main

    clangAST

    clangBasic

    clangFrontend

    clangTooling

    clangIndex

    )

    2.准备main.cpp文件

     

    3.执行命令

    cmake -G "Xcode" ~/Tool/LLVM/llvm/

    4.打开xxxxx.xcodeproj文件

    ok!

    使用cmake生成xcode的项目

    cmake .. -G "Xcode"

    结果报如下错误

    -- The C compiler identification is unknown

    -- The CXX compiler identification is unknown

    CMake Error at CMakeLists.txt:2 (project):

     No CMAKE_C_COMPILER could be found.

    CMake Error at CMakeLists.txt:2 (project):

     No CMAKE_CXX_COMPILER could be found.

    后来使用如下命令解决

    sudo xcode-select --switch /Applications/Xcode.app/

    重试时记得清空build下的文件

    Processed: 0.009, SQL: 9