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

前端 未结 5 571
走了就别回头了
走了就别回头了 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:39

    You can use

    cmake_minimum_required(VERSION 2.8.4)
    
    add_subdirectory(src/prj1)
    add_subdirectory(src/prj2)
    

    then in each directory create an other CMakeLists.txt like this one :

    cmake_minimum_required(VERSION 2.8.4)
    project(prj1)
    
    set(EXEC_NAME prj1)
    
    set(SOURCE_FILES
        main_prj1.cpp
        x.cpp
        y.cpp
    )
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    
    set(EXECUTABLE_OUTPUT_PATH ../../dist/${CMAKE_BUILD_TYPE})
    
    add_executable(${EXEC_NAME} ${SOURCE_FILES})
    

    You can use file(GLOB SOURCE_FILES *.cpp) if you want to automatically add files in your compilation. But keep in mind that this "trick" is strongly not encouraged.

    This will also automatically add build configurations to CLion.

提交回复
热议问题