Skip to content

Commit a3ca54d

Browse files
committed
Do not install headers if they are not desired.
Reason: When including the project with FetchContent into a cmake project the headers are just needed for building, so the headers are not needed to be installed. In this case ignore them
1 parent f4a8a81 commit a3ca54d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ include(CPack)
1414

1515
option(DEBUG "use debug flag" NO)
1616
option(ENABLE_TESTS "Enable Unittests" ON)
17+
# Turn OFF, if you are using FetchContent to include it to your project
18+
option(INSTALL_HEADERS "Install header files if the library is used as dependency" ON)
1719

1820
# defines variables used in the dbc.pc.in
1921
include(GNUInstallDirs)
@@ -92,13 +94,13 @@ install(TARGETS ${PROJECT_NAME}
9294
DESTINATION ${CMAKE_INSTALL_LIBDIR})
9395

9496
# install headers
95-
if (${CMAKE_MINOR_VERSION} GREATER_EQUAL 23)
97+
if (${CMAKE_MINOR_VERSION} GREATER_EQUAL 23 AND INSTALL_HEADERS)
9698
install(TARGETS ${PROJECT_NAME}
9799
FILE_SET HEADERS
98100
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lib${PROJECT_NAME}
99101
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
100102
)
101-
else()
103+
elseif(INSTALL_HEADERS)
102104
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/libdbc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
103105
endif()
104106

0 commit comments

Comments
 (0)