forked from goToMain/c-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
42 lines (37 loc) · 1.46 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
#
# Copyright (c) 2020 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(utils VERSION 0.1.0 LANGUAGES C)
# libutils.a
set(LIB_UTILS utils)
file(GLOB LIB_UTILS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
file(GLOB LIB_UTILS_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/utils/*.h)
add_library(${LIB_UTILS} STATIC ${LIB_UTILS_SRC} ${LIB_UTILS_INC})
target_include_directories(${LIB_UTILS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(${LIB_UTILS} PROPERTIES PUBLIC_HEADER "${LIB_UTILS_INC}")
# check target
set(TEST_BIN test-utils)
file(GLOB TEST_SRC
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.h
)
add_executable(${TEST_BIN} ${TEST_SRC})
target_link_libraries(${TEST_BIN} ${LIB_UTILS})
target_include_directories(${TEST_BIN} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(${TEST_BIN} PROPERTIES EXCLUDE_FROM_ALL TRUE)
function(download_file URL FILE_PATH)
message("Downloading ${FILE_PATH}..")
file(DOWNLOAD ${URL} ${FILE_PATH} STATUS DOWNLOAD_RESULT)
list(GET DOWNLOAD_RESULT 0 DOWNLOAD_RESULT_CODE)
if(NOT DOWNLOAD_RESULT_CODE EQUAL 0)
message(FATAL_ERROR "Failed downloading ${URL}! Error: ${DOWNLOAD_RESULT}.")
endif()
endfunction()
add_custom_target(check_utils
COMMAND ${CMAKE_BINARY_DIR}/${TEST_BIN} -i"${CMAKE_CURRENT_SOURCE_DIR}/tests/input"
COMMAND rm ${CMAKE_BINARY_DIR}/${TEST_BIN}
DEPENDS ${TEST_BIN}
)