This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
78 lines (57 loc) · 2.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
cmake_minimum_required(VERSION 3.8)
#### Basic project settings
# Project name
project(Caramel)
# Version numbers
set(VERSION_MAJOR 0)
set(VERSION_MINOR 0)
set(VERSION_PATCH 1)
configure_file (
"src/Common.h.in"
"${PROJECT_BINARY_DIR}/Common.h"
)
include_directories("${PROJECT_BINARY_DIR}")
# Change the required C++ standard
set(CMAKE_CXX_STANDARD 17)
# Make the compiler more strict
#set(CXX_STRICT_WARNINGS "-Werror")
set(CXX_STRICT_WARNINGS "-fno-elide-constructors -pedantic-errors -ansi -Wextra -Wall -Winit-self -Wold-style-cast -Woverloaded-virtual -Wuninitialized -Winit-self")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STRICT_WARNINGS}")
# Change default output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/cpp-bin)
# Print the source directory
message("Current source directory: " ${CMAKE_CURRENT_SOURCE_DIR})
#### Library setup : copy shared object + define grammar as a library
set(PROJECT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib)
# Find Antlr runtime library and store the path in ANTLR_RUNTIME
find_library(ANTLR_RUNTIME NAMES libantlr4-runtime.so.4.7.1 PATHS ${PROJECT_LIBRARY_DIR})
# Copy shared library in output directory (we avoid setting LD_LIBRARY_PATH)
configure_file(${PROJECT_LIBRARY_DIR}/libantlr4-runtime.so.4.7.1
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libantlr4-runtime.so.4.7.1 COPYONLY)
# Get every cpp file path into GRAMMAR_BASE
file(GLOB_RECURSE GRAMMAR_BASE ${CMAKE_SOURCE_DIR}/build/cpp-grammar/*.cpp)
# Define Grammar as a library managed and built by CMake
add_library(Grammar ${GRAMMAR_BASE})
target_include_directories(Grammar SYSTEM PRIVATE ${PROJECT_LIBRARY_DIR}/antlr4-runtime-headers)
# Disable GCC warnings when compiling Antlr
target_compile_options(Grammar
PRIVATE "-Wno-unused-parameter"
PRIVATE "-Wno-unused-but-set-variable")
#### Executable setup: define source files, executable, include directories and library links
file(GLOB_RECURSE SOURCE_FILES
"src/*.cpp"
"src/*.h"
)
add_executable(Caramel ${SOURCE_FILES})
# Check if Chef has been invoked before
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/build/cpp-grammar")
message("You have to run `./chef.py build --grammar --language cpp --brew` first.")
endif()
# For Grammar library and Caramel, set include directories. Caramel should have Grammar headers included.
target_include_directories(Caramel SYSTEM PRIVATE ${PROJECT_LIBRARY_DIR}/antlr4-runtime-headers)
target_include_directories(Caramel PRIVATE ${CMAKE_SOURCE_DIR}/build/cpp-grammar)
# Add the tclap library.
target_include_directories(Caramel SYSTEM PRIVATE ${PROJECT_LIBRARY_DIR}/tclap/include)
# Link Caramel
target_link_libraries(Caramel ${ANTLR_RUNTIME})
target_link_libraries(Caramel Grammar)