forked from progschj/ThreadPool
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
65 lines (50 loc) · 2.13 KB
/
CMakeLists.txt
File metadata and controls
65 lines (50 loc) · 2.13 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.21...3.25)
project(ThreadPool CXX)
include(GNUInstallDirs)
set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "Install location for cmake related files")
mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)
set(LIBRARY_TYPES "OBJECT;STATIC;SHARED")
set(THREADPOOL_LIBRARY_TYPE "STATIC" CACHE STRING "Choose the type of library to build, options are: ${LIBRARY_TYPES}.")
set_property(CACHE THREADPOOL_LIBRARY_TYPE PROPERTY STRINGS ${LIBRARY_TYPES})
if (NOT THREADPOOL_LIBRARY_TYPE IN_LIST LIBRARY_TYPES)
message(FATAL_ERROR "Invalid option: THREADPOOL_LIBRARY_TYPE=${THREADPOOL_LIBRARY_TYPE}. Supported options: ${LIBRARY_TYPES}.")
endif()
find_package(Threads REQUIRED)
set(PROJECT_DEPENDENCIES Threads)
add_library(ThreadPool ${THREADPOOL_LIBRARY_TYPE} ThreadPool.cpp ThreadPool.hpp )
target_link_libraries(ThreadPool PUBLIC Threads::Threads)
target_include_directories(ThreadPool
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(ThreadPool PUBLIC cxx_std_17)
enable_testing()
add_executable(example example.cpp)
target_link_libraries(example PRIVATE ThreadPool)
add_test(example example)
# Define public headers to get them automatically installed.
set_target_properties(ThreadPool PROPERTIES
PUBLIC_HEADER "ThreadPool.hpp")
set(THREADPOOL_EXPORT ThreadPoolTargets)
configure_file(
Config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake @ONLY
)
# Install the lib and its headers. Flag it for export.
install(
TARGETS ThreadPool
EXPORT ${THREADPOOL_EXPORT}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Create the export file for the build tree.
export(TARGETS ThreadPool FILE ${PROJECT_BINARY_DIR}/${THREADPOOL_EXPORT}.cmake)
# Create the export file for the install tree.
install(EXPORT ${THREADPOOL_EXPORT}
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)
install(
FILES #TODO ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)