很多时候一些大型的C++工程项目虽然使用了CMake,但是对应的没有使用make而是Ninja,因为Ninja比较快。
而使用了Ninja的项目,CLion是不支持打开的,会报错:
/usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /home/zhang/ClickHouse-stable-full/ClickHouse
CMake Error: Error: generator : Unix Makefiles
Does not match the generator used previously: Ninja
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
你可以去投票让jetbrain尽快实现这个功能:Support Ninja CMake generator : CPP-2659
我在网上查到有人写了一个脚本帮忙实现CLion对Ninja的支持,地址在这里:Ninja support for CLion IDE
确保系统安装了Python3:
apt install python3
具体的方法是先下载脚本cmake_ninja_wrapper.py
wget https://gist.githubusercontent.com/arichardson/3de8adaebec0d488c13911edd2e0fe63/raw/ba71097edecfea31d8f0c51804f45d66ccf5c751/cmake_ninja_wrapper.py
chmod +x cmake_ninja_wrapper.py
编辑cmake_ninja_wrapper.py
文件开头的REAL_CMAKE变量名为cmake的位置。
然后找到 Settings → Build, Execution, Deployment → Toolchains
在 "CMake executable"这栏选择 cmake_ninja_wrapper.py 脚本.
注意:如果你是打开别人的工程文件,把下面这几行注释了
exit_code = call_cmake(sys.argv[1:])
if exit_code != 0:
sys.exit(exit_code)
然后重新加载项目就可以正确识别出了。