Bladeren bron

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).
Itamar 3 jaren geleden
bovenliggende
commit
3b5eeb7fdd
1 gewijzigde bestanden met toevoegingen van 6 en 4 verwijderingen
  1. 6 4
      Meta/CMake/utils.cmake

+ 6 - 4
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)