forked from ibphoenix/tomsfastmath
224 lines
7.5 KiB
CMake
224 lines
7.5 KiB
CMake
##
|
|
## THIS IS THE MASTER FILE
|
|
## It contains some basic defaults and defintions that are inherited by the projects
|
|
##
|
|
|
|
################################################################################
|
|
# CONTENTS
|
|
#
|
|
# Project header
|
|
# CMake globals
|
|
# Project Settings
|
|
# Options
|
|
|
|
# Targets
|
|
|
|
# Testing (TODO)
|
|
# Packaging (TODO)
|
|
################################################################################
|
|
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
|
|
include(ConfigSafeGuards)
|
|
|
|
|
|
################################################################################
|
|
#
|
|
# Project header
|
|
#
|
|
#################################################################################
|
|
|
|
# Suppress "Policy CMP0066 is not set"
|
|
# This policy provides compatibility for projects that do not expect
|
|
# config-specific compiler flags to be used.
|
|
# See https://cmake.org/cmake/help/latest/policy/CMP0066.html
|
|
#set (CMAKE_POLICY_WARNING_CMP0066 OFF)
|
|
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
# tomsfastmath - modified from CMakeLists.txt created for libtomath
|
|
project (TOMSFASTMATH
|
|
VERSION 0.13.1
|
|
DESCRIPTION "TomsFastMath is meant to be a very fast yet still fairly portable and easy to port large integer arithmetic library written in ISO C."
|
|
HOMEPAGE_URL "https://github.com/libtom/tomsfastmath"
|
|
LANGUAGES C)
|
|
|
|
# package release version
|
|
# bump if re-releasing the same VERSION + patches
|
|
# set to 1 if releasing a new VERSION
|
|
set(PACKAGE_RELEASE_VERSION 1)
|
|
################################################################################
|
|
#
|
|
# CMake Global Settings
|
|
#
|
|
################################################################################
|
|
|
|
# Allow use of function cmake_print_variables to print vars to output
|
|
# See https://cmake.org/cmake/help/latest/module/CMakePrintHelpers.html
|
|
include(CMakePrintHelpers)
|
|
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "Export compile_commands.json to support editors such as Kate, Visual Studio Code, Vim etc.")
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON CACHE INTERNAL "Generate verbose makefile")
|
|
|
|
# For tomsfastmath we use Build, although convention is to use all lowercase
|
|
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/Build)
|
|
|
|
|
|
################################################################################
|
|
#
|
|
# Project Settings
|
|
#
|
|
#################################################################################
|
|
|
|
# Define build mode - this must be executed AFTER the project command otherwise
|
|
# the cmake compiler will complain that CMAKE_BUILD_TYPE is uninitialised.
|
|
message(STATUS "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}")
|
|
if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
|
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build...")
|
|
endif()
|
|
|
|
if ( UNIX )
|
|
set(CMAKE_INSTALL_PREFIX /opt/fireswarm CACHE PATH "Default installation directory" FORCE)
|
|
elseif ( WIN32 )
|
|
set(CMAKE_INSTALL_PREFIX $ENV{ProgramFiles}/fireswarm CACHE PATH "Default installation directory" FORCE)
|
|
endif()
|
|
|
|
|
|
################################################################################
|
|
#
|
|
# Option Settings
|
|
#
|
|
#################################################################################
|
|
|
|
# ### Options: Things you can set via commandline options to cmake (e.g. -DTOMSFASTMATH_DISABLE_LIBCXX=[ON|OFF])
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
|
|
|
option(TOMSFASTMATH_DISABLE_LIBCXX "Do not use libc++, even if available" ON)
|
|
|
|
option(ENABLE_WARNINGS_SETTINGS "Allow target_set_warnings to add flags and defines.
|
|
Set this to OFF if you want to provide your own warning parameters.
|
|
See cmake/Warnings.cmake for more info." ON)
|
|
|
|
option(ENABLE_LTO "Enable link time optimization" ON)
|
|
|
|
|
|
include(LTO)
|
|
include(Warnings)
|
|
include(functions)
|
|
include(sources)
|
|
include(CompilerSettings)
|
|
|
|
# Check for LTO (Link-time optimisation) support.
|
|
find_lto(CXX)
|
|
|
|
|
|
include_directories( "src/" "src/headers" )
|
|
include(cmake/sources.cmake)
|
|
|
|
# The only direct cmake argument for now
|
|
option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# Compose CFLAGS
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Some information ported from makefile_include.mk
|
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
message(STATUS "Setting build type to 'Release' as none was specified.")
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
endif()
|
|
|
|
# We only differentiate between MSVC and GCC-compatible compilers
|
|
if(MSVC)
|
|
set(LTM_C_FLAGS -W3)
|
|
elseif(WATCOM)
|
|
set(LTM_C_FLAGS -fo=.obj -oaxt -3r -w3)
|
|
else()
|
|
set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow
|
|
-Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
|
|
-Wstrict-prototypes -Wpointer-arith -Wsystem-headers)
|
|
set(CMAKE_C_FLAGS_DEBUG "-g3")
|
|
set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
|
|
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
|
|
endif()
|
|
|
|
# What compiler do we have and what are their...uhm... peculiarities
|
|
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
|
|
list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header)
|
|
# Clang requires at least '-O1' for dead code elimination
|
|
set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}")
|
|
endif()
|
|
if(CMAKE_C_COMPILER MATCHES "mingw")
|
|
list(APPEND LTM_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast)
|
|
endif()
|
|
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
|
list(APPEND LTM_C_FLAGS -Wno-nullability-completeness)
|
|
endif()
|
|
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
|
|
list(APPEND LTM_C_FLAGS -no-undefined)
|
|
endif()
|
|
|
|
# TODO: coverage (lgcov)
|
|
|
|
# If the user set the environment variables at generate-time, append them
|
|
# in order to allow overriding our defaults.
|
|
# ${LTM_CFLAGS} means the user passed it via sth like:
|
|
# $ cmake -DLTM_CFLAGS="foo"
|
|
list(APPEND LTM_C_FLAGS ${LTM_CFLAGS})
|
|
list(APPEND LTM_LD_FLAGS ${LTM_LDFLAGS})
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# library target
|
|
#-----------------------------------------------------------------------------
|
|
add_library( ${PROJECT_NAME} SHARED
|
|
${TFM_SOURCE}
|
|
${TFM_HEADERS}
|
|
)
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
|
|
)
|
|
|
|
target_compile_options(${PROJECT_NAME} BEFORE PRIVATE
|
|
${LTM_C_FLAGS}
|
|
)
|
|
target_link_options(${PROJECT_NAME} BEFORE PRIVATE
|
|
${LTM_LD_FLAGS}
|
|
)
|
|
|
|
set(PUBLIC_HEADERS tfm.h)
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
OUTPUT_NAME tomsfastmath
|
|
VERSION ${PROJECT_VERSION}
|
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
|
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
|
)
|
|
|
|
option(COMPILE_LTO "Build with LTO enabled")
|
|
if(COMPILE_LTO)
|
|
check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO)
|
|
if(COMPILER_SUPPORTS_LTO)
|
|
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
else()
|
|
message(SEND_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.")
|
|
endif()
|
|
endif()
|
|
|
|
|
|
|
|
################################################################################
|
|
################################################################################
|
|
################################################################################
|
|
################################################################################
|
|
|