首页 > 技术文章 > 使用CLion编辑C工程

nidey 2017-01-07 00:40 原文

最近正在研究Linux C代码编辑器,确实也不太喜欢SI(Windows看代码还行,编辑一般,同步麻烦),

尝试使用CLion,但对makefile工程支持不好,怎么编译还没搞懂,

阅读、编辑还不错,智能提示、语法检查、函数跳转、查引用都挺好用的。


不过要想使用CLion的这些功能需要添加工程中的h文件到CMakeList.txt,
可参考如下脚本(把print结果添到CMakeList.txt里就行)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import fnmatch
import os
import sys


def find_file(path, file_exp):
    for r, d, f in os.walk(path):
        for n in fnmatch.filter(f, file_exp):
            yield os.path.join(r, n)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print('Usage: python get_h_cmakelist.py path_to_your_project')
        exit(-1)
    project_path = sys.argv[1]
    h_dir = []
    for file in find_file(project_path, '*.h'):
        file_dir = os.path.dirname(file)
        if file_dir not in h_dir:
            h_dir.append(file_dir)
    print('include_directories({0})'.format('\r\n\t'.join(h_dir)))

 

结果类似

include_directories(E:\ids\suricata-3.1.2\libhtp\htp
    E:\ids\suricata-3.1.2\libhtp\test
    E:\ids\suricata-3.1.2\libhtp\test\gtest
    E:\ids\suricata-3.1.2\src)

 

推荐阅读