-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
142 lines (120 loc) · 6.61 KB
/
CMakeLists.txt
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
136
137
138
139
140
141
142
# Copyright (c) 2023 Giopler
# Creative Commons Attribution No Derivatives 4.0 International license
# https://creativecommons.org/licenses/by-nd/4.0
# SPDX-License-Identifier: CC-BY-ND-4.0
#
# Share — copy and redistribute the material in any medium or format for any purpose, even commercially.
# NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material.
# Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made.
# You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
# Our target system is the current long-term support version of Ubuntu (22.04).
# Ubuntu 22.04LTS includes CMake 3.22, CLang 14.0, Gcc 11.2, and OpenSSL 3.0.
# Versions of CMake supported by CLion 2022.1.3 are 2.8.11 to 3.22.x.
cmake_minimum_required(VERSION 3.22)
# set defaults for all targets
set(CMAKE_CXX_STANDARD 20) # set C++20 as the default
set(CMAKE_CXX_STANDARD_REQUIRED ON) # require C++20
set(CMAKE_CXX_EXTENSIONS OFF) # turn off GNU compiler extensions
project(Giopler-Cpp
VERSION 0.2.0
DESCRIPTION "A profiling, logging, and testing library for C++20"
HOMEPAGE_URL "https://github.com/giopler/giopler-cpp"
LANGUAGES CXX)
include(CTest)
# ------------------------------------------------------------------------------
# https://cmake.org/cmake/help/latest/module/FindThreads.html
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(NOT Threads_FOUND)
message(ERROR A threading library is required.)
endif()
# ------------------------------------------------------------------------------
# https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL)
if(NOT OpenSSL_FOUND)
message(ERROR OpenSSL library is required.)
endif()
# ------------------------------------------------------------------------------
# https://cmake.org/cmake/help/latest/module/FindZLIB.html
find_package(ZLIB REQUIRED)
if(NOT ZLIB_FOUND)
message(ERROR zlib compression library is required.)
endif()
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Giopler is a header-only library
# http://mariobadr.com/creating-a-header-only-library-with-cmake.html
# https://dominikberner.ch/cmake-interface-lib/
# https://www.cppengineer.com/blog/using-cmake-to-create-header-only-shared-and-static-libraries
# Usage: target_link_libraries(your_app_or_lib PRIVATE ${GIOPLER_LIBRARIES})
add_library(giopler INTERFACE)
target_include_directories(giopler INTERFACE
${OPENSSL_INCLUDE_DIR}
${ZLIB_INCLUDE_DIRS}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(giopler INTERFACE
Threads::Threads
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARIES}
)
# ------------------------------------------------------------------------------
add_executable(simple "${CMAKE_CURRENT_SOURCE_DIR}/sample/simple.cpp")
target_compile_options(simple PRIVATE -Werror -Wall)
target_link_libraries(simple PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(hello "${CMAKE_CURRENT_SOURCE_DIR}/sample/hello.cpp")
target_compile_options(hello PRIVATE -Werror -Wall)
target_link_libraries(hello PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(there "${CMAKE_CURRENT_SOURCE_DIR}/sample/there.cpp")
target_compile_options(there PRIVATE -Werror -Wall)
target_link_libraries(there PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(threads "${CMAKE_CURRENT_SOURCE_DIR}/sample/threads.cpp")
target_compile_options(threads PRIVATE -Werror -Wall)
target_link_libraries(threads PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(factorial "${CMAKE_CURRENT_SOURCE_DIR}/sample/factorial.cpp")
target_compile_options(factorial PRIVATE -Werror -Wall)
target_link_libraries(factorial PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(ackermann "${CMAKE_CURRENT_SOURCE_DIR}/sample/ackermann.cpp")
target_compile_options(ackermann PRIVATE -Werror -Wall)
target_link_libraries(ackermann PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(fibonacci "${CMAKE_CURRENT_SOURCE_DIR}/sample/fibonacci.cpp")
target_compile_options(fibonacci PRIVATE -Werror -Wall)
target_link_libraries(fibonacci PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(collatz "${CMAKE_CURRENT_SOURCE_DIR}/sample/collatz.cpp")
target_compile_options(collatz PRIVATE -Werror -Wall)
target_link_libraries(collatz PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(matrices "${CMAKE_CURRENT_SOURCE_DIR}/sample/matrices.cpp")
target_compile_options(matrices PRIVATE -Werror -Wall)
target_link_libraries(matrices PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(funnel_sort "${CMAKE_CURRENT_SOURCE_DIR}/sample/funnel_sort.cpp")
target_compile_options(funnel_sort PRIVATE -Werror -Wall)
target_link_libraries(funnel_sort PRIVATE giopler m)
# ------------------------------------------------------------------------------
add_executable(benchmark "${CMAKE_CURRENT_SOURCE_DIR}/sample/benchmark.cpp")
target_compile_options(benchmark PRIVATE -Werror -Wall)
target_link_libraries(benchmark PRIVATE giopler m)
# ------------------------------------------------------------------------------
# only one of these can be defined at a time
# the compiler build (Debug, Release, etc) should also be changed in lock-step
# For example, use Debug for GIOPLER_BUILD_MODE_DEV
#add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_OFF=1)
#add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_DEV=1)
#add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_TEST=1)
#add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_BENCH=1)
#add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_QA=1)
add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_PROF=1)
#add_compile_definitions(PRIVATE GIOPLER_BUILD_MODE_PROD=1)
# ------------------------------------------------------------------------------
if(BUILD_TESTING)
add_test(NAME ackermann_ackermann4_1 COMMAND giopler_test ackermann ackermann4_1)
endif()