Skip to content

Commit 9af1f55

Browse files
Merge pull request #2713 from vidurvij-apptronik:vidur/remove-installing-glfw3-headers
PiperOrigin-RevId: 808125077 Change-Id: If87b65d2d8607f153dfd66fbfa9a6ca39c98845f
2 parents 7eab011 + 28aa33b commit 9af1f55

File tree

4 files changed

+52
-29
lines changed

4 files changed

+52
-29
lines changed

python/mujoco/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ mujoco_pybind11_module(_simulate simulate.cc)
454454
target_link_libraries(
455455
_simulate
456456
PRIVATE mujoco
457-
mujoco::libsimulate
457+
mujoco::libmujoco_simulate
458+
glfw
458459
errors_header
459460
raw
460461
structs_header

sample/cmake/SampleDependencies.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ if(MUJOCO_EXTRAS_STATIC_GLFW)
9898
unset(BUILD_SHARED_LIBS_OLD)
9999
endif()
100100

101-
if(NOT SAMPLE_STANDALONE)
101+
if(NOT SAMPLE_STANDALONE AND NOT MUJOCO_SAMPLES_USE_SYSTEM_GLFW)
102102
target_compile_options(glfw PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
103103
target_link_options(glfw PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
104104
endif()

simulate/CMakeLists.txt

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ option(SIMULATE_GLFW_DYNAMIC_SYMBOLS "Whether to resolve GLFW symbols dynamicall
4747
# Check if we are building as standalone project.
4848
set(SIMULATE_STANDALONE OFF)
4949
set(_INSTALL_SIMULATE ON)
50+
5051
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
5152
set(SIMULATE_STANDALONE ON)
5253
# If standalone, do not install the samples.
@@ -93,7 +94,7 @@ if(NOT TARGET lodepng)
9394
# This is not a CMake project.
9495
set(LODEPNG_SRCS ${lodepng_SOURCE_DIR}/lodepng.cpp)
9596
set(LODEPNG_HEADERS ${lodepng_SOURCE_DIR}/lodepng.h)
96-
add_library(lodepng STATIC ${LODEPNG_HEADERS} ${LODEPNG_SRCS})
97+
add_library(lodepng OBJECT ${LODEPNG_HEADERS} ${LODEPNG_SRCS})
9798
target_compile_options(lodepng PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
9899
target_link_options(lodepng PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
99100
target_include_directories(lodepng PUBLIC ${lodepng_SOURCE_DIR})
@@ -114,7 +115,7 @@ if(APPLE)
114115
target_link_libraries(platform_ui_adapter PUBLIC "-framework CoreVideo")
115116
endif()
116117
target_include_directories(
117-
platform_ui_adapter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
118+
platform_ui_adapter PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
118119
$<TARGET_PROPERTY:glfw,INTERFACE_INCLUDE_DIRECTORIES>
119120
)
120121
target_link_libraries(platform_ui_adapter PUBLIC mujoco::mujoco)
@@ -123,23 +124,30 @@ if(SIMULATE_GLFW_DYNAMIC_SYMBOLS)
123124
endif()
124125
add_library(mujoco::platform_ui_adapter ALIAS platform_ui_adapter)
125126

126-
add_library(libsimulate STATIC $<TARGET_OBJECTS:platform_ui_adapter>)
127-
set_target_properties(libsimulate PROPERTIES OUTPUT_NAME simulate)
128-
add_library(mujoco::libsimulate ALIAS libsimulate)
127+
add_library(libmujoco_simulate STATIC $<TARGET_OBJECTS:platform_ui_adapter> $<TARGET_OBJECTS:lodepng>)
128+
set_target_properties(libmujoco_simulate PROPERTIES OUTPUT_NAME simulate)
129+
add_library(mujoco::libmujoco_simulate ALIAS libmujoco_simulate)
130+
set_target_properties(libmujoco_simulate PROPERTIES PUBLIC_HEADER "simulate.h;platform_ui_adapter.h;glfw_adapter.h;glfw_dispatch.h;glfw_corevideo.h;array_safety.h")
131+
129132

130133
target_sources(
131-
libsimulate
132-
PUBLIC simulate.h
133-
PRIVATE simulate.cc array_safety.h
134+
libmujoco_simulate
135+
PRIVATE simulate.cc
134136
)
135-
target_include_directories(libsimulate PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
136-
target_compile_options(libsimulate PRIVATE ${MUJOCO_SIMULATE_COMPILE_OPTIONS})
137-
target_link_libraries(libsimulate PUBLIC lodepng mujoco::platform_ui_adapter mujoco::mujoco)
138-
target_link_options(libsimulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS})
137+
target_include_directories(libmujoco_simulate
138+
PUBLIC
139+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
140+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/simulate>
141+
PRIVATE
142+
${lodepng_SOURCE_DIR}
143+
)
144+
target_compile_options(libmujoco_simulate PRIVATE ${MUJOCO_SIMULATE_COMPILE_OPTIONS})
145+
target_link_libraries(libmujoco_simulate PUBLIC mujoco::mujoco)
146+
target_link_options(libmujoco_simulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS})
139147

140148
if(APPLE)
141-
target_sources(libsimulate PRIVATE macos_gui.mm)
142-
target_link_libraries(libsimulate PUBLIC "-framework Cocoa")
149+
target_sources(libmujoco_simulate PRIVATE macos_gui.mm)
150+
target_link_libraries(libmujoco_simulate PUBLIC "-framework Cocoa")
143151
endif()
144152

145153
# Build simulate executable
@@ -167,13 +175,16 @@ if(SIMULATE_BUILD_EXECUTABLE)
167175

168176
target_link_libraries(
169177
simulate
170-
libsimulate
178+
libmujoco_simulate
171179
mujoco::mujoco
172180
glfw
173181
Threads::Threads
174-
lodepng
175182
)
176183

184+
if(APPLE)
185+
target_link_libraries(simulate "-framework CoreVideo")
186+
endif()
187+
177188
if (MUJOCO_WITH_USD)
178189
target_link_libraries(
179190
simulate
@@ -263,16 +274,6 @@ if(SIMULATE_BUILD_EXECUTABLE)
263274
)
264275
endif()
265276

266-
install(
267-
TARGETS simulate
268-
EXPORT ${PROJECT_NAME}
269-
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT simulate
270-
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT simulate
271-
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT simulate
272-
BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT simulate
273-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT simulate
274-
)
275-
276277
if(NOT MUJOCO_SIMULATE_USE_SYSTEM_GLFW)
277278
# We downloaded GLFW. Depending if it is a static or shared LIBRARY we might
278279
# need to install it.
@@ -288,5 +289,26 @@ if(SIMULATE_BUILD_EXECUTABLE)
288289
)
289290
endif()
290291
endif()
292+
293+
install(
294+
TARGETS simulate
295+
EXPORT ${PROJECT_NAME}
296+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT simulate
297+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT simulate
298+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT simulate
299+
BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT simulate
300+
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT simulate
301+
)
302+
303+
# Specify public headers for libmujoco_simulate
304+
305+
install(
306+
TARGETS libmujoco_simulate
307+
EXPORT mujoco
308+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT simulate
309+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT simulate
310+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT simulate
311+
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/simulate" COMPONENT simulate
312+
)
291313
endif()
292314
endif()

simulate/cmake/SimulateDependencies.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ if(MUJOCO_EXTRAS_STATIC_GLFW)
9898
unset(BUILD_SHARED_LIBS_OLD)
9999
endif()
100100

101-
if(NOT SIMULATE_STANDALONE)
101+
if(NOT SIMULATE_STANDALONE AND NOT MUJOCO_SIMULATE_USE_SYSTEM_GLFW)
102102
target_compile_options(glfw PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
103103
target_link_options(glfw PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
104104
endif()

0 commit comments

Comments
 (0)