-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
143 lines (122 loc) · 5.78 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
cmake_minimum_required(VERSION 3.9)
project(jstar)
set(CMAKE_PROJECT_DESCRIPTION "A lightweight embeddable scripting language")
set(CMAKE_PROJECT_HOMEPAGE_URL "https://bamless.github.io/jstar/")
set(JSTAR_VERSION_MAJOR 2)
set(JSTAR_VERSION_MINOR 0)
set(JSTAR_VERSION_PATCH 0)
set(JSTAR_VERSION ${JSTAR_VERSION_MAJOR}.${JSTAR_VERSION_MINOR}.${JSTAR_VERSION_PATCH})
set(CMAKE_C_STANDARD 99)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# General options
option(JSTAR_INSTALL "Generate install targets" ON)
option(JSTAR_COMPUTED_GOTOS "Use computed gotos for VM eval loop" ON)
option(JSTAR_NAN_TAGGING "Use NaN tagging technique to store the VM internal type" ON)
option(JSTAR_DBG_PRINT_EXEC "Trace the execution of the VM" OFF)
option(JSTAR_DBG_PRINT_GC "Trace the execution of the garbage collector" OFF)
option(JSTAR_DBG_STRESS_GC "Stress the garbage collector by calling it on every allocation" OFF)
option(JSTAR_INSTRUMENT "Enable function instrumentation" OFF)
# Options for optional libraries
option(JSTAR_SYS "Include the 'sys' module in the language" ON)
option(JSTAR_IO "Include the 'io' module in the language" ON)
option(JSTAR_MATH "Include the 'math' module in the language" ON)
option(JSTAR_DEBUG "Include the 'debug' module in the language" ON)
option(JSTAR_RE "Include the 're' module in the language" ON)
# Setup config file
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/cmake/conf.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/jstar/conf.h
)
# Set default build type if not specified
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
# Check for link time optimization support
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO)
if(LTO)
message(STATUS "J* link-time optimization enabled")
endif()
endif()
# Set output directories
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
# Set compiler flags
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -fomit-frame-pointer -fno-plt -s")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Qunused-arguments -O3 -fomit-frame-pointer -fno-plt -s")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
elseif(MSVC)
# Disable secure warnings for the useless _s variants of standard functions.
# These shouldn't even exist in c99 but MSVC will complain about them because it's MSVC.
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DNOMINMAX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244 /wd4267 /wd5105 /wd4116")
endif()
# Find Python, needed to run build-time scripts
find_package(Python COMPONENTS Interpreter)
# Instrumentation
add_subdirectory(profile)
# J*, cli, compiler and external dependencies
add_subdirectory(src)
add_subdirectory(apps)
add_subdirectory(extern)
# -----------------------------------------------------------------------------
# Installation
# -----------------------------------------------------------------------------
if(JSTAR_INSTALL)
include(GNUInstallDirs)
# Install export files
install(EXPORT jstar-export
FILE JStarTargets.cmake
NAMESPACE jstar::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jstar
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/JStarConfigVersion.cmake
VERSION ${JSTAR_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/JStarConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/JStarConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jstar
)
# Install license files
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION share/licenses/jstar)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern/argparse/LICENSE DESTINATION share/licenses/jstar/argparse)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern/cwalk/LICENSE.md DESTINATION share/licenses/jstar/cwalk)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern/dirent/LICENSE DESTINATION share/licenses/jstar/dirent)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern/replxx/LICENSE.md DESTINATION share/licenses/jstar/replxx)
# On Windows install required runtime dlls alongside exe
include(cmake/MinGWRuntime.cmake)
include(InstallRequiredSystemLibraries)
# Packaging support
set(CPACK_PACKAGE_VENDOR "bamless")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "J* - A Lightweight Scripting Language")
set(CPACK_PACKAGE_EXECUTABLES jstar;jstar)
set(CPACK_PACKAGE_VERSION ${JSTAR_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${JSTAR_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${JSTAR_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${JSTAR_VERSION_PATCH})
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "jstar")
include(CPack)
endif()