mirror of
				https://github.com/XRPLF/rippled.git
				synced 2025-11-04 11:15:56 +00:00 
			
		
		
		
	Adds two CMake functions:
* add_module(library subdirectory): Declares an OBJECT "library" (a CMake abstraction for a collection of object files) with sources from the given subdirectory of the given library, representing a module. Isolates the module's headers by creating a subdirectory in the build directory, e.g. .build/tmp123, that contains just a symlink, e.g. .build/tmp123/basics, to the module's header directory, e.g. include/xrpl/basics, in the source directory, and putting .build/tmp123 (but not include/xrpl) on the include path of the module sources. This prevents the module sources from including headers not explicitly linked to the module in CMake with target_link_libraries.
* target_link_modules(library scope modules...): Links the library target to each of the module targets, and removes their sources from its source list (so they are not compiled and linked twice).
Uses these functions to separate and explicitly link modules in libxrpl:
    Level 01: beast
    Level 02: basics
    Level 03: json, crypto
    Level 04: protocol
    Level 05: resource, server
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			717 B
		
	
	
	
		
			CMake
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			717 B
		
	
	
	
		
			CMake
		
	
	
	
	
	
# file(CREATE_SYMLINK) only works on Windows with administrator privileges.
 | 
						|
# https://stackoverflow.com/a/61244115/618906
 | 
						|
function(create_symbolic_link target link)
 | 
						|
  if(WIN32)
 | 
						|
    if(NOT IS_SYMLINK "${link}")
 | 
						|
      if(NOT IS_ABSOLUTE "${target}")
 | 
						|
        # Relative links work do not work on Windows.
 | 
						|
        set(target "${link}/../${target}")
 | 
						|
      endif()
 | 
						|
      file(TO_NATIVE_PATH "${target}" target)
 | 
						|
      file(TO_NATIVE_PATH "${link}" link)
 | 
						|
      execute_process(COMMAND cmd.exe /c mklink /J "${link}" "${target}")
 | 
						|
    endif()
 | 
						|
  else()
 | 
						|
    file(CREATE_LINK "${target}" "${link}" SYMBOLIC)
 | 
						|
  endif()
 | 
						|
  if(NOT IS_SYMLINK "${link}")
 | 
						|
    message(ERROR "failed to create symlink: <${link}>")
 | 
						|
  endif()
 | 
						|
endfunction()
 |