summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 6a3076b5a79c785debff74cdf01d783e362062e4 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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 0.42.0
    DESCRIPTION "Library of FUD"
    LANGUAGES CXX)

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

set(CMAKE_EXPORT_COMPILE_COMMANDS true)

find_package(SQLite3 REQUIRED)

add_library(fud SHARED
    source/libfud.cpp
    source/fud_allocator.cpp
    source/fud_assert.cpp
    source/fud_format.cpp
    source/fud_directory.cpp
    source/fud_c_file.cpp
    source/fud_memory.cpp
    source/fud_sqlite.cpp
    source/fud_string_view.cpp
    source/fud_string_convert.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}" -fno-rtti -fno-exceptions)

target_include_directories(fud PUBLIC include ${SQLite3_INCLUDE_DIRS})
target_include_directories(fud PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)

target_link_libraries(fud ${SQLite3_LIBRARIES})

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

if (DEFINED FUD_BOUNDS_CHECKING)
else()
    set(FUD_BOUNDS_CHECKING true)
endif()

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/libfud.hpp"
    "include/fud_allocator.hpp"
    "include/fud_algorithm.hpp"
    "include/fud_array.hpp"
    "include/fud_assert.hpp"
    "include/fud_c_file.hpp"
    "include/fud_c_string.hpp"
    "include/fud_directory.hpp"
    "include/fud_fixed_vector.hpp"
    "include/fud_fud_type_traits.hpp"
    "include/fud_memory.hpp"
    "include/fud_option.hpp"
    "include/fud_permissions.hpp"
    "include/fud_result.hpp"
    "include/fud_span.hpp"
    "include/fud_status.hpp"
    "include/fud_string.hpp"
    "include/fud_string_convert.hpp"
    "include/fud_string_view.hpp"
    "include/fud_sqlite.hpp"
    "include/fud_unique_array.hpp"
    "include/fud_utf8.hpp"
    "include/fud_utf8_iterator.hpp"
    "include/fud_vector.hpp"
    "${CMAKE_CURRENT_BINARY_DIR}/fud_config.hpp"
)

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

install(TARGETS fud
    EXPORT fud
    PUBLIC_HEADER
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
)
include(cmake/CheckGit.cmake)
CheckGitSetup(GIT_HASH)

configure_file(cmake/fud_config.hpp.in include/fud_config.hpp @ONLY)
add_dependencies(fud AlwaysCheckGit)