-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
80 lines (64 loc) · 2.43 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
cmake_minimum_required(VERSION 3.23)
project(sockcanpp LANGUAGES CXX VERSION 1.1.0)
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
option(BUILD_TESTS "Build the tests" OFF)
set(CMAKE_CXX_STANDARD 11)
include(GNUInstallDirs)
if (BUILD_SHARED_LIBS STREQUAL "ON")
add_library(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
else()
add_library(${PROJECT_NAME} STATIC)
endif()
###
# If BUILD_TESTS is set to ON, a static test library with the name of the project suffixed with "_test" will be created
###
if(BUILD_TESTS STREQUAL "ON")
add_library(${PROJECT_NAME}_test STATIC)
endif()
add_subdirectory(include)
add_subdirectory(src)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
FILE_SET HEADERS
)
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"lib${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES "cmake/lib${PROJECT_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
configure_file(libsockcanpp.pc.in ${CMAKE_BINARY_DIR}/libsockcanpp.pc @ONLY)
# Install pkg-config files
install(FILES ${CMAKE_BINARY_DIR}/libsockcanpp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
include(cmake/cpack.cmake)
###
# Docs target
###
add_custom_target("docs" COMMENT "Create Doxygen documentation")
add_custom_command(
TARGET "docs"
POST_BUILD
COMMENT "Generate Doxygen documentation for publication or reading"
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
###
# If the CMAKE_BUILD_TYPE is set to Debug, enable the tests
###
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND BUILD_TESTS STREQUAL "ON")
enable_testing()
add_subdirectory(test)
endif()