-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
150 lines (140 loc) Β· 3.79 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
143
144
145
146
147
148
149
150
cmake_minimum_required(VERSION 3.29)
# Project declaration
project(
platformdirs
VERSION 0.1.0
DESCRIPTION "π Python's platformdirs module for C++"
HOMEPAGE_URL "https://jcbhmr.me/platformdirs"
LANGUAGES CXX)
# Library targets
add_library(platformdirs)
add_library(platformdirs::platformdirs ALIAS platformdirs)
target_sources(
platformdirs
PRIVATE src/platformdirs.cpp
src/platformdirs/api.cpp
src/platformdirs/macos.cpp
src/platformdirs/unix.cpp
src/platformdirs/utils.cpp
src/platformdirs/version.cpp
src/platformdirs/windows.cpp)
target_include_directories(platformdirs PUBLIC include)
target_compile_features(platformdirs PRIVATE cxx_std_23)
# cosmocc has exceptions off by default
target_compile_options(platformdirs PRIVATE -fexceptions)
target_compile_definitions(platformdirs PRIVATE
PROJECT_VERSION="${PROJECT_VERSION}"
PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
PROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}
PROJECT_VERSION_TWEAK=${PROJECT_VERSION_TWEAK})
# Binary targets
add_executable(platformdirs_exe)
add_executable(platformdirs::platformdirs_exe ALIAS platformdirs_exe)
set_property(TARGET platformdirs_exe PROPERTY OUTPUT_NAME platformdirs)
target_sources(platformdirs_exe PRIVATE src/platformdirs_exe.cpp)
target_compile_features(platformdirs_exe PRIVATE cxx_std_23)
# cosmocc has exceptions off by default
target_compile_options(platformdirs_exe PRIVATE -fexceptions)
target_link_libraries(platformdirs_exe PRIVATE platformdirs)
target_compile_definitions(platformdirs_exe PRIVATE
PROJECT_VERSION="${PROJECT_VERSION}"
PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
PROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}
PROJECT_VERSION_TWEAK=${PROJECT_VERSION_TWEAK})
# Testing
include(CTest)
if(BUILD_TESTING)
add_test(NAME platformdirs COMMAND platformdirs_exe)
endif()
# Installation
include(GNUInstallDirs)
install(TARGETS platformdirs_exe)
# Packaging
if(WIN32)
set(CPACK_GENERATOR ZIP)
else()
set(CPACK_GENERATOR TGZ)
endif()
include(CPack)
# Tasks
if(BUILD_TESTING AND CMAKE_SOURCE_DIR STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
file(
GLOB_RECURSE
c_cxx_files
src/*.c
src/*.cpp
src/*.cc
src/*.cxx
src/*.h
src/*.hxx
src/*.hh
src/*.hpp
include/*.h
include/*.hxx
include/*.hh
include/*.hpp
test/*.c
test/*.cpp
test/*.cc
test/*.cxx
test/*.h
test/*.hxx
test/*.hh
test/*.hpp
examples/*.c
examples/*.cpp
examples/*.cc
examples/*.cxx
examples/*.h
examples/*.hxx
examples/*.hh
examples/*.hpp)
file(
GLOB_RECURSE
cmake_files
cmake/*.cmake
src/*CMakeLists.txt
src/*.cmake
test/*CMakeLists.txt
test/*.cmake)
list(APPEND cmake_files CMakeLists.txt)
add_custom_target(
format
COMMAND clang-format -i ${c_cxx_files}
COMMAND cmake-format -i ${cmake_files}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
USES_TERMINAL)
file(
GLOB_RECURSE
all_files
.github/*
cmake/*
src/*
examples/*
test/*
docs/*)
list(
APPEND
all_files
.gitignore
CMakeLists.txt
CMakePresets.json
README.md
task.cmake)
add_custom_target(
lint
COMMAND codespell -w ${all_files}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
USES_TERMINAL)
find_package(Doxygen)
if(Doxygen_FOUND)
set(DOXYGEN_EXCLUDE "${CMAKE_BINARY_DIR}")
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
doxygen_add_docs(docs "${PROJECT_SOURCE_DIR}")
add_custom_target(preview COMMAND python -m http.server WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" USES_TERMINAL)
add_dependencies(preview docs)
endif()
endif()