Created
January 20, 2022 01:37
-
-
Save GaussianWonder/afaa0640f74973a3c054110dc35e9ae3 to your computer and use it in GitHub Desktop.
Macro to auto include all directories that contain headers. Useful when no naming conflicts exist. Benefit of not specifying relative paths to your own headers. This can easily be integrated with conan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Search all directories that contain headers | |
macro(HEADER_DIRECTORIES return_list) | |
file(GLOB_RECURSE new_list *.h) | |
set(dir_list "") | |
foreach(file_path ${new_list}) | |
get_filename_component(dir_path ${file_path} PATH) | |
set(dir_list ${dir_list} ${dir_path}) | |
endforeach() | |
list(REMOVE_DUPLICATES dir_list) | |
set(${return_list} ${dir_list}) | |
endmacro() | |
# Get all header dirs to include | |
header_directories(header_dir_list) | |
list(LENGTH header_dir_list header_dir_list_count) | |
message(STATUS "[INFO] Found ${header_dir_list_count} header directories.") | |
target_include_directories( | |
${PROJECT_NAME} | |
PUBLIC | |
${header_dir_list} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment