summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: bfe3ba01f68ae416c69e307d73dd399eda208ebf (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
# NB: ≥3.8 required for C++17
cmake_minimum_required(VERSION 3.8...3.31)
project(pom)

option(LIBPOM_CXX "Build C++ library" ON)
option(LIBPOM_EXAMPLES "Build examples" ON)
option(LIBPOM_TESTS "Build tests" ON)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (MSVC)
    add_compile_options(/W4)
else()
    add_compile_options(-Wall -Wextra -Wpedantic -Wshadow)
endif()


add_library(pom STATIC pom.c)
add_library(pom-shared SHARED pom.c)
set_target_properties(pom-shared PROPERTIES OUTPUT_NAME pom)

# Tests
if (LIBPOM_TESTS)
    add_executable(tests tests/errors.c tests/location.c tests/parsing.c tests/interpretation.c tests/main.c)
    target_include_directories(tests PRIVATE .)
    target_link_libraries(tests pom)
endif()

# Examples
if (LIBPOM_EXAMPLES)
    add_executable(example_read_conf examples/read_conf.c)
    target_include_directories(example_read_conf PRIVATE .)
    target_link_libraries(example_read_conf pom)
    add_executable(example_custom_alloc examples/custom_alloc.c)
    target_include_directories(example_custom_alloc PRIVATE .)
    target_link_libraries(example_custom_alloc pom)
    add_executable(example_all_functions examples/all_functions.c)
    target_include_directories(example_all_functions PRIVATE .)
    target_link_libraries(example_all_functions pom)
endif()

# Installation
install(TARGETS pom pom-shared DESTINATION lib)
install(FILES pom.h DESTINATION include)

if (LIBPOM_CXX)

    # C++ library
    add_library(pom++ STATIC cpp/pom.cpp)
    add_library(pom++-shared SHARED cpp/pom.cpp)
    set_target_properties(pom++-shared PROPERTIES OUTPUT_NAME pom++)
    target_include_directories(pom++ PRIVATE .)
    target_include_directories(pom++-shared PRIVATE .)
    target_link_libraries(pom++ PRIVATE pom)
    target_link_libraries(pom++-shared PRIVATE pom-shared)

    # C++ Examples
    if (LIBPOM_EXAMPLES)
        add_executable(example++_read_conf cpp/examples/read_conf.cpp)
        target_include_directories(example++_read_conf PRIVATE cpp)
        target_link_libraries(example++_read_conf pom++)
        add_executable(example++_all_functions cpp/examples/all_functions.cpp)
        target_include_directories(example++_all_functions PRIVATE cpp)
        target_link_libraries(example++_all_functions pom++)
    endif()

    # Installation
    install(TARGETS pom++ pom++-shared DESTINATION lib)
    install(FILES cpp/pom.hpp DESTINATION include)

endif()