Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
65 lines (53 loc) · 1.88 KB
/
Copy pathCMakeLists.txt
File metadata and controls
65 lines (53 loc) · 1.88 KB
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
cmake_minimum_required(VERSION 3.23)
get_filename_component(lib_name ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${lib_name}
LANGUAGES CXX
VERSION 2.3.1
DESCRIPTION "25 SLOC Strings in switch"
HOMEPAGE_URL "https://github.com/viraltaco/h"
)
# Global Settings
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
# Common flags for all targets
set(COPTS -Wall -Wextra -Wpedantic -Wunreachable-code -Wredundant-decls)
set(OPTIMIZED_COPTS ${COPTS} -O3 -march=native)
# 1. Target: tests
add_subdirectory(tests)
add_subdirectory(bench)
# 2. Target: compile and run options.cxx
add_executable(options_bin examples/options.cxx lib/h.h)
set_target_properties(options_bin PROPERTIES OUTPUT_NAME options)
add_custom_target(run-options
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/options "--version"
DEPENDS options_bin
COMMENT "Building and running options.cxx with argument --version"
)
# 2bis. Target: compile and run hashmap.cxx
add_executable(hashmap_bin examples/hashmap.cxx lib/h.h)
set_target_properties(hashmap_bin PROPERTIES OUTPUT_NAME hashmap)
add_custom_target(run-hashmap
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/hashmap
DEPENDS hashmap_bin
COMMENT "Building and running hashmap.cxx"
)
# 3. Target: run tests, then compile, optimized as a dynamic library
# Target to run the tests
add_custom_target(run-tests
COMMAND tests
DEPENDS tests
COMMENT "Running tests..."
)
# Optimized Dynamic Library
# We include lib/h.cxx to provide a translation unit for the shared library.
add_library(h_shared SHARED lib/h.cxx lib/h.h)
# Force test execution before library compilation
add_dependencies(h_shared run-tests)
# Apply optimization flags
target_compile_options(h_shared PRIVATE ${OPTIMIZED_COPTS})
set_target_properties(h_shared PROPERTIES
OUTPUT_NAME h
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)