mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-25 07:05:48 +00:00
Compile posix_libentry into a static library to ensure it's linked last
* If we want our global constructor to run after even static linked libaries (which we will soon for LLVM) then we must make it a static library as well. We do some tricks to ensure the symbols are still pulled in even though it's otherwise "unused".
This commit is contained in:
+31
-30
@@ -9,25 +9,22 @@ set(RDOC_LIBRARIES)
|
||||
|
||||
if(ANDROID)
|
||||
list(APPEND RDOC_LIBRARIES
|
||||
PRIVATE m
|
||||
PRIVATE dl
|
||||
PRIVATE log
|
||||
PRIVATE android
|
||||
PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
PRIVATE -lm
|
||||
PRIVATE -ldl
|
||||
PRIVATE -llog
|
||||
PRIVATE -landroid)
|
||||
elseif(APPLE)
|
||||
list(APPEND RDOC_LIBRARIES
|
||||
PRIVATE m
|
||||
PRIVATE dl
|
||||
PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
PRIVATE -lm
|
||||
PRIVATE -ldl)
|
||||
elseif(UNIX)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
list(APPEND RDOC_LIBRARIES
|
||||
PRIVATE m
|
||||
PRIVATE dl
|
||||
PRIVATE rt
|
||||
PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
PRIVATE -lm
|
||||
PRIVATE -ldl
|
||||
PRIVATE -lrt)
|
||||
|
||||
if(ENABLE_XLIB)
|
||||
find_package(X11 REQUIRED)
|
||||
@@ -36,7 +33,7 @@ elseif(UNIX)
|
||||
PRIVATE ${X11_X11_INCLUDE_PATH})
|
||||
|
||||
list(APPEND RDOC_LIBRARIES
|
||||
PRIVATE ${X11_X11_LIB})
|
||||
PRIVATE -l${X11_X11_LIB})
|
||||
endif()
|
||||
|
||||
if(ENABLE_XCB)
|
||||
@@ -49,10 +46,14 @@ elseif(UNIX)
|
||||
PRIVATE ${XCB_INCLUDE_DIRS})
|
||||
|
||||
list(APPEND RDOC_LIBRARIES
|
||||
PRIVATE ${XCB_LIBRARIES})
|
||||
PRIVATE -l${XCB_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT "x${CMAKE_THREAD_LIBS_INIT}" STREQUAL "x")
|
||||
list(APPEND RDOC_LIBRARIES PRIVATE -l${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
set(sources
|
||||
api/app/renderdoc_app.h
|
||||
api/replay/basic_types.h
|
||||
@@ -218,9 +219,6 @@ if(ANDROID)
|
||||
os/posix/posix_stringio.cpp
|
||||
os/posix/posix_threading.cpp
|
||||
os/posix/posix_specific.h)
|
||||
# posix_libentry must be the last so that library_loaded is called after
|
||||
# static objects are constructed.
|
||||
list(APPEND sources os/posix/posix_libentry.cpp)
|
||||
elseif(APPLE)
|
||||
list(APPEND sources
|
||||
data/embedded_files.h
|
||||
@@ -237,9 +235,6 @@ elseif(APPLE)
|
||||
os/posix/posix_stringio.cpp
|
||||
os/posix/posix_threading.cpp
|
||||
os/posix/posix_specific.h)
|
||||
# posix_libentry must be the last so that library_loaded is called after
|
||||
# static objects are constructed.
|
||||
list(APPEND sources os/posix/posix_libentry.cpp)
|
||||
elseif(UNIX)
|
||||
list(APPEND sources
|
||||
data/embedded_files.h
|
||||
@@ -258,9 +253,6 @@ elseif(UNIX)
|
||||
os/posix/posix_stringio.cpp
|
||||
os/posix/posix_threading.cpp
|
||||
os/posix/posix_specific.h)
|
||||
# posix_libentry must be the last so that library_loaded is called after
|
||||
# static objects are constructed.
|
||||
list(APPEND sources os/posix/posix_libentry.cpp)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR APPLE)
|
||||
@@ -281,10 +273,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR APPLE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(rdoc OBJECT ${sources})
|
||||
target_compile_definitions(rdoc ${RDOC_DEFINITIONS})
|
||||
target_include_directories(rdoc ${RDOC_INCLUDES})
|
||||
|
||||
set(data
|
||||
data/glsl/blit.vert
|
||||
data/glsl/checkerboard.frag
|
||||
@@ -371,22 +359,35 @@ endif()
|
||||
add_subdirectory(driver/ihv/amd)
|
||||
list(APPEND renderdoc_objects $<TARGET_OBJECTS:rdoc_amd>)
|
||||
|
||||
# rdoc must be after its drivers because of linux_libentry.cpp
|
||||
add_library(rdoc OBJECT ${sources})
|
||||
target_compile_definitions(rdoc ${RDOC_DEFINITIONS})
|
||||
target_include_directories(rdoc ${RDOC_INCLUDES})
|
||||
|
||||
list(APPEND renderdoc_objects
|
||||
$<TARGET_OBJECTS:rdoc>
|
||||
${data_objects})
|
||||
|
||||
# posix_libentry must be the last so that library_loaded is called after
|
||||
# static objects are constructed. We guarantee this happens after even
|
||||
# any other static libraries that we link by making it its own static
|
||||
# library and appending it to the end of the link list.
|
||||
add_library(renderdoc_libentry STATIC os/posix/posix_libentry.cpp)
|
||||
target_compile_definitions(renderdoc_libentry ${RDOC_DEFINITIONS})
|
||||
target_include_directories(renderdoc_libentry ${RDOC_INCLUDES})
|
||||
link_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
list(APPEND RDOC_LIBRARIES PRIVATE -lrenderdoc_libentry)
|
||||
|
||||
add_library(renderdoc SHARED ${renderdoc_objects})
|
||||
target_compile_definitions(renderdoc ${RDOC_DEFINITIONS})
|
||||
target_include_directories(renderdoc ${RDOC_INCLUDES})
|
||||
target_link_libraries(renderdoc ${RDOC_LIBRARIES})
|
||||
|
||||
if(UNIX AND NOT ANDROID AND NOT APPLE)
|
||||
set_target_properties(renderdoc PROPERTIES LINK_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/renderdoc.version -Wl,--no-undefined")
|
||||
set_target_properties(renderdoc PROPERTIES LINK_FLAGS "-Wl,--undefined,force_include_libentry -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/renderdoc.version -Wl,--no-undefined")
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
set_target_properties(renderdoc PROPERTIES LINK_FLAGS "-Wl,--build-id")
|
||||
set_target_properties(renderdoc PROPERTIES LINK_FLAGS "-Wl,--undefined,force_include_libentry -Wl,--build-id")
|
||||
# rename output library
|
||||
set_target_properties(renderdoc PROPERTIES OUTPUT_NAME "VkLayer_GLES_RenderDoc")
|
||||
|
||||
|
||||
@@ -87,3 +87,10 @@ struct init
|
||||
{
|
||||
init() { library_loaded(); }
|
||||
} do_init;
|
||||
|
||||
// we want to be sure the constructor and library_loaded are included even when this is in a static
|
||||
// library, so we have this global function that does nothing but takes the address.
|
||||
extern "C" __attribute__((visibility("default"))) void *force_include_libentry()
|
||||
{
|
||||
return &do_init;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user