Skip to content

Commit

Permalink
Add supporting CMake FOLDER for header libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kachsheev committed Dec 24, 2024
1 parent b6d613c commit 52b4c39
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
6 changes: 4 additions & 2 deletions cmake/CmakeFlameResolver.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.19)

include(Macros)

Expand Down Expand Up @@ -27,7 +27,7 @@ include(Packaging)
# LOCAL_INSTALL -
# WARNINGS -
# WARNINGS_AS_ERRORS -
# SHOW_HEADERS -
# ENABLE_FOLDER -
# Code generation options:
# ONLY_POSITION_INDEPENDENT_OBJECTS -
# MAKE_STATIC -
Expand All @@ -50,6 +50,7 @@ include(Packaging)
function(flame_resolver_settings)
enable_internal_use()
internal_settings(${ARGN})
internal_switch_using_folder()
endfunction(flame_resolver_settings)

# Options:
Expand All @@ -58,6 +59,7 @@ endfunction(flame_resolver_settings)
# Values:
# NAME -
# LIBRARY_ALIAS_NAME -
# FOLDER -
# INSTALL_PATH -
# INSTALL_SUBDIR - directory name adding to prefix path
# Lists:
Expand Down
20 changes: 19 additions & 1 deletion cmake/Functions/CommonFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ macro(internal_settings)
"INSTALL"
"LOCAL_INSTALL"
"INPLACE_OBJECTS"
"SHOW_HEADERS"
"ENABLE_FOLDER"

# Code generation options
"ONLY_POSITION_INDEPENDENT_OBJECTS"
Expand Down Expand Up @@ -95,3 +95,21 @@ macro(internal_settings)
set(FLAME_${value} ${FLAME_${value}} PARENT_SCOPE)
endforeach()
endmacro()

#
#
#
function(internal_switch_using_folder)
check_internal_use()
if(FLAME_ENABLE_FOLDER)
get_property(USE_FOLDER GLOBAL PROPERTY USE_FOLDER)
if(NOT USE_FOLDER)
set_property(GLOBAL PROPERTY USE_FOLDER ON)
endif()
else()
get_property(USE_FOLDER GLOBAL PROPERTY USE_FOLDER)
if(USE_FOLDER)
set_property(GLOBAL PROPERTY USE_FOLDER OFF)
endif()
endif()
endfunction()
17 changes: 12 additions & 5 deletions cmake/Functions/HeaderLibraryFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function(internal_header_library)

# Parse arguments
set(OPTIONS "DEBUG")
set(VALUES "NAME" "LIBRARY_ALIAS_NAME" "INSTALL_PATH" "INSTALL_SUBDIR")
set(VALUES "NAME" "LIBRARY_ALIAS_NAME" "FOLDER" "INSTALL_PATH" "INSTALL_SUBDIR")
set(LISTS "DEPENDENCY_TARGET_LIST" "HEADER_LIST" "INCLUDE_PATHS")
cmake_parse_arguments("HEADER" "${OPTIONS}" "${VALUES}" "${LISTS}" "${ARGN}")

Expand Down Expand Up @@ -42,6 +42,9 @@ macro(internal_header_library_print_parse_result)
print_debug_function_oneline("HEADER_LIBRARY_ALIAS_NAME = ")
print_debug_value_newline(${HEADER_LIBRARY_ALIAS_NAME})

print_debug_function_oneline("HEADER_FOLDER = ")
print_debug_value_newline(${HEADER_FOLDER})

print_debug_function_oneline("HEADER_DEPENDENCY_TARGET_LIST = ")
print_debug_value_newline(${HEADER_DEPENDENCY_TARGET_LIST})

Expand All @@ -51,7 +54,7 @@ macro(internal_header_library_print_parse_result)
print_debug_function_oneline("HEADER_INSTALL_PATH = ")
print_debug_value_newline(${HEADER_INSTALL_PATH})

print_debug_function_oneline("HEADER_INSTALL_SUBDIR = ")
print_debug_function_oneline("HEADER_INSTALL_SUBDIR = ")
print_debug_value_newline(${HEADER_INSTALL_SUBDIR})

print_debug_function_newline("-------- PARSE RESULT --------")
Expand All @@ -61,6 +64,12 @@ macro(internal_header_library_print_parse_result)
else()
set(HEADER_DEBUG NO_DEBUG)
endif()
if (FLAME_ENABLE_FOLDER)
if (NOT HEADER_FOLDER)
set(HEADER_FOLDER "Header libraries")
endif()
set(HEADER_FOLDER_ARG "FOLDER;${HEADER_FOLDER}")
endif()
endmacro(internal_header_library_print_parse_result)

macro(internal_header_library_process_parameters)
Expand Down Expand Up @@ -109,11 +118,9 @@ macro(internal_header_library_add)
DEPENDENCY_HEADERS "${HEADER_DEPENDENCY_TARGET_LIST}"
LIBRARY_ALIASES "${HEADER_LIBRARY_ALIAS_NAME}"
INSTALL_PATH "${HEADER_INSTALL_PATH}"
${HEADER_FOLDER_ARG}
${HEADER_DEBUG}
)
if(FLAME_SHOW_HEADERS)
add_custom_target("${HEADER_NAME}" SOURCES ${HEADER_LIST})
endif()

unset(TARGET_CUSTOM_PROPERTIES)
unset(TARGET_NAME)
Expand Down
8 changes: 6 additions & 2 deletions cmake/Functions/ResolveFunctions/ResolveHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function(internal_resolve_headers)
print_oneline("-- Header library ${REAL_TARGET} - ")

get_target_property(HEADER_LIST ${target.property} FLAME_ADDING_FILES)
add_library(${REAL_TARGET} INTERFACE)
target_sources(${REAL_TARGET} INTERFACE "$<BUILD_INTERFACE:${HEADER_LIST}>")
add_library(${REAL_TARGET} INTERFACE ${HEADER_LIST})

get_target_property(INCLUDE_PATHS ${target.property} FLAME_INCLUDE_PATHS)
if(INCLUDE_PATHS)
Expand All @@ -33,6 +32,11 @@ function(internal_resolve_headers)
install(FILES ${HEADER_LIST} DESTINATION ${INSTALL_PATH})
endif()

get_target_property(FOLDER ${target.property} FLAME_FOLDER)
if(FLAME_ENABLE_FOLDER AND FOLDER)
set_target_properties(${REAL_TARGET} PROPERTIES FOLDER ${FOLDER})
endif()

print_newline("done")
endforeach()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(internal_add_header_target_properties)
check_internal_use()

set(OPTIONS "DEBUG" "NO_DEBUG")
set(VALUES "PROPERTY_CONTAINER_NAME" "REAL_TARGET" "INSTALL_PATH")
set(VALUES "PROPERTY_CONTAINER_NAME" "REAL_TARGET" "FOLDER" "INSTALL_PATH")
set(LISTS "ADDING_FILES" "INCLUDE_PATHS" "DEPENDENCY_HEADERS" "LIBRARY_ALIASES")

cmake_parse_arguments("FLAME" "${OPTIONS}" "${VALUES}" "${LISTS}" "${ARGN}")
Expand Down Expand Up @@ -45,6 +45,9 @@ function(internal_add_header_target_properties)
print_debug_function_oneline("FLAME_LIBRARY_ALIASES = ")
print_debug_value_newline(${FLAME_LIBRARY_ALIASES})

print_debug_function_oneline("FLAME_FOLDER = ")
print_debug_value_newline(${FLAME_FOLDER})

print_debug_function_oneline("FLAME_INSTALL_PATH = ")
print_debug_value_newline(${FLAME_INSTALL_PATH})

Expand All @@ -62,8 +65,15 @@ function(internal_add_header_target_properties)
FLAME_DEFINES "${FLAME_DEFINES}"
FLAME_DEPENDENCY_HEADERS "${FLAME_DEPENDENCY_HEADERS}"
FLAME_LIBRARY_ALIASES "${FLAME_LIBRARY_ALIASES}"
FLAME_FOLDER "${FLAME_FOLDER}"
FLAME_INSTALL_PATH "${FLAME_INSTALL_PATH}"
)
if(FLAME_ENABLE_FOLDER)
set_property(TARGET ${FLAME_PROPERTY_CONTAINER_NAME}
PROPERTY
FOLDER "${FLAME_PROPERTY_CONTAINERS_FOLDER}"
)
endif()

end_debug_function()
endfunction(internal_add_header_target_properties)
6 changes: 3 additions & 3 deletions cmake/Options/CommonOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ option(FLAME_INPLACE_OBJECTS
OFF
)

option(FLAME_SHOW_HEADERS
"Show header files"
ON
option(FLAME_ENABLE_FOLDER
"Enable CMake folder"
OFF
)
2 changes: 2 additions & 0 deletions cmake/Variables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ if (FLAME_CONAN_SUPPORT)
endif()

set(FLAME_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR}/include/CmakeFlameResolver)

set(FLAME_PROPERTY_CONTAINERS_FOLDER "Property containers" CACHE STRING "" FORCE)

0 comments on commit 52b4c39

Please sign in to comment.