Kyle A. answered 05/05/20
Senior Software Engineer Specializing in Systems Programming
Hi!
This may depend on the specific CMake generator you are using. IDEs such as CLion will manage this for you and create separate directories for Release and Debug.
If you are are using a single configuration generator like Makefiles you can use the CMAKE_BUILD_TYPE variable which will allow you to select DEBUG or RELEASE among other options.
Check out the documentation for this variable here. This page also talks about multi config generators and other options.
https://cmake.org/cmake/help/v3.0/variable/CMAKE_BUILD_TYPE.html
To use this, you can pass it in on the command line like so:
CMake also allows you to set both a C and C++ compiler separately using the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables. Usually it's best to set these in your environment before running CMake rather than hard coding them in your CMakeLists.txt though. I'm assuming the library you're referencing is C code since you want to compile with gcc? CMake should use the correct compiler based on the file extension to my knowledge.