Skip to content

Commit

Permalink
fix: avoiding double nested include directories for PUBLIC_INCLUDES
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 13, 2022
1 parent 7b4bd41 commit 8893c6b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Checks: "*,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes,
-misc-definitions-in-headers,
"
WarningsAsErrors: ''
HeaderFilterRegex: ''
Expand Down
15 changes: 13 additions & 2 deletions src/PackageProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ function(package_project)
STREQUAL
"")
foreach(_INC ${_PackageProject_PUBLIC_INCLUDES})
# make include absolute
if(NOT IS_ABSOLUTE ${_INC})
set(_INC "${CMAKE_CURRENT_SOURCE_DIR}/${_INC}")
endif()
# install include
if(IS_DIRECTORY ${_INC})
install(DIRECTORY ${_INC} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})

# strip double include directories
if("${CMAKE_INSTALL_INCLUDEDIR}" STREQUAL "include" AND "${_INC}" MATCHES ".*[/\\]include[/\\]?")
message(STATUS "package_project: avoiding double nested `include` directories for PUBLIC_INCLUDES")
set(_CMAKE_INSTALL_INCLUDEDIR "")
else()
set(_CMAKE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
endif()

install(DIRECTORY ${_INC} DESTINATION ${CMAKE_INSTALL_PREFIX}/${_CMAKE_INSTALL_INCLUDEDIR})
else()
install(FILES ${_INC} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${_INC} DESTINATION ${CMAKE_INSTALL_PREFIX}/${_CMAKE_INSTALL_INCLUDEDIR})
endif()
endforeach()
endif()
Expand Down
2 changes: 2 additions & 0 deletions test/include/mylib/lib.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

// test external pac
#include <Eigen/Dense>
#include <fmt/core.h>
Expand Down

0 comments on commit 8893c6b

Please sign in to comment.