-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
68 lines (55 loc) · 2.15 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
cmake_minimum_required(VERSION 3.24)
project(fq C)
include(FetchContent)
enable_testing()
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/out")
include_directories("${CMAKE_SOURCE_DIR}/src")
set(BASE_SOURCE_FILES
src/freqlist.c
src/fq.c
src/util.c)
# Executable "fq"
add_executable(fq src/main.c
${BASE_SOURCE_FILES})
set(BASE_TEST_SOURCE_FILES
test/util_t.c)
FetchContent_Declare(
cheat_h
URL https://github.com/Tuplanolla/cheat/archive/refs/tags/1.0.4.tar.gz
URL_HASH MD5=30c3edd18d1f6d96e2da0c6682f260b7
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(cheat_h)
# Executable with unit tests "test_fq"
add_executable(test_fq test/test_fq.c
${BASE_TEST_SOURCE_FILES}
${BASE_SOURCE_FILES})
target_include_directories(test_fq PUBLIC "${cheat_h_SOURCE_DIR}")
# Install with `make install`
install(TARGETS fq
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/)
# To trigger dependencies before `make test`
set_property(DIRECTORY APPEND
PROPERTY TEST_INCLUDE_FILES
"${CMAKE_CURRENT_BINARY_DIR}/BuildTestTarget.cmake")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/BuildTestTarget.cmake"
"execute_process(COMMAND \"${CMAKE_COMMAND}\""
" --build \"${CMAKE_BINARY_DIR}\""
" --config \"\$ENV{CMAKE_CONFIG_TYPE}\")")
# Unit tests with `make test`
add_test(test_fq ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_fq)
# To clean everything: compiled binaries and *make* files
add_custom_target(clean-all
make clean && rm -fR ${CMAKE_BINARY_DIR}/CMakeCache.txt
${CMAKE_BINARY_DIR}/cmake_install.cmake
${CMAKE_BINARY_DIR}/Makefile
${CMAKE_BINARY_DIR}/CMakeFiles
${CMAKE_BINARY_DIR}/cmake-build-debug
${CMAKE_BINARY_DIR}/cmake-build-release
${CMAKE_BINARY_DIR}/install_manifest.txt
${CMAKE_BINARY_DIR}/Testing
${CMAKE_BINARY_DIR}/_deps
&& rmdir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)