Yzena
/
Yc
2
1
Fork 0
C Utils for Yzena https://docs.yzena.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

254 lines
7.3 KiB

# ***** BEGIN LICENSE BLOCK *****
#
# Copyright 2017-2022 Yzena Tech
#
# Licensed under the Yzena Viral User License, Version 0.1 (the "Yzena Viral
# User License" or "YVUL"), the GNU Affero General Public License (the "GNU
# AGPL"), Version 3.0, and the Server Side Public License (the "SSPL"),
# Version 1. You may not use this file except in compliance with all of those
# licenses.
#
# You may obtain a copy of the Yzena Viral User License at
#
# https://yzena.com/yzena-viral-user-license/
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Yzena Viral User License is distributed under the
# following disclaimer:
#
# As far as the law allows, this software comes as is, without any
# warranty or condition, and no contributor will be liable to anyone for
# any damages related to this software or this license, under any kind of
# legal claim.
#
# You may obtain a copy of the GNU Affero General Public License at
#
# https://www.gnu.org/licenses/agpl-3.0.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the GNU Affero General Public License is distributed under
# the following disclaimer:
#
# This software 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 Affero
# General Public License for more details.
#
# You may obtain a copy of the Server Side Public License at
#
# https://www.mongodb.com/licensing/server-side-public-license
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Server Side Public License is distributed under the
# following disclaimer:
#
# This software 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 Server
# Side Public License for more details.
#
# ****** END LICENSE BLOCK ******
cmake_minimum_required(VERSION 3.0)
project(yc C)
cmake_policy(SET CMP0054 NEW)
set(CMAKE_C_STANDARD 11)
# Necessary to suppress a useless warning with QtCreator.
set(ignoreMe "${QT_QMAKE_EXECUTABLE}")
set(ignoreMe "${CMAKE_CXX_COMPILER}")
option(YC_ENABLE_FTRACE "Enable tracing of function calls" OFF)
if ("${YC_ENABLE_FTRACE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_ENABLE_FTRACE=1")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_ENABLE_FTRACE=0")
endif()
option(YC_ENABLE_AFL "Enable fuzzing with AFL" OFF)
if ("${YC_ENABLE_AFL}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_ENABLE_AFL=1 -DYC_DEBUG")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_ENABLE_AFL=0")
endif()
option(YC_ENABLE_ALLOC_ACCOUNTING "Enable extra accounting in allocators" ON)
if ("${YC_ENABLE_ALLOC_ACCOUNTING}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_ENABLE_ALLOC_ACCOUNTING=1")
else()
if ("${YC_ENABLE_FTRACE}")
message(SEND_ERROR "Must enable alloc accounting with ftrace")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_ENABLE_ALLOC_ACCOUNTING=0")
endif()
if(NOT "${MSVC}")
option(YC_USE_VALGRIND OFF)
if("${YC_USE_VALGRIND}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_USE_VALGRIND")
endif()
string(COMPARE NOTEQUAL "${CMAKE_SYSTEM_NAME}" "FreeBSD" result)
if(result)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200809L")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE")
option(YC_STRICT_BUILD "Build with strict compiler options" ON)
if("${YC_STRICT_BUILD}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Weverything -Wno-padded")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-c++98-compat")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-disabled-macro-expansion")
endif()
endif()
option(YC_NO_POSIX_SPAWN OFF)
if("${YC_NO_POSIX_SPAWN}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_NO_POSIX_SPAWN")
endif()
endif()
add_subdirectory("cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
message(STATUS "${CMAKE_BUILD_TYPE}")
# If we are in debug mode...
if(("${CMAKE_BUILD_TYPE}" MATCHES "Debug" OR "${CMAKE_BUILD_TYPE}" MATCHES "RelWithDegInfo")
AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
# Create the sanitizer options.
option(YC_SANITIZER_ADDRESS "Build with AddressSanitizer" ON)
# If the memory sanitizer is in use, set the flag.
if ("${YC_SANITIZER_ADDRESS}")
string(CONCAT YC_SANITIZER_FLAGS " -fsanitize=address")
endif()
# Option to run the undefined behavior sanitizer.
option(YC_SANITIZER_UNDEFINED "Build with UndefinedBehaviorSanitizer" ON)
# If we want to run the undefined behavior sanitizer...
if("${YC_SANITIZER_UNDEFINED}")
string(CONCAT YC_SANITIZER_FLAGS " -fsanitize=undefined")
endif()
endif()
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
option(YC_DEBUG_CODE "Add extra debug code" OFF)
else()
set(YC_DEBUG_CODE FALSE)
endif()
if("${YC_DEBUG_CODE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_DEBUG_CODE=1")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DYC_DEBUG_CODE=0")
endif()
# If we are using sanitizers...
if(DEFINED YC_SANITIZER_FLAGS)
# We must use Clang as the linker.
set(CMAKE_LINKER "${CMAKE_C_COMPILER}")
# These are all options to make the print outs prettier.
string(CONCAT YC_FLAGS "${YC_SANITIZER_FLAGS} -fno-omit-frame-pointer "
"-fno-optimize-sibling-calls -fno-common")
# We need to set compiler *and* linker flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${YC_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${YC_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover=all")
endif()
# If we are in release mode...
if("${CMAKE_BUILD_TYPE}" MATCHES "Release")
option(YC_ENABLE_LTO "Build with link time optimization" OFF)
if ("${YC_ENABLE_LTO}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
endif()
# Have an option to harden Yc.
option(YC_HARDEN "Build with hardened security" OFF)
# If we are hardened, add Control Flow Integrity.
# We would like to add Safe Stack, but it seg faults
# with jemalloc right now.
if("${YC_HARDEN}")
# Set a bunch of initial flags.
#set(YC_FLAGS "-fsanitize=cfi -fvisibility=hidden -fsanitize=safe-stack")
set(YC_FLAGS "-fsanitize=cfi -fvisibility=hidden")
# We need to set compiler flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${YC_FLAGS}")
endif()
endif()
set("YC_DOCS_DIR" "docs")
set("YC_INCLUDE_DIR" "include")
set("YC_SRC_DIR" "src")
enable_testing()
option(YC_ENABLE_LONG_TESTS "Enable tests that take a long time to run" OFF)
if ("${YC_ENABLE_LONG_TESTS}")
option(
YC_ENABLE_EXTRA_LONG_TESTS
"Enable tests that take an extra long time to run" OFF)
endif()
if(NOT "${MSVC}")
add_subdirectory("${YC_DOCS_DIR}")
endif()
include_directories("${YC_INCLUDE_DIR}")
add_subdirectory("${YC_INCLUDE_DIR}")
add_subdirectory("${YC_SRC_DIR}")
option(YC_ENABLE_TESTS "Enable building all tests" ON)
if("${YC_ENABLE_TESTS}")
add_subdirectory("tests")
endif()
option(YC_BUILD_SAMPLES "Build samples" OFF)
if ("${YC_BUILD_SAMPLES}")
add_subdirectory(samples)
endif()
option(YC_BUILD_BENCHMARKS "Enable building benchmarks" OFF)
if ("${YC_BUILD_BENCHMARKS}")
add_subdirectory(benchmarks)
endif()