-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
53 lines (41 loc) · 1.67 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
cmake_minimum_required(VERSION 3.9.4)
include(CheckIPOSupported)
project(forthscript)
# https://stackoverflow.com/questions/42582456/cmake-function-to-convert-string-to-c-string-literal
function(convert_to_cstring_literal var value)
string(REGEX REPLACE "([\\\"])" "\\\\\\1" escaped "${value}")
string(REPLACE "\n" "\\n" escaped "${escaped}")
set("${var}" "\"${escaped}\"" PARENT_SCOPE)
endfunction()
set(CMAKE_CXX_STANDARD 17)
set(REPL_SOURCE_PATH "${CMAKE_SOURCE_DIR}/src/prelude/repl.fscript")
# Bundle REPL source
message(STATUS "REPL source in ${REPL_SOURCE_PATH}")
file(READ "${REPL_SOURCE_PATH}" REPL_SOURCE)
convert_to_cstring_literal(REPL_SOURCE "${REPL_SOURCE}")
message(STATUS "REPL code listing follows \n${REPL_SOURCE}")
add_definitions(-DFORTHSCRIPT_REPL_SOURCE=${REPL_SOURCE})
# Set NDEBUG variable
message(STATUS "Build type selected = ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE MATCHES Release)
add_definitions(-DNDEBUG)
endif()
# Enabling warnings as errors
if (MSVC)
add_compile_options(/W1)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()
include_directories(include)
file(GLOB_RECURSE SOURCES src/*.cpp)
add_executable(forthscript ${SOURCES})
# Enable LTO on release
if (CMAKE_BUILD_TYPE MATCHES Release)
check_ipo_supported(RESULT supported OUTPUT error)
if ( supported )
message(STATUS "LTO builds are supported")
set_property(TARGET forthscript PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
set_target_properties(forthscript PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
set_target_properties(forthscript PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})