summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: d5ebb4e253346772ee8e0114afa164775de996c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
cmake_minimum_required(VERSION 3.19...3.27)

if(${CMAKE_VERSION} VERSION_LESS 3.12)
    cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

project(libfud
    VERSION 1.0.0
    DESCRIPTION "Library of FUD"
    LANGUAGES CXX C)

set(CXX_CPPCHECK "project=build/compile_commands.json;enable=information;force")

set(CMAKE_EXPORT_COMPILE_COMMANDS true)

add_library(fud SHARED
    source/libfud.cpp
    source/fud_assert.cpp
    source/fud_memory.cpp
    source/fud_c_file.cpp
    source/fud_string.cpp
    source/fud_utf8.cpp
    source/fud_utf8_iterator.cpp
)

include(cmake/warnings.cmake)
target_compile_options(fud PRIVATE "${FUD_WARNINGS}")

target_include_directories(fud PUBLIC include)

set_target_properties(
    fud PROPERTIES
    CXX_STANDARD 20
    C_STANDARD 23
    CXX_EXTENSIONS OFF
    C_EXTENSIONS OFF
    CXX_STANDARD_REQUIRED ON)


if (FUD_TEST)
    add_subdirectory(test)
    # set(CVG_FLAGS -fsanitize=address -fsanitize=undefined --coverage)
    set(CVG_FLAGS --coverage)
    target_compile_options(fud PUBLIC ${CVG_FLAGS})
    target_link_options(fud PUBLIC ${CVG_FLAGS})
endif ()

if (FUD_DOC)
    find_package(Doxygen
        REQUIRED dot
        OPTIONAL_COMPONENTS mscgen dia)

    set(DOXYGEN_GENERATE_HTML YES)
    set(DOXYGEN_GENERATE_MAN YES)
    doxygen_add_docs(fudDocs
        include
        # CONFIG_FILE "Doxyfile"
        Comment "Generate man pages and html"
    )
endif()

include(GNUInstallDirs)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}
    CACHE PATH "Location of header files" )
set(SYSCONFIG_INSTALL_DIR ${CMAKE_INSTALL_SYSCONFDIR}
    CACHE PATH "Location of configuration files" )

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/FudConfig.cmake.in
  ${CMAKE_CURRENT_BINARY_DIR}/FudConfig.cmake
  INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Foo
  PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
write_basic_package_version_file(
  ${CMAKE_CURRENT_BINARY_DIR}/FudConfigVersion.cmake
  VERSION 1.0.0
  COMPATIBILITY SameMajorVersion )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FudConfig.cmake
              ${CMAKE_CURRENT_BINARY_DIR}/FudConfigVersion.cmake
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Fud )

set(FUD_HEADERS
    "include/fud_array.hpp"
    "include/fud_assert.hpp"
    "include/fud_c_file.hpp"
    "include/fud_fud_type_traits.hpp"
    "include/fud_memory.hpp"
    "include/fud_result.hpp"
    "include/fud_status.hpp"
    "include/fud_string.hpp"
    "include/fud_unique_array.hpp"
    "include/fud_utf8.hpp"
    "include/fud_utf8_iterator.hpp"
    "include/libfud.hpp"
)

set_target_properties(fud PROPERTIES PUBLIC_HEADER "${FUD_HEADERS}")

install(TARGETS fud
    EXPORT fud
    PUBLIC_HEADER
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
)