cpp-clion-template
cpp-clion-template copied to clipboard
My default template for CLion C++ projects.
cpp_clion_template
Falven
Template project for Clion C++ projects.
This project uses CMake for cross-platform compliance.
Building - Out of Source (Recommended)
I recommend you build this project out-of-source so source files don't get mixed with build files and cause problems. What this means is placing the build files outside of the project's source root directory.
- Create a directory outside of this project where binaries will be built.
- If building with a CMake GUI application:
- Right click anywhere outside the project and make a new folder
cpp_clion_template_build/
.
- Right click anywhere outside the project and make a new folder
- If building through the cmake CLI (command line interface):
-
mkdir cpp_clion_template_build/
-
- If building with a CMake GUI application:
- Set appropriate directories; depending on your CMake utility:
- If building with a CMake GUI application:
- Set the 'source' directory to the top-level directory of this project.
- Set the 'build' directory to the directory you created in step 1.
- If building through a CMake CLI (command line interface):
- cd to the directory we created in step 1.
cpp_clion_template_build/
(important!)
- cd to the directory we created in step 1.
- If building with a CMake GUI application:
- Set appropriate cmake variables
- If building with a CMake GUI application:
- Set appropriate variable values in 'cache values'.
- If building through a CMake CLI (command line interface):
- You can pass options to CMake CLI using the
-D <var>:<type>=<value>
command. -
cmake [options] <path-to-source>
- You can pass options to CMake CLI using the
- If building with a CMake GUI application:
- Create build tools for the project.
- If building with a CMake GUI application:
- Select configure and select an appropriate generator, where the generator is the type of build project you would like to create, and completely dependent on your platform.
- If building through the cmake CLI (command line interface):
-
cmake -G <generator-name>
where generator is the type of project you would like to create, and completely dependent on your platform. Make sure you are in thecpp_clion_template_build/
directory when you do this.- To see available options simply type
cmake -G
- To see available options simply type
-
- If building with a CMake GUI application:
- Build the project using the generated build tools
- For example, if you generated a
Makefile
typemake
.
- For example, if you generated a
Example
Generating a Unix Makefile:
-
mkdir cpp_clion_template_build/ && cd cpp_clion_template_build/
-
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ../cpp_clion_template/
-
make
Running the tests.
This project uses CTest, CMake's built-in testing framework.
To run the tests:
- Make sure you have built the project.
- Run the tests:
- If built with a CMake GUI application:
- Simply run the project associated with the test (in Visual Studio, XCode...)
- If built with the CMake CLI:
2. Open a CLI and switch to the binary directory of your build.
cd cd cpp_clion_template_build/
3. runctest
and cmake will run all of the tests associated with the project and output results.