144 lines
3.9 KiB
CMake
144 lines
3.9 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(
|
|
uIRC
|
|
VERSION 0.4.0
|
|
DESCRIPTION "Simple and lightweight IRC protocol helper"
|
|
LANGUAGES C
|
|
)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
add_compile_definitions(UIRC_VERSION="${PROJECT_VERSION}")
|
|
|
|
OPTION(BUILD_IRCV3 "Build IRCv3 components" OFF)
|
|
OPTION(BUILD_VALIDATORS "Build message validators" OFF)
|
|
OPTION(BUILD_DOCS "Build documentation with doxygen" OFF)
|
|
OPTION(BUILD_TESTS "Build tests that check the library compliance" OFF)
|
|
OPTION(CODE_ANALYZER "Analyze the code statically" OFF)
|
|
OPTION(CODE_COVERAGE "Build with coverage tools" OFF)
|
|
|
|
set(UIRC_SOURCE
|
|
src/assembler/message.c
|
|
src/assembler/user.c
|
|
src/command/command.c
|
|
src/command/reply.c
|
|
src/error/error.c
|
|
src/memory/list.c
|
|
src/memory/struct.c
|
|
src/mode/mode.c
|
|
src/tokenizer/message.c
|
|
src/tokenizer/user.c
|
|
)
|
|
|
|
set(UIRC_HEADERS
|
|
include/assembler.h
|
|
include/command.h
|
|
include/ctcp.h
|
|
include/error.h
|
|
include/memory.h
|
|
include/misc.h
|
|
include/mode.h
|
|
include/tag.h
|
|
include/tokenizer.h
|
|
include/type.h
|
|
include/uirc.h
|
|
include/validator.h
|
|
)
|
|
|
|
# Libraries
|
|
find_library(LLIST_PATH NAMES llist REQUIRED)
|
|
find_library(STRINGEXT_PATH NAMES stringext REQUIRED)
|
|
set(UIRC_LIBS ${STRINGEXT_PATH} ${LLIST_PATH})
|
|
|
|
# Features
|
|
if (BUILD_IRCV3)
|
|
message(STATUS "IRCv3 capabilities enabled")
|
|
add_compile_definitions(UIRC_FEATURE_IRCV3)
|
|
set(UIRC_SOURCE
|
|
${UIRC_SOURCE}
|
|
src/assembler/tag.c
|
|
src/tokenizer/tag.c
|
|
src/tag/tag.c
|
|
)
|
|
endif()
|
|
if (BUILD_VALIDATORS)
|
|
message(STATUS "Message validators enabled")
|
|
add_compile_definitions(UIRC_FEATURE_VALIDATORS)
|
|
set(UIRC_SOURCE
|
|
${UIRC_SOURCE}
|
|
src/validator/validator.c
|
|
)
|
|
endif()
|
|
if (BUILD_CTCP)
|
|
message(STATUS "CTCP support will be built")
|
|
add_compile_definitions(UIRC_FEATURE_CTCP)
|
|
set(UIRC_SOURCE
|
|
${UIRC_SOURCE}
|
|
src/ctcp/ctcp.c
|
|
)
|
|
endif()
|
|
if(BUILD_DOCS)
|
|
find_package(Doxygen REQUIRED)
|
|
if (DOXYGEN_FOUND)
|
|
set(DOXYGEN_SOURCE_BROWSER YES)
|
|
set(DOXYGEN_MACRO_EXPANSION YES)
|
|
set(DOXYGEN_EXPAND_ONLY_PREDEF YES)
|
|
set(DOXYGEN_PREDEFINED
|
|
"UIRC_FEATURE_IRCV3"
|
|
"UIRC_FEATURE_VALIDATORS"
|
|
)
|
|
doxygen_add_docs(docgen
|
|
src/doc/main.doc
|
|
README.md
|
|
${UIRC_HEADERS}
|
|
ALL
|
|
)
|
|
endif()
|
|
endif()
|
|
if (BUILD_TESTS)
|
|
message(STATUS "Tests are going to be built.")
|
|
add_subdirectory(src/test)
|
|
enable_testing()
|
|
add_test(NAME "FullLoop" COMMAND "fullloop" )
|
|
add_test(NAME "EarlyTrail" COMMAND "earlytrail")
|
|
add_test(NAME "OptCRLF" COMMAND "optcrlf" )
|
|
add_test(NAME "Allocators" COMMAND "allocs" )
|
|
add_test(NAME "ManualAssemblers" COMMAND "manassm" )
|
|
add_test(NAME "ErrorNumbers" COMMAND "errno" )
|
|
add_test(NAME "Modes" COMMAND "modes" )
|
|
endif()
|
|
|
|
add_library(uirc ${UIRC_SOURCE})
|
|
target_link_libraries(uirc ${UIRC_LIBS})
|
|
target_include_directories(uirc PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
)
|
|
|
|
separate_arguments(UIRC_HEADERS)
|
|
set_target_properties(uirc PROPERTIES
|
|
C_STANDARD 99
|
|
VERSION ${PROJECT_VERSION}
|
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
|
PUBLIC_HEADER "${UIRC_HEADERS}"
|
|
)
|
|
|
|
install(
|
|
TARGETS uirc
|
|
LIBRARY
|
|
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/uirc"
|
|
)
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror")
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -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 -pedantic")
|
|
if (CODE_ANALYZER)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fanalyzer")
|
|
endif()
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Weverything -Wno-padded -Wno-disabled-macro-expansion -pedantic")
|
|
if (CODE_COVERAGE)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
|
|
endif()
|
|
endif()
|
|
|