serene/CMakeLists.txt

235 lines
7.2 KiB
CMake
Raw Normal View History

2021-10-12 20:51:03 +01:00
# Serene Programming Language
#
2023-02-06 17:40:45 +00:00
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
2021-10-12 20:51:03 +01:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
2021-10-12 20:51:03 +01:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
2021-10-12 20:51:03 +01:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.19)
project(Serene
VERSION 1.0.0
DESCRIPTION "A modern Lisp."
LANGUAGES CXX C)
# Clangd command file
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# =============================================================================
# Policies
# =============================================================================
cmake_policy(SET CMP0116 OLD)
# =============================================================================
# User Options
# =============================================================================
2021-04-07 19:56:54 +01:00
option(CPP_20_SUPPORT "C++20 Support" OFF)
option(SERENE_BUILD_TESTING "Enable tests" OFF)
option(SERENE_ENABLE_BUILDID "Enable build id." OFF)
option(SERENE_ENABLE_THINLTO "Enable ThisLTO." ON)
option(SERENE_ENABLE_DOCS "Enable document generation" OFF)
option(SERENE_ENABLE_TIDY "Enable clang tidy check" OFF)
2021-09-27 15:25:06 +01:00
option(SERENE_DISABLE_CCACHE "Disable automatic ccache integration" OFF)
2022-04-04 22:42:56 +01:00
option(SERENE_ENABLE_DEVTOOLS "Enable the devtools build" OFF)
2022-06-18 11:11:08 +01:00
# LLVM
# Info about the target llvm build
option(LLVM_USE_PERF "If the target LLVM build is built with LLVM_USE_PERF" OFF)
# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
## Settings =======================
# specify the C++ standard
2021-04-07 19:56:54 +01:00
if (CPP_20_SUPPORT)
set(CMAKE_CXX_STANDARD 20)
else()
2021-04-11 18:36:00 +01:00
set(CMAKE_CXX_STANDARD 17)
2021-04-07 19:56:54 +01:00
endif()
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(SERENE_ENABLE_TIDY)
find_program(CLANG_TIDY_PATH NAMES clang-tidy REQUIRED)
endif()
# We use iwyu intensively. For the version details check out the
# submodule at `deps/include-what-you-use`
find_program(iwyu NAMES include-what-you-use iwyu REQUIRED)
set(iwyu_path ${iwyu})
# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(MemoryCheckCommand "valgrind")
# Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
find_package(BDWgc 8.2.0 REQUIRED)
find_program(LLD_PROGRAM REQUIRED NAMES lld)
find_program(MLIRTBLGEN_PROGRAM REQUIRED NAMES mlir-tblgen)
# Setup the basic compiler flags
add_compile_options(
-Wall
-Wextra
-Werror
2023-02-05 17:35:16 +00:00
-Wpedantic
2023-02-06 15:43:51 +00:00
-Wabstract-final-class
-Walloca
-Warray-bounds-pointer-arithmetic
-Warray-parameter
-Wassign-enum
-Wsign-conversion
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wdouble-promotion
-Wformat=2)
add_link_options(-fuse-ld=lld)
# if ((SERENE_USE_LIBCXX) AND (NOT (SERENE_TOOLCHAIN_PATH)))
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -v")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
# endif()
2021-09-27 15:25:06 +01:00
# if ((SERENE_USE_LIBCXX) AND (SERENE_TOOLCHAIN_PATH))
# endif()
2021-09-27 15:25:06 +01:00
# if (SERENE_USE_COMPILER_RT)
# add_link_options(-rtlib=compiler-rt -stdlib=libc++ )
# endif()
2021-09-27 15:25:06 +01:00
# CCache support ==============================
if(SERENE_DISABLE_CCACHE)
message(STATUS "CCache support is disabled")
else()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Found CCache")
set(SERENE_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
set(SERENE_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
set(SERENE_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
CACHE STRING "Parameters to pass through to ccache")
set(CCACHE_PROGRAM "${SERENE_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
if (SERENE_CCACHE_MAXSIZE)
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${SERENE_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
endif()
if (SERENE_CCACHE_DIR)
set(CCACHE_PROGRAM "CCACHE_DIR=${SERENE_CCACHE_DIR} ${CCACHE_PROGRAM}")
endif()
message(STATUS "Using CCACHE: ${CCACHE_PROGRAM}")
2021-09-27 15:25:06 +01:00
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
else()
message(FATAL_ERROR "Unable to find the program ccache. Set SERENE_DISABLE_CCACHE to ON")
endif()
endif()
Include(FetchContent)
2022-02-19 14:53:24 +00:00
if(SERENE_BUILD_TESTING)
message(STATUS "Fetching Catch2 v3...")
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.0-preview4
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
endif()
2021-09-27 15:25:06 +01:00
# LLVM setup =========================================
# find_package(LLVM REQUIRED all-targets CONFIG)
# find_package(MLIR REQUIRED CONFIG)
# find_package(LLD REQUIRED CONFIG)
# message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
# message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
# message(STATUS "Using LLDConfig.cmake in: ${LLD_DIR}")
# set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
# set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
# set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
# list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
# list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
# list(APPEND CMAKE_MODULE_PATH "${LLD_CMAKE_DIR}")
# include(TableGen)
# include(AddLLVM)
# include(AddMLIR)
# include(HandleLLVMOptions)
# include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
2021-11-03 14:06:45 +00:00
# separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
# add_definitions(${LLVM_DEFINITIONS_LIST})
# link_directories(${LLVM_BUILD_LIBRARY_DIR})
# add_definitions(${LLVM_DEFINITIONS})
# set(CONDITIONAL_COMPONENTS "")
# if(LLVM_USE_PERF)
# list(APPEND CONDITIONAL_COMPONENTS PerfJITEvents)
# endif()
# llvm_map_components_to_libnames(llvm_libs
# core
# support
# jitlink
# orcjit
# ExecutionEngine
# ${CONDITIONAL_COMPONENTS}
# ${LLVM_TARGETS_TO_BUILD}
# )
# # Serene Setup ===================================
# # Make sure that our source directory is on the current cmake module path so
# # that we can include cmake files from this directory.
# list(INSERT CMAKE_MODULE_PATH 0
# "${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
# "${LLVM_COMMON_CMAKE_UTILS}/Modules"
# )
add_subdirectory(serene)
# include(tablegen-serene)
# Create the tools we use to compile Serene
#add_subdirectory(serene-tblgen)
# The compiled library code is here
# add_subdirectory(libserene)
# The static library containing builtin special forms and functions
# add_subdirectory(core)
# Binary tools of the compiler
# add_subdirectory(serenec)
# add_subdirectory(serene-repl)
# add_subdirectory(devtools)
2022-04-04 22:42:56 +01:00
if (SERENE_ENABLE_DOCS)
add_subdirectory(docs)
endif()
endif()