Skip to content

Commit

Permalink
Make corrosion_install support include directories
Browse files Browse the repository at this point in the history
Supports directories added with `target_include_directories` like
normal.

There is a slight oddity.
Because of how install(DIRECTORY) works, we can't put the include
directory inside `${CMAKE_INSTALL_PREFIX}/include`, since that would
create `${CMAKE_INSTALL_PREFIX}/include/<include dir name>`.
Instead we copy directly to the CMAKE_INSTALL_PREFIX, and then use
whatever name the include directory had (hopefully just `include`).

This means that when installing the path to include files will be

-- Installing: /tmp/install/./include
-- Installing: /tmp/install/./include/is_odd
-- Installing: /tmp/install/./include/is_odd/is_odd.h

Instead of just

-- Installing: /tmp/install/include
-- Installing: /tmp/install/include/is_odd
-- Installing: /tmp/install/include/is_odd/is_odd.h
  • Loading branch information
Gtker committed Aug 3, 2024
1 parent 9f7c08e commit f9290de
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,41 @@ function(corrosion_install)
)
endif()
endif()

# Executables can also have export tables, so they _might_ also need header files
if (DEFINED COR_INSTALL_PUBLIC_HEADER_PERMISSIONS)
set(PERMISSIONS ${COR_INSTALL_PUBLIC_HEADER_PERMISSIONS})
elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
else()
# Directories need OWNER_EXECUTE in order to be deletable by owner
set(PERMISSIONS ${DEFAULT_PERMISSIONS} OWNER_EXECUTE)
endif()

if (DEFINED COR_INSTALL_PUBLIC_HEADER_CONFIGURATIONS)
set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_PUBLIC_HEADER_CONFIGURATIONS})
elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
else()
set(CONFIGURATIONS)
endif()

set(PUBLIC_HEADER_PROPERTIES INCLUDE_DIRECTORIES PUBLIC_INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES)
foreach(PUBLIC_HEADER_PROPERTY ${PUBLIC_HEADER_PROPERTIES})
get_target_property(PUBLIC_HEADER ${INSTALL_TARGET} ${PUBLIC_HEADER_PROPERTY})

if(NOT PUBLIC_HEADER MATCHES .*-NOTFOUND)
foreach(INCLUDE_DIRECTORY ${PUBLIC_HEADER})
install(
DIRECTORY ${INCLUDE_DIRECTORY}
DESTINATION .
FILE_PERMISSIONS ${PERMISSIONS}
DIRECTORY_PERMISSIONS ${PERMISSIONS}
${CONFIGURATIONS}
)
endforeach()
endif()
endforeach()
endforeach()

elseif(INSTALL_TYPE STREQUAL "EXPORT")
Expand Down

0 comments on commit f9290de

Please sign in to comment.