From 3b5eeb7fddda8d26a983a85c2fc29a0c40f866e5 Mon Sep 17 00:00:00 2001 From: Itamar Date: Fri, 26 Nov 2021 15:53:46 +0200 Subject: [PATCH] CMake: Simplify serenity_install_sources by inferring installation path The serenity_install_sources function now infers the path under `/usr/src/serenity` in which to install the source files according to the relative path of the source files in the repository. For example `Userland/Libraries/LibGUI/Widget.h` gets installed at `/usr/src/serenity/Userland/Libraries/LibGUI/Widget.h`. This fixes cases where the source files of libraries are not under `Userland/Libraries` (for example LibShell & LibLanguageServer). --- Meta/CMake/utils.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake index e139d69d14..27556f0e7a 100644 --- a/Meta/CMake/utils.cmake +++ b/Meta/CMake/utils.cmake @@ -10,11 +10,13 @@ function(serenity_install_headers target_name) endforeach() endfunction() -function(serenity_install_sources target_name) +function(serenity_install_sources) + string(LENGTH ${SerenityOS_SOURCE_DIR} root_source_dir_length) + string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${root_source_dir_length} -1 current_source_dir_relative) file(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.cpp") foreach(source ${sources}) get_filename_component(subdirectory ${source} DIRECTORY) - install(FILES ${source} DESTINATION usr/src/serenity/${target_name}/${subdirectory} OPTIONAL) + install(FILES ${source} DESTINATION usr/src/serenity/${current_source_dir_relative}/${subdirectory} OPTIONAL) endforeach() endfunction() @@ -31,7 +33,7 @@ endfunction() function(serenity_lib target_name fs_name) serenity_install_headers(${target_name}) - serenity_install_sources("Userland/Libraries/${target_name}") + serenity_install_sources() add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES}) set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE) set_target_properties(${target_name} PROPERTIES VERSION "serenity") @@ -42,7 +44,7 @@ endfunction() function(serenity_libc target_name fs_name) serenity_install_headers("") - serenity_install_sources("Userland/Libraries/LibC") + serenity_install_sources() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic") add_library(${target_name} SHARED ${SOURCES}) install(TARGETS ${target_name} DESTINATION usr/lib)