Skip to content

Commit 698c97c

Browse files
authored
Merge pull request #1061 from UE4SS-RE/cmakepropagation
Improves CMake configuration and propagation
2 parents ad867f0 + f881d4c commit 698c97c

File tree

7 files changed

+92
-37
lines changed

7 files changed

+92
-37
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/${CMAKE_INSTALL
5959
add_subdirectory("cmake/modules/CompilerOptions")
6060

6161
# Set compiler options
62-
add_compile_options("$<$<NOT:$<COMPILE_LANGUAGE:ASM_MASM>>:${DEFAULT_COMPILER_FLAGS}>")
63-
add_link_options("${DEFAULT_SHARED_LINKER_FLAGS}" "${DEFAULT_EXE_LINKER_FLAGS}")
62+
# NOTE: Do NOT use add_compile_options/add_link_options here as they won't propagate to external consumers
63+
# Instead, these are applied via apply_compiler_settings_to_targets() which uses target_*_options with PUBLIC
64+
# visibility on the UE4SS target, ensuring proper propagation to downstream projects
65+
# add_compile_options("$<$<NOT:$<COMPILE_LANGUAGE:ASM_MASM>>:${DEFAULT_COMPILER_FLAGS}>")
66+
# add_link_options("${DEFAULT_SHARED_LINKER_FLAGS}" "${DEFAULT_EXE_LINKER_FLAGS}")
6467
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6568

6669
# Initialize Compiler flags after compiler detection.

UE4SS/CMakeLists.txt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ else()
4545
set(UE4SS_LIB_BUILD_GITSHA "no-git")
4646
endif()
4747

48-
# Add version definitions
49-
add_compile_definitions(
50-
UE4SS_LIB_VERSION_MAJOR=${UE4SS_LIB_VERSION_MAJOR}
51-
UE4SS_LIB_VERSION_MINOR=${UE4SS_LIB_VERSION_MINOR}
52-
UE4SS_LIB_VERSION_HOTFIX=${UE4SS_LIB_VERSION_HOTFIX}
53-
UE4SS_LIB_VERSION_PRERELEASE=${UE4SS_LIB_VERSION_PRERELEASE}
54-
UE4SS_LIB_VERSION_BETA=${UE4SS_LIB_VERSION_BETA}
55-
UE4SS_LIB_BETA_STARTED=$<BOOL:${UE4SS_LIB_BETA_IS_STARTED}>
56-
UE4SS_LIB_IS_BETA=$<BOOL:${UE4SS_LIB_IS_BETA}>
57-
UE4SS_LIB_BUILD_GITSHA="${UE4SS_LIB_BUILD_GITSHA}"
58-
UE4SS_CONFIGURATION="$<CONFIG>"
59-
)
60-
6148
message("UE4SS Version: ${UE4SS_LIB_VERSION_MAJOR}.${UE4SS_LIB_VERSION_MINOR}.${UE4SS_LIB_VERSION_HOTFIX}.${UE4SS_LIB_VERSION_PRERELEASE}.${UE4SS_LIB_VERSION_BETA} (${UE4SS_LIB_BUILD_GITSHA})")
6249

6350
# ---------------------------------------------------------------------------
@@ -75,11 +62,24 @@ add_library(UE4SS SHARED ${UE4SS_SOURCES})
7562
target_compile_features(UE4SS PUBLIC cxx_std_23)
7663

7764
# Add include directories
78-
target_include_directories(UE4SS PUBLIC
65+
target_include_directories(UE4SS PUBLIC
7966
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
8067
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/generated_include>
8168
)
8269

70+
# Add version definitions with PUBLIC visibility so external consumers get them
71+
target_compile_definitions(UE4SS PUBLIC
72+
UE4SS_LIB_VERSION_MAJOR=${UE4SS_LIB_VERSION_MAJOR}
73+
UE4SS_LIB_VERSION_MINOR=${UE4SS_LIB_VERSION_MINOR}
74+
UE4SS_LIB_VERSION_HOTFIX=${UE4SS_LIB_VERSION_HOTFIX}
75+
UE4SS_LIB_VERSION_PRERELEASE=${UE4SS_LIB_VERSION_PRERELEASE}
76+
UE4SS_LIB_VERSION_BETA=${UE4SS_LIB_VERSION_BETA}
77+
UE4SS_LIB_BETA_STARTED=$<BOOL:${UE4SS_LIB_BETA_IS_STARTED}>
78+
UE4SS_LIB_IS_BETA=$<BOOL:${UE4SS_LIB_IS_BETA}>
79+
UE4SS_LIB_BUILD_GITSHA="${UE4SS_LIB_BUILD_GITSHA}"
80+
UE4SS_CONFIGURATION="$<CONFIG>"
81+
)
82+
8383
# Add headers as sources for IDE integration
8484
target_sources(UE4SS PUBLIC
8585
FILE_SET ue4ss_headers TYPE HEADERS
@@ -137,7 +137,8 @@ target_link_libraries(UE4SS PUBLIC
137137
# Enable link-time optimization
138138
set_property(TARGET UE4SS PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
139139

140-
# Set runtime library to DLL for C++ mods compatibility
140+
# Set runtime library to dynamic CRT (/MD, /MDd)
141+
# This matches Visual Studio's default, so external mods don't need to set it explicitly.
141142
set_property(TARGET UE4SS PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
142143

143144
# Set output name and standard

cmake/modules/IDEOrganization.cmake

Lines changed: 14 additions & 6 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")
@@ -185,12 +195,10 @@ function(apply_compiler_settings_to_targets TARGET_COMPILE_OPTIONS TARGET_LINK_O
185195
target_compile_options(${target} PUBLIC "${TARGET_COMPILE_OPTIONS}")
186196
target_link_options(${target} PUBLIC "${TARGET_LINK_OPTIONS}")
187197
target_compile_definitions(${target} PUBLIC "${TARGET_COMPILE_DEFINITIONS}")
188-
target_compile_options(${target} PUBLIC "${TARGET_COMPILE_OPTIONS}")
189198
else()
190199
target_compile_options(${target} PRIVATE "${TARGET_COMPILE_OPTIONS}")
191200
target_link_options(${target} PRIVATE "${TARGET_LINK_OPTIONS}")
192201
target_compile_definitions(${target} PRIVATE "${TARGET_COMPILE_DEFINITIONS}")
193-
target_compile_options(${target} PRIVATE "${TARGET_COMPILE_OPTIONS}")
194202
endif()
195203
endif()
196204

cmake/modules/IDEVisibility.cmake

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,45 @@ function(make_headers_visible TARGET_NAME INCLUDE_DIR)
3030
"${INCLUDE_DIR}/*.hxx"
3131
"${INCLUDE_DIR}/*.inl"
3232
)
33-
33+
3434
if(HEADER_FILES)
3535
# Check if it's an INTERFACE library or not
3636
get_target_property(target_type ${TARGET_NAME} TYPE)
37-
37+
3838
if(target_type STREQUAL "INTERFACE_LIBRARY")
39-
# For INTERFACE libraries
39+
# For INTERFACE libraries, add FILE_SET for actual usage
4040
target_sources(${TARGET_NAME} INTERFACE
4141
FILE_SET headers TYPE HEADERS
4242
BASE_DIRS ${INCLUDE_DIR}
4343
FILES ${HEADER_FILES}
4444
)
45+
46+
# Create a companion OBJECT library for IDE visibility
47+
# This makes the headers appear in the solution explorer
48+
set(VISIBILITY_TARGET "${TARGET_NAME}_IDE")
49+
if(NOT TARGET ${VISIBILITY_TARGET})
50+
add_library(${VISIBILITY_TARGET} OBJECT EXCLUDE_FROM_ALL)
51+
target_sources(${VISIBILITY_TARGET} PRIVATE ${HEADER_FILES})
52+
53+
# Organize headers using source_group
54+
source_group(TREE "${INCLUDE_DIR}" PREFIX "Header Files" FILES ${HEADER_FILES})
55+
56+
# Set folder properties for IDE organization
57+
get_target_property(target_folder ${TARGET_NAME} FOLDER)
58+
if(target_folder)
59+
set_target_properties(${VISIBILITY_TARGET} PROPERTIES
60+
FOLDER "${target_folder}"
61+
VS_FOLDER "${target_folder}")
62+
endif()
63+
64+
# Prevent this target from being built
65+
set_target_properties(${VISIBILITY_TARGET} PROPERTIES
66+
LINKER_LANGUAGE CXX
67+
EXCLUDE_FROM_ALL TRUE
68+
EXCLUDE_FROM_DEFAULT_BUILD TRUE)
69+
70+
message(STATUS "Created ${VISIBILITY_TARGET} for IDE visibility")
71+
endif()
4572
else()
4673
# For normal libraries
4774
target_sources(${TARGET_NAME} PUBLIC

cmake/modules/ProjectConfig.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ option(UE4SS_SUPPRESS_THIRD_PARTY_WARNINGS "Suppress warnings from third-party l
1919
option(UE4SS_VERSION_CHECK "Enable compiler version checking" ON)
2020

2121
# Profiler configuration
22-
set(RC_PROFILER_FLAVOR "Tracy" CACHE STRING "Select profiler: Tracy, Superluminal, or None")
22+
# Default to None - users can opt-in to Tracy or Superluminal if needed
23+
set(RC_PROFILER_FLAVOR "None" CACHE STRING "Select profiler: Tracy, Superluminal, or None")
2324
set_property(CACHE RC_PROFILER_FLAVOR PROPERTY STRINGS Tracy Superluminal None)
2425

2526
# Proxy configuration

cmake/modules/Utilities.cmake

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ endfunction()
3838
# TARGET_COMPILE_DEFINITIONS - Compile definitions for each configuration
3939
#
4040
function(generate_build_configurations)
41-
# These variables will be set in the parent scope
42-
set(BUILD_CONFIGS "" PARENT_SCOPE)
43-
set(TARGET_COMPILE_OPTIONS "$<$<NOT:$<COMPILE_LANGUAGE:ASM_MASM>>:${DEFAULT_COMPILER_FLAGS}>" PARENT_SCOPE)
44-
set(TARGET_LINK_OPTIONS "${DEFAULT_EXE_LINKER_FLAGS}" "${DEFAULT_SHARED_LINKER_FLAGS}" PARENT_SCOPE)
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+
44+
# These variables will be built up in _LOCAL variants and set in parent scope at the end
45+
set(TARGET_COMPILE_OPTIONS_LOCAL "")
46+
set(TARGET_LINK_OPTIONS_LOCAL "")
4547
set(TARGET_COMPILE_DEFINITIONS_LOCAL ${TARGET_COMPILE_DEFINITIONS})
4648

4749
# Build configs to return
@@ -78,7 +80,9 @@ function(generate_build_configurations)
7880
set(CMAKE_CXX_FLAGS_${triplet_upper} "${CMAKE_CXX_FLAGS_${triplet_upper}} ${final_compiler_flags}" CACHE STRING "" FORCE)
7981
set(CMAKE_C_FLAGS_${triplet_upper} "${CMAKE_C_FLAGS_${triplet_upper}} ${final_compiler_flags}" CACHE STRING "" FORCE)
8082

81-
list(APPEND TARGET_COMPILE_OPTIONS_LOCAL "$<$<NOT:$<COMPILE_LANGUAGE:ASM_MASM>>:$<$<STREQUAL:$<CONFIG>,${triplet}>:${compiler_flags}>>")
83+
# Combine DEFAULT_COMPILER_FLAGS with per-config flags for propagation to external consumers
84+
# This ensures both base flags (like /W3, /Zc:inline) and config-specific flags (like /O2) propagate
85+
list(APPEND TARGET_COMPILE_OPTIONS_LOCAL "$<$<NOT:$<COMPILE_LANGUAGE:ASM_MASM>>:$<$<STREQUAL:$<CONFIG>,${triplet}>:${DEFAULT_COMPILER_FLAGS};${compiler_flags}>>")
8286

8387
# Set up linker flags
8488
set(linker_flags
@@ -96,13 +100,19 @@ function(generate_build_configurations)
96100
# Append to existing flags to preserve CMake's defaults (including standard libraries)
97101
set(CMAKE_EXE_LINKER_FLAGS_${triplet_upper} "${CMAKE_EXE_LINKER_FLAGS_${triplet_upper}} ${exe_linker_flags}" CACHE STRING "" FORCE)
98102
set(CMAKE_SHARED_LINKER_FLAGS_${triplet_upper} "${CMAKE_SHARED_LINKER_FLAGS_${triplet_upper}} ${shared_linker_flags}" CACHE STRING "" FORCE)
99-
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}>")
100107
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "${triplet}")
101-
# For single-config, append to base flags (don't use TARGET_LINK_OPTIONS to avoid duplication)
108+
# For single-config, append to base flags including DEFAULT_EXE_LINKER_FLAGS
102109
# Preserve CMake's defaults including standard libraries
103-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${exe_linker_flags}" CACHE STRING "" FORCE)
104-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${shared_linker_flags}" CACHE STRING "" FORCE)
110+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DEFAULT_EXE_LINKER_FLAGS} ${exe_linker_flags}" CACHE STRING "" FORCE)
111+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DEFAULT_SHARED_LINKER_FLAGS} ${shared_linker_flags}" CACHE STRING "" FORCE)
105112
message(STATUS "Single-config: Applied ${triplet} linker flags to base CMAKE linker flags")
113+
# Also add to TARGET_LINK_OPTIONS for propagation to external consumers
114+
list(APPEND TARGET_LINK_OPTIONS_LOCAL "${DEFAULT_EXE_LINKER_FLAGS}")
115+
list(APPEND TARGET_LINK_OPTIONS_LOCAL "${linker_flags}")
106116
endif()
107117

108118
# Set platform-specific variables

deps/first/Profiler/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ project(${TARGET})
88
message("Project: ${TARGET} (HEADER-ONLY)")
99

1010
set(ProfilerFlavors Tracy Superluminal None)
11-
set(RC_PROFILER_FLAVOR Tracy CACHE STRING "Profiler flavor (Tracy, Superluminal, or None)")
11+
# Default to None - users can opt-in to Tracy or Superluminal if needed
12+
# This is also set in ProjectConfig.cmake - whichever is evaluated last takes precedence
13+
set(RC_PROFILER_FLAVOR "None" CACHE STRING "Profiler flavor (Tracy, Superluminal, or None)")
1214
set_property(CACHE RC_PROFILER_FLAVOR PROPERTY STRINGS ${ProfilerFlavors})
1315

1416
add_library(${TARGET} INTERFACE)
@@ -23,8 +25,10 @@ target_include_directories(${TARGET} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/inclu
2325
make_headers_visible(${TARGET} "${CMAKE_CURRENT_SOURCE_DIR}/include")
2426

2527
if (${RC_PROFILER_FLAVOR} STREQUAL None)
28+
message(STATUS "Profiler: Disabled (set RC_PROFILER_FLAVOR=Tracy to enable)")
2629
target_compile_definitions(${TARGET} INTERFACE DISABLE_PROFILER IS_TRACY=0 IS_SUPERLUMINAL=0)
2730
elseif (${RC_PROFILER_FLAVOR} STREQUAL Tracy)
31+
message(STATUS "Profiler: Tracy (fetching from GitHub)")
2832
# Tracy start
2933
FetchContent_Declare(Tracy
3034
GIT_REPOSITORY [email protected]:wolfpld/tracy.git
@@ -37,6 +41,7 @@ elseif (${RC_PROFILER_FLAVOR} STREQUAL Tracy)
3741
target_compile_definitions(${TARGET} INTERFACE IS_TRACY=1 IS_SUPERLUMINAL=0)
3842
target_link_libraries(${TARGET} INTERFACE TracyClient)
3943
elseif (${RC_PROFILER_FLAVOR} STREQUAL Superluminal)
44+
message(STATUS "Profiler: Superluminal")
4045
find_package(SuperluminalAPI REQUIRED)
4146

4247
target_compile_definitions(${TARGET} INTERFACE IS_TRACY=0 IS_SUPERLUMINAL=1)

0 commit comments

Comments
 (0)