-
Notifications
You must be signed in to change notification settings - Fork 515
/
CMakeLists.txt
66 lines (57 loc) · 2.23 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
cmake_minimum_required(VERSION 3.5)
project(dirent LANGUAGES C CXX)
# User options
option(DIRENT_BUILD_TESTS "Build bundled tests" ON)
message(STATUS "Build test and example programs: ${DIRENT_BUILD_TESTS}")
# Initialize C and C++ compilers
enable_language(C CXX)
# Compile in debug mode by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug
CACHE STRING
"Type of build: None Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
endif(NOT CMAKE_BUILD_TYPE)
# Use the include directory only on Windows
if(WIN32)
include_directories(${CMAKE_SOURCE_DIR}/include)
endif(WIN32)
# Install dirent.h
if(WIN32)
install(FILES include/dirent.h DESTINATION include)
endif(WIN32)
# Add distclean target
add_custom_target(distclean
COMMAND ${CMAKE_BUILD_TOOL} clean
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/distclean.cmake
)
# Build example programs
if(DIRENT_BUILD_TESTS)
add_executable(find examples/find.c)
add_executable(ls examples/ls.c)
add_executable(locate examples/locate.c)
add_executable(updatedb examples/updatedb.c)
add_executable(scandir examples/scandir.c)
add_executable(cat examples/cat.c)
add_executable(dir examples/dir.c)
add_executable(du examples/du.c)
# Build test programs
include(CTest)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C ${CMAKE_CFG_INTDIR})
function(add_test_executable TEST_NAME)
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
add_test(NAME ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND $<TARGET_FILE:${TEST_NAME}>)
add_dependencies(check ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY SKIP_RETURN_CODE 77)
endfunction(add_test_executable)
add_test_executable(t-compile tests/t-compile.c)
add_test_executable(t-dirent tests/t-dirent.c)
add_test_executable(t-scandir tests/t-scandir.c)
add_test_executable(t-unicode tests/t-unicode.c)
add_test_executable(t-cplusplus tests/t-cplusplus.cpp)
add_test_executable(t-telldir tests/t-telldir.c)
add_test_executable(t-strverscmp tests/t-strverscmp.c)
add_test_executable(t-utf8 tests/t-utf8.c)
add_test_executable(t-symlink tests/t-symlink.c)
endif(DIRENT_BUILD_TESTS)