Improve CMakeLists

This commit is contained in:
Alex D. 2021-01-02 18:12:59 +00:00
parent 5a0ef358a4
commit a047a9c6d8
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 80 additions and 57 deletions

View File

@ -1,64 +1,101 @@
cmake_minimum_required(VERSION 3.16)
project(microirc LANGUAGES C)
set(library_VERSION "2020.12.20")
include(GNUInstallDirs)
OPTION(BUILD_TESTS "Build tests for ctest" OFF)
OPTION(BUILD_IRCV3 "Build IRCv3 components" ON)
OPTION(BUILD_HELPERS "Build message helpers" ON)
OPTION(BUILD_VALIDATORS "Build message validators" ON)
OPTION(CODE_ANALYZER "Analyze the code statically" ON)
OPTION(CODE_COVERAGE "Build with coverage tools" OFF)
set(UIRC_VERSION "2021.01.02")
add_compile_definitions(UIRC_VERSION="${UIRC_VERSION}")
# NOTE: Do these seem too annoying? Try writing good code then.
# Code that triggers these warnings will not be accepted unless it has a good reason to trigger them.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Werror -Wformat-overflow=2 -Wformat-security -Winit-self -Wstrict-overflow=2 -Wstringop-overflow=2 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wparentheses -pedantic -fstack-check)
if ( CODE_ANALYZER )
add_compile_options(-fanalyzer)
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Weverything -Wno-padded -Wno-disabled-macro-expansion -pedantic)
if ( CODE_COVERAGE )
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
endif()
endif()
OPTION(BUILD_HELPERS "Build message helpers" ON )
OPTION(BUILD_VALIDATORS "Build message validators" ON )
OPTION(BUILD_IRCV3 "Build IRCv3 components" ON )
OPTION(BUILD_TESTS "Build tests for ctest" OFF)
OPTION(CODE_ANALYZER "Analyze the code statically" OFF)
OPTION(CODE_COVERAGE "Build with coverage tools" OFF)
if ( BUILD_IRCV3 )
message(STATUS "IRCv3 capabilities are going to be built.")
add_compile_definitions(UIRC_IRCV3)
endif()
if ( BUILD_VALIDATORS )
message(STATUS "Message validators are going to be built.")
add_compile_definitions(UIRC_VALIDATORS)
set(build_FILES ${build_FILES} src/validators.c)
endif()
set(build_FILES
set(UIRC_SOURCE
src/assemblers.c
src/misc.c
src/tokenizers.c
)
if ( BUILD_HELPERS )
set(UIRC_HEADERS
include/functions.h
include/helpers.h
include/mappings.h
include/types.h
include/uirc.h
)
#
# Features
#
if (BUILD_IRCV3)
message(STATUS "IRCv3 capabilities are going to be built.")
add_compile_definitions(UIRC_IRCV3)
endif()
if (BUILD_VALIDATORS)
message(STATUS "Message validators are going to be built.")
add_compile_definitions(UIRC_VALIDATORS)
set(UIRC_SOURCE ${UIRC_SOURCE} src/validators.c)
endif()
if (BUILD_HELPERS)
message(STATUS "Helper functions are going to be built.")
set(build_FILES ${build_FILES} src/helpers.c)
set(UIRC_SOURCE ${UIRC_SOURCE} src/helpers.c)
add_compile_definitions(UIRC_HELPERS)
if ( BUILD_IRCV3 )
set(build_FILES ${build_FILES} src/taghelpers.c)
if (BUILD_IRCV3)
set(UIRC_SOURCE ${UIRC_SOURCE} src/taghelpers.c)
endif()
endif()
if (BUILD_TESTS)
message(STATUS "Tests are going to be built.")
enable_testing()
add_subdirectory(tests)
endif()
add_library(uirc ${UIRC_SOURCE})
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror")
add_compile_options(-pedantic)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(
-Wall
-Wextra
-Wformat-overflow=2
-Wformat-security
-Winit-self
-Wstrict-overflow=2
-Wstringop-overflow=2
-Walloc-zero
-Wduplicated-branches
-Wduplicated-cond
-Wtrampolines
-Wfloat-equal
-Wshadow
-Wunsafe-loop-optimizations
-Wparentheses
-fstack-check
)
if (CODE_ANALYZER)
add_compile_options(-fanalyzer)
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(
-Weverything
-Wno-padded
-Wno-disabled-macro-expansion
)
if (CODE_COVERAGE)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
endif()
endif()
add_library(uirc ${build_FILES})
include(GNUInstallDirs)
separate_arguments(UIRC_HEADERS)
set_target_properties(uirc PROPERTIES
C_STANDARD 99
VERSION ${library_VERSION}
SOVERSION ${library_VERSION}
PUBLIC_HEADER "include/functions.h;include/helpers.h;include/mappings.h;include/types.h;include/uirc.h"
VERSION ${UIRC_VERSION}
SOVERSION ${UIRC_VERSION}
PUBLIC_HEADER "${UIRC_HEADERS}"
)
install(
@ -66,9 +103,3 @@ install(
LIBRARY
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uirc
)
if ( BUILD_TESTS )
message(STATUS "Tests are going to be built.")
enable_testing()
add_subdirectory(tests)
endif()

View File

@ -20,11 +20,3 @@
#include "helpers.h"
#include "mappings.h"
#include "types.h"
#ifndef UIRC_GUARD_UIRC
#define UIRC_GUARD_UIRC
#define UIRC_VERSION 20201220
#endif /* UIRC_GUARD_UIRC */