Skip to content

Commit 809ae87

Browse files
committed
build(cmake): also fix linker flags and folder organization propagation
1 parent 495b2fd commit 809ae87

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cmake/modules/IDEOrganization.cmake

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,17 @@ function(organize_targets_by_source_dir)
121121
# Get all targets in the project
122122
set(ALL_TARGETS "")
123123
get_all_targets_recursive(ALL_TARGETS ${CMAKE_SOURCE_DIR})
124-
124+
125+
# Determine the base directory to use for path matching
126+
# When used as a subdirectory, use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR
127+
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
128+
# We are the root project
129+
set(BASE_SOURCE_DIR "${CMAKE_SOURCE_DIR}")
130+
else()
131+
# We are a subdirectory of another project
132+
set(BASE_SOURCE_DIR "${PROJECT_SOURCE_DIR}")
133+
endif()
134+
125135
# Organize targets in IDE folders
126136
foreach(target ${ALL_TARGETS})
127137
# Skip non-target entries
@@ -141,12 +151,12 @@ function(organize_targets_by_source_dir)
141151
if(TARGET_TYPE STREQUAL "UTILITY")
142152
continue() # Skip utility targets
143153
endif()
144-
154+
145155
# Standard organization based on source directory
146156
get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
147157
if(TARGET_SOURCE_DIR)
148-
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" REL_SOURCE_DIR "${TARGET_SOURCE_DIR}")
149-
158+
string(REPLACE "${BASE_SOURCE_DIR}/" "" REL_SOURCE_DIR "${TARGET_SOURCE_DIR}")
159+
150160
# Categorize targets
151161
if(REL_SOURCE_DIR MATCHES "^deps/first")
152162
set_target_properties(${target} PROPERTIES FOLDER "deps/first")

cmake/modules/Utilities.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ endfunction()
3838
# TARGET_COMPILE_DEFINITIONS - Compile definitions for each configuration
3939
#
4040
function(generate_build_configurations)
41+
# Determine if we're using a multi-config generator (Visual Studio, Xcode) or single-config (Ninja, Makefiles)
42+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
43+
4144
# These variables will be built up in _LOCAL variants and set in parent scope at the end
4245
set(TARGET_COMPILE_OPTIONS_LOCAL "")
4346
set(TARGET_LINK_OPTIONS_LOCAL "")
@@ -97,7 +100,10 @@ function(generate_build_configurations)
97100
# Append to existing flags to preserve CMake's defaults (including standard libraries)
98101
set(CMAKE_EXE_LINKER_FLAGS_${triplet_upper} "${CMAKE_EXE_LINKER_FLAGS_${triplet_upper}} ${exe_linker_flags}" CACHE STRING "" FORCE)
99102
set(CMAKE_SHARED_LINKER_FLAGS_${triplet_upper} "${CMAKE_SHARED_LINKER_FLAGS_${triplet_upper}} ${shared_linker_flags}" CACHE STRING "" FORCE)
100-
list(APPEND TARGET_LINK_OPTIONS_LOCAL "$<$<STREQUAL:$<CONFIG>,${triplet}>:${linker_flags}>")
103+
# Include default linker flags for propagation to external consumers
104+
# UE4SS is a SHARED library, so use DEFAULT_SHARED_LINKER_FLAGS (which is currently empty)
105+
# But also include DEFAULT_EXE_LINKER_FLAGS (/DEBUG:FULL) for completeness
106+
list(APPEND TARGET_LINK_OPTIONS_LOCAL "$<$<STREQUAL:$<CONFIG>,${triplet}>:${DEFAULT_EXE_LINKER_FLAGS};${linker_flags}>")
101107
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "${triplet}")
102108
# For single-config, append to base flags (don't use TARGET_LINK_OPTIONS to avoid duplication)
103109
# Preserve CMake's defaults including standard libraries

0 commit comments

Comments
 (0)