Skip to content
Snippets Groups Projects
Commit ef437634 authored by brusale's avatar brusale
Browse files

move building to CMake

parent ba1e1c15
Branches cmake-build
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.10)
# Project name
project(COCOATruth)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g -O3")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -static-libasan")
# Include directories
include_directories(interface)
# Find all source files
file(GLOB SRCS "src/*.cc")
file(GLOB HEADERS "interface/*.h")
# Add library
add_library(PFTruth STATIC ${SRCS})
# Find ROOT package
find_package(ROOT REQUIRED)
include_directories(${ROOT_INCLUDE_DIRS})
link_directories(${ROOT_LIBRARY_DIRS})
add_definitions(${ROOT_CXX_FLAGS})
# Add executable
add_executable(COCOATruth COCOATruth.cc)
target_link_libraries(COCOATruth PFTruth ${ROOT_LIBRARIES})
# Clean up
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}")
\ No newline at end of file
# Variables
CC := g++
CFLAGS := -Wall -Wextra -g -O3 -std=c++17
ASANFLAGS := -fsanitize=address -static-libasan
ROOTFLAGS := `root-config --glibs --cflags`
INCLUDES := -Iinterface
LIBS := libPFTruth.a
#EXECUTABLE := pftruth
EXECUTABLE := COCOATruth
# Find all source files
SRCS := $(wildcard src/*.cc)
OBJS := $(SRCS:.cc=.o)
HEADERS := $(wildcard interface/*.h)
# Default target
all: $(LIBS) $(EXECUTABLE)
# Compile .cc files into .o files
%.o: %.cc $(HEADERS)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
# Archive .o files into a static library
$(LIBS): $(OBJS)
ar rcs $@ $^
# Compile pftruth.cc into an executable
#$(EXECUTABLE): pftruth.cc $(LIBS)
# $(CC) $(CFLAGS) $(ROOTFLAGS) $< $(INCLUDES) $(LIBS) -o $@
#
$(EXECUTABLE): COCOATruth.cc $(LIBS)
$(CC) $(CFLAGS) $(ROOTFLAGS) $< $(INCLUDES) $(LIBS) -o $@
# Clean up
clean:
rm -f $(OBJS) $(LIBS) $(EXECUTABLE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment