I am trying to build a CMake file that replicates a Makefile that I have always used. My professor gave us a working CMakeLists.txt that I have been able to use but I was trying to customize it so it would act the same as my Makefile since I use different flags for each build.
Here is my Makefile:
OBJS = Assign1.cpp
CC = g++
DEBUG_FLAGS = -O0 -g3 -fsanitize=address
RELEASE_FLAGS = -O3 -g0
FLAGS = -std=c++14 -Wall -Wextra
release: $(OBJS)
$(CC) $(RELEASE_FLAGS) $(FLAGS) $(OBJS) -o Assign1
debug: $(OBJS)
$(CC) $(DEBUG_FLAGS) $(FLAGS) $(OBJS) -o debug && cgdb ./debug
In the command line, I simply type make
and it automatically defaults to release. If I type make debug
it will make the debug and run cgdb on the executable.
I have tried doing the same with my CMake File but I do not know how to set up/run different executables if that is the correct terminology. This is my Cmake File:
cmake_minimum_required(VERSION 3.5)
project(Assignment2)
set(RELEASE "-O3 -g0")
set(DEBUG "-O0 -g3 -fsanitize=address")
set(CMAKE_CXX_FLAGS "-std=c++14 -Wall -Wextra")
set(SOURCE_FILES main.cpp compute-e.hpp compute-e.cpp compute-fib.cpp compute-fib.hpp compute-pi.cpp compute-pi.hpp)
add_executable(Assign2 ${RELEASE} ${CMAKE_CXX_FLAGS} ${SOURCE_FILES})
add_executable(debug ${DEBUG} ${CMAKE_CXX_FLAGS} ${SOURCE_FILES} && cgdb ./debug)
What do I need to do to get this to work? I understand Makefiles better than I do CMake files.