feynman/CMakeLists.txt

154 lines
4.7 KiB
CMake

# Feynman -- Wayland compositor for GNU Emacs
#
# Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
#
# 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.
#
# 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.
#
# 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 name and a few useful settings. Other commands can pick up the results
project(Feynman
VERSION 0.0.0
DESCRIPTION "Wayland compositor for GNU Emacs"
LANGUAGES C)
# Clangd command file
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Policies ==========================
cmake_policy(SET CMP0116 OLD)
# User Options ======================
option(FEYNMAN_ENABLE_BUILDID "Enable build id." OFF)
option(FEYNMAN_ENABLE_TIDY "Enable clang tidy check" OFF)
option(FEYNMAN_DISABLE_CCACHE "Disable automatic ccache integration" OFF)
set(FEYNMAN_EMACS_DIR "" CACHE PATH "PATH to the Emacs build directory")
# 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 =======================
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
# Setup the source locations
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/libfeynman/include)
#configure_file(${INCLUDE_DIR}/config.h.in src/config.h)
if(FEYNMAN_ENABLE_TIDY)
find_program(CLANG_TIDY_PATH NAMES clang-tidy REQUIRED)
endif()
find_program(iwyu NAMES include-what-you-use iwyu REQUIRED)
set(iwyu_path ${iwyu})
set(MemoryCheckCommand "valgrind")
# Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Setup the basic compiler flags
add_compile_options(
-Wall
-Wextra
-Werror
-fno-rtti
# Dedicate a section to each function, so the linker
# can do a better job on dead code elimination
-ffunction-sections
-fdata-sections
$<$<CONFIG:DEBUG>:-g3>
$<$<CONFIG:DEBUG>:-O1>
$<$<CONFIG:DEBUG>:-ggdb>
# For the sake of debugging
$<$<CONFIG:DEBUG>:-fno-inline>
# To make the local ccache happy
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=.>
# No tail call elimination on Debug to let asan provide
# better stacktrackes
$<$<CONFIG:DEBUG>:-fno-optimize-sibling-calls>
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
$<$<CONFIG:RELEASE>:-O3>
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
)
add_link_options(
# We enforce the lld linker
-fuse-ld=lld
-Wl,-gc-sections
$<$<CONFIG:RELEASE>:-s>
# Do not link against shared libraries
#--static
)
if(FEYNMAN_ENABLE_BUILDID)
add_link_options(-Wl,--build-id)
endif()
include(GNUInstallDirs)
Include(FetchContent)
# CCache support ==============================
if(FEYNMAN_DISABLE_CCACHE)
message(STATUS "CCache support is disabled")
else()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Found CCache")
set(FEYNMAN_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
set(FEYNMAN_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
set(FEYNMAN_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
CACHE STRING "Parameters to pass through to ccache")
set(CCACHE_PROGRAM "${FEYNMAN_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
if (FEYNMAN_CCACHE_MAXSIZE)
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${FEYNMAN_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
endif()
if (FEYNMAN_CCACHE_DIR)
set(CCACHE_PROGRAM "CCACHE_DIR=${FEYNMAN_CCACHE_DIR} ${CCACHE_PROGRAM}")
endif()
message(STATUS "Using CCACHE: ${CCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
else()
message(FATAL_ERROR "Unable to find the program ccache. Set FEYNMAN_DISABLE_CCACHE to ON")
endif()
endif()
# Feynman Setup ===================================
add_definitions(-DWLR_USE_UNSTABLE)
include_directories(SYSTEM ${PROJECT_BINARY_DIR}/src)
include_directories(SYSTEM ${FEYNMAN_EMACS_DIR}/include)
include_directories(${INCLUDE_DIR})
# Hide all the symbols by default
if(NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
endif()
add_subdirectory(libfeynman)
add_subdirectory(src)
endif()