How to Create, Compile, And Run a single file in CLion

前端 未结 6 507
情话喂你
情话喂你 2021-01-31 03:07

I am working on some c++ stuff and I hate having to create a whole new project just to run a few things on a file.

I also don\'t like how when you creat

6条回答
  •  独厮守ぢ
    2021-01-31 03:41

    CLion is based on CMake. So if you want to not use CMake, you can use other editors like Sublime Text.

    But a simple CMake script could solve the problem.

    The following CMake script automatically adds cpp files in the current directory and its subdirectories to executables (filename as the target name).

    cmake_minimum_required(VERSION 3.15)
    project(MyApp)
    
    set(CMAKE_CXX_STANDARD 17)
    
    file(GLOB APP_SOURCES *.cpp */*.cpp)
    foreach (testsourcefile ${APP_SOURCES})
        get_filename_component(testname ${testsourcefile} NAME_WE)
        message("${testname}")
        add_executable(${testname} ${testsourcefile})
    endforeach (testsourcefile ${APP_SOURCES})
    

提交回复
热议问题