Is it possible to configure CLion to compile source files in a project independently?

前端 未结 5 550
走了就别回头了
走了就别回头了 2020-12-23 17:12

I am currently doing some Project Euler challenges in C using the JetBrains CLion IDE. When I completed these in Python and Java (in PyCharm and IntelliJ, respectively), I w

5条回答
  •  礼貌的吻别
    2020-12-23 17:42

    You can add these lines to your CMakeLists.txt .

        #GLOB_RECURSE will find files in all subdirectories that match the globbing expressions and store it into the variable.
        file(GLOB_RECURSE APP_SOURCES *.c)
        foreach (testsourcefile ${APP_SOURCES})
            #get filename without extension
            get_filename_component(testname ${testsourcefile} NAME_WE)
            #add executable for all file
            add_executable(${testname} ${testsourcefile})
        endforeach (testsourcefile ${APP_SOURCES})
    

    You will have to reload cmake project (Tools -> Cmake) every time you add or delete files from your project. Also build time will increase if you add more number of files. Alternative you can create more directories and subdirectories and use file(GLOB_RECURSE APP_SOURCES path/to/*.c) so it will build only those files.

提交回复
热议问题