Skip to content

Commit e8305c7

Browse files
Automate shared library copy next to executable so they can be located at program execution.
1 parent f5cded0 commit e8305c7

File tree

44 files changed

+211
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+211
-96
lines changed

CMakeLists.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@ set(OZZ_VERSION ${OZZ_VERSION_MAJOR}.${OZZ_VERSION_MINOR}.${OZZ_VERSION_PATCH})
1111

1212
# Add project build options
1313
option(ozz_build_tools "Build tools" ON)
14-
option(ozz_build_fbx "Build Fbx pipeline (Requires Fbx SDK)" ON)
14+
option(ozz_build_fbx "Build Fbx pipeline (Requires Fbx SDK)" OFF)
1515
option(ozz_build_gltf "Build glTF importer (Requires c++11)" ON)
1616
option(ozz_build_data "Build data on code change" OFF)
1717
option(ozz_build_samples "Build samples" ON)
1818
option(ozz_build_howtos "Build howtos" ON)
1919
option(ozz_build_tests "Build unit tests" ON)
2020
option(ozz_build_simd_ref "Force SIMD math reference implementation" OFF)
21-
option(ozz_build_msvc_rt_dll "Select msvc DLL runtime library" ON)
2221
option(ozz_build_postfix "Use per config postfix name" ON)
23-
option(ozz_build_dll "Build ozz runtime libraries as DLLs" OFF)
22+
option(ozz_build_dll "Build ozz as shared libraries" OFF)
23+
option(ozz_build_msvc_rt_dll "Select msvc DLL runtime library" OFF)
24+
25+
# Checks DLL flags
26+
if(ozz_build_dll AND NOT ozz_build_msvc_rt_dll)
27+
message("Forcing ozz_build_msvc_rt_dll to ON as ozz is being built as dll (ozz_build_dll is ON).")
28+
set(ozz_build_msvc_rt_dll ON)
29+
endif()
2430

2531
# Include ozz cmake parameters and scripts
2632
include(CheckCXXCompilerFlag)
2733
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/compiler_settings.cmake)
2834
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/package_settings.cmake)
2935
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/fuse_target.cmake)
3036
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/clang_format.cmake)
37+
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/shared_library.cmake)
3138

3239
# Add project execution options
3340
option(ozz_run_tests_headless "Run samples without rendering (used for unit tests)" ON)
@@ -84,6 +91,7 @@ message("-- - ozz_build_samples: " ${ozz_build_samples})
8491
message("-- - ozz_build_howtos: " ${ozz_build_howtos})
8592
message("-- - ozz_build_tests: " ${ozz_build_tests})
8693
message("-- - ozz_build_simd_ref: " ${ozz_build_simd_ref})
94+
message("-- - ozz_build_dll: " ${ozz_build_dll})
8795
message("-- - ozz_build_msvc_rt_dll: " ${ozz_build_msvc_rt_dll})
8896
message("-- - ozz_build_postfix: " ${ozz_build_postfix})
8997

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Finds target dependencies on shared libraries so they can
2+
# be copied next to the exe.
3+
#----------------------------------------------------------
4+
5+
# Finds all target dependencies
6+
function(get_link_libraries OUTPUT_LIST _TARGET)
7+
get_target_property(LIBS ${_TARGET} LINK_LIBRARIES)
8+
9+
list(APPEND VISITED_TARGETS ${TARGET})
10+
11+
set(LIB_FILES "")
12+
foreach(LIB ${LIBS})
13+
14+
if (TARGET ${LIB})
15+
list(FIND VISITED_TARGETS ${LIB} VISITED)
16+
if (${VISITED} EQUAL -1)
17+
get_link_libraries(LINK_LIBS ${LIB})
18+
list(APPEND LIB_FILES ${LIB} ${LINK_LIBS})
19+
endif()
20+
endif()
21+
endforeach()
22+
set(VISITED_TARGETS ${VISITED_TARGETS} PARENT_SCOPE)
23+
set(${OUTPUT_LIST} ${LIB_FILES} PARENT_SCOPE)
24+
endfunction()
25+
26+
# Copy dependent shared libraries next to executable target
27+
function(target_copy_shared_libraries _TARGET)
28+
# Copy only applies to win32 for the moment
29+
if(WIN32)
30+
get_link_libraries(LINKED_TARGETS ${_TARGET})
31+
32+
foreach(LINKED_TARGET ${LINKED_TARGETS})
33+
get_target_property(TARGET_TYPE ${LINKED_TARGET} TYPE)
34+
if(TARGET_TYPE STREQUAL "SHARED_LIBRARY")
35+
list(APPEND DLL_TARGETS "$<TARGET_FILE:${LINKED_TARGET}>")
36+
endif()
37+
endforeach()
38+
39+
if(DLL_TARGETS)
40+
add_custom_command(
41+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET}_dll_copy"
42+
DEPENDS ${DLL_TARGETS}
43+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DLL_TARGETS} "./"
44+
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET}_dll_copy"
45+
VERBATIM)
46+
47+
# This allows to create a dependency with the command above, so command is executed again when target is built AND a DLL changed
48+
target_sources(${_TARGET} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET}_dll_copy")
49+
endif()
50+
endif()
51+
endfunction()

howtos/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_executable(load_from_file
44
load_from_file.cc)
55
target_link_libraries(load_from_file
66
ozz_animation)
7+
target_copy_shared_libraries(load_from_file)
78
set_target_properties(load_from_file
89
PROPERTIES FOLDER "howtos")
910
add_test(NAME load_from_file COMMAND load_from_file "${ozz_media_directory}/bin/pab_skeleton.ozz")
@@ -18,6 +19,7 @@ add_executable(custom_skeleton_importer
1819
custom_skeleton_importer.cc)
1920
target_link_libraries(custom_skeleton_importer
2021
ozz_animation_offline)
22+
target_copy_shared_libraries(custom_skeleton_importer)
2123
set_target_properties(custom_skeleton_importer
2224
PROPERTIES FOLDER "howtos")
2325
add_test(NAME custom_skeleton_importer COMMAND custom_skeleton_importer)
@@ -28,6 +30,7 @@ add_executable(custom_animation_importer
2830
custom_animation_importer.cc)
2931
target_link_libraries(custom_animation_importer
3032
ozz_animation_offline)
33+
target_copy_shared_libraries(custom_animation_importer)
3134
set_target_properties(custom_animation_importer
3235
PROPERTIES FOLDER "howtos")
3336
add_test(NAME custom_animation_importer COMMAND custom_animation_importer)

include/ozz/animation/offline/fbx/fbx.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333
#include "ozz/base/maths/simd_math.h"
3434
#include "ozz/base/maths/transform.h"
3535

36-
#ifdef OZZ_USE_DYNAMIC_LINKING
37-
#ifdef OZZ_BUILD_ANIMATIONFBX_LIB
38-
// export for dynamic linking while building ozz
39-
#define OZZ_ANIMFBX_DLL __declspec(dllexport)
40-
#else
41-
// import for dynamic linking when just using ozz
42-
#define OZZ_ANIMFBX_DLL __declspec(dllimport)
43-
#endif()
44-
#else
45-
// static linking
46-
#define OZZ_ANIMFBX_DLL
36+
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
37+
#ifdef OZZ_BUILD_ANIMATIONFBX_LIB
38+
// export for dynamic linking while building ozz
39+
#define OZZ_ANIMFBX_DLL __declspec(dllexport)
40+
#else // OZZ_BUILD_ANIMATIONFBX_LIB
41+
// import for dynamic linking when just using ozz
42+
#define OZZ_ANIMFBX_DLL __declspec(dllimport)
4743
#endif
44+
#else // OZZ_BUILD_ANIMATIONFBX_LIB
45+
// static linking
46+
#define OZZ_ANIMFBX_DLL
47+
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
4848

4949
namespace ozz {
5050
namespace math {

include/ozz/base/platform.h

+32-40
Original file line numberDiff line numberDiff line change
@@ -41,58 +41,50 @@
4141
#include <cassert>
4242
#include <cstddef>
4343

44-
#ifdef OZZ_USE_DYNAMIC_LINKING
45-
#ifdef OZZ_BUILD_BASE_LIB
46-
// export for dynamic linking while building ozz
47-
#define OZZ_BASE_DLL __declspec(dllexport)
48-
#else
49-
// import for dynamic linking when just using ozz
50-
#define OZZ_BASE_DLL __declspec(dllimport)
51-
#endif()
44+
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
45+
46+
#ifdef OZZ_BUILD_BASE_LIB
47+
// export for dynamic linking while building ozz
48+
#define OZZ_BASE_DLL __declspec(dllexport)
5249
#else
53-
// static linking
54-
#define OZZ_BASE_DLL
50+
// import for dynamic linking when just using ozz
51+
#define OZZ_BASE_DLL __declspec(dllimport)
5552
#endif
5653

57-
#ifdef OZZ_USE_DYNAMIC_LINKING
58-
#ifdef OZZ_BUILD_ANIMATION_LIB
59-
// export for dynamic linking while building ozz
60-
#define OZZ_ANIMATION_DLL __declspec(dllexport)
61-
#else
62-
// import for dynamic linking when just using ozz
63-
#define OZZ_ANIMATION_DLL __declspec(dllimport)
64-
#endif()
54+
#ifdef OZZ_BUILD_ANIMATION_LIB
55+
// export for dynamic linking while building ozz
56+
#define OZZ_ANIMATION_DLL __declspec(dllexport)
6557
#else
66-
// static linking
67-
#define OZZ_ANIMATION_DLL
58+
// import for dynamic linking when just using ozz
59+
#define OZZ_ANIMATION_DLL __declspec(dllimport)
6860
#endif
6961

70-
#ifdef OZZ_USE_DYNAMIC_LINKING
71-
#ifdef OZZ_BUILD_ANIMOFFLINE_LIB
72-
// export for dynamic linking while building ozz
73-
#define OZZ_ANIMOFFLINE_DLL __declspec(dllexport)
74-
#else
75-
// import for dynamic linking when just using ozz
76-
#define OZZ_ANIMOFFLINE_DLL __declspec(dllimport)
77-
#endif()
62+
#ifdef OZZ_BUILD_ANIMOFFLINE_LIB
63+
// export for dynamic linking while building ozz
64+
#define OZZ_ANIMOFFLINE_DLL __declspec(dllexport)
7865
#else
79-
// static linking
80-
#define OZZ_ANIMOFFLINE_DLL
66+
// import for dynamic linking when just using ozz
67+
#define OZZ_ANIMOFFLINE_DLL __declspec(dllimport)
8168
#endif
8269

83-
#ifdef OZZ_USE_DYNAMIC_LINKING
84-
#ifdef OZZ_BUILD_ANIMATIONTOOLS_LIB
85-
// export for dynamic linking while building ozz
86-
#define OZZ_ANIMTOOLS_DLL __declspec(dllexport)
87-
#else
88-
// import for dynamic linking when just using ozz
89-
#define OZZ_ANIMTOOLS_DLL __declspec(dllimport)
90-
#endif()
70+
#ifdef OZZ_BUILD_ANIMATIONTOOLS_LIB
71+
// export for dynamic linking while building ozz
72+
#define OZZ_ANIMTOOLS_DLL __declspec(dllexport)
9173
#else
92-
// static linking
93-
#define OZZ_ANIMTOOLS_DLL
74+
// import for dynamic linking when just using ozz
75+
#define OZZ_ANIMTOOLS_DLL __declspec(dllimport)
9476
#endif
9577

78+
#else // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
79+
80+
// static linking
81+
#define OZZ_BASE_DLL
82+
#define OZZ_ANIMATION_DLL
83+
#define OZZ_ANIMOFFLINE_DLL
84+
#define OZZ_ANIMTOOLS_DLL
85+
86+
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
87+
9688
namespace ozz {
9789

9890
// Finds the number of elements of a statically allocated array.

include/ozz/geometry/runtime/skinning_job.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
#include "ozz/base/platform.h"
3232
#include "ozz/base/span.h"
3333

34-
#ifdef OZZ_USE_DYNAMIC_LINKING
35-
#ifdef OZZ_BUILD_GEOMETRY_LIB
36-
// export for dynamic linking while building ozz
37-
#define OZZ_GEOMETRY_DLL __declspec(dllexport)
38-
#else
39-
// import for dynamic linking when just using ozz
40-
#define OZZ_GEOMETRY_DLL __declspec(dllimport)
41-
#endif()
34+
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
35+
#ifdef OZZ_BUILD_GEOMETRY_LIB
36+
// export for dynamic linking while building ozz
37+
#define OZZ_GEOMETRY_DLL __declspec(dllexport)
4238
#else
43-
// static linking
44-
#define OZZ_GEOMETRY_DLL
39+
// import for dynamic linking when just using ozz
40+
#define OZZ_GEOMETRY_DLL __declspec(dllimport)
4541
#endif
42+
#else
43+
// static linking
44+
#define OZZ_GEOMETRY_DLL
45+
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
4646

4747
namespace ozz {
4848
namespace math {

include/ozz/options/options.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@
8383
#include <cstddef>
8484
#include <string>
8585

86-
#ifdef OZZ_USE_DYNAMIC_LINKING
87-
#ifdef OZZ_BUILD_OPTIONS_LIB
88-
// export for dynamic linking while building ozz
89-
#define OZZ_OPTIONS_DLL __declspec(dllexport)
90-
#else
91-
// import for dynamic linking when just using ozz
92-
#define OZZ_OPTIONS_DLL __declspec(dllimport)
93-
#endif()
86+
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
87+
#ifdef OZZ_BUILD_OPTIONS_LIB
88+
// export for dynamic linking while building ozz
89+
#define OZZ_OPTIONS_DLL __declspec(dllexport)
9490
#else
95-
// static linking
96-
#define OZZ_OPTIONS_DLL
91+
// import for dynamic linking when just using ozz
92+
#define OZZ_OPTIONS_DLL __declspec(dllimport)
9793
#endif
94+
#else
95+
// static linking
96+
#define OZZ_OPTIONS_DLL
97+
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
9898

9999
namespace ozz {
100100
namespace options {
@@ -121,8 +121,10 @@ enum ParseResult {
121121
// _version and _usage are not copied, ParseCommandLine caller is in charge of
122122
// maintaining their allocation during application lifetime.
123123
// See ParseResult for more details about returned values.
124-
OZZ_OPTIONS_DLL ParseResult ParseCommandLine(int _argc, const char* const* _argv,
125-
const char* _version, const char* _usage);
124+
OZZ_OPTIONS_DLL ParseResult ParseCommandLine(int _argc,
125+
const char* const* _argv,
126+
const char* _version,
127+
const char* _usage);
126128

127129
// Get the executable path that was extracted from the last call to
128130
// ParseCommandLine.

samples/additive/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ add_executable(sample_additive
2929
"${CMAKE_CURRENT_BINARY_DIR}/media/animation_splay_additive.ozz")
3030
target_link_libraries(sample_additive
3131
sample_framework)
32-
32+
target_copy_shared_libraries(sample_additive)
3333
set_target_properties(sample_additive
3434
PROPERTIES FOLDER "samples")
3535

samples/attach/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ add_executable(sample_attach
2121

2222
target_link_libraries(sample_attach
2323
sample_framework)
24-
24+
target_copy_shared_libraries(sample_attach)
2525
set_target_properties(sample_attach
2626
PROPERTIES FOLDER "samples")
2727

samples/baked/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_executable(sample_baked
2323

2424
target_link_libraries(sample_baked
2525
sample_framework)
26+
target_copy_shared_libraries(sample_baked)
2627

2728
set_target_properties(sample_baked
2829
PROPERTIES FOLDER "samples")

samples/blend/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_executable(sample_blend
3131

3232
target_link_libraries(sample_blend
3333
sample_framework)
34+
target_copy_shared_libraries(sample_blend)
3435

3536
set_target_properties(sample_blend
3637
PROPERTIES FOLDER "samples")

samples/demo.zip

4.77 KB
Binary file not shown.

samples/foot_ik/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_executable(sample_foot_ik
2929
"${CMAKE_CURRENT_BINARY_DIR}/media/floor.ozz")
3030
target_link_libraries(sample_foot_ik
3131
sample_framework)
32+
target_copy_shared_libraries(sample_foot_ik)
3233

3334
set_target_properties(sample_foot_ik
3435
PROPERTIES FOLDER "samples")

samples/framework/tools/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Adds fbx2mesh utility target.
22
if(ozz_build_fbx)
33

4-
# share meshes with thte sample framework
4+
# share meshes with the sample framework
55
add_executable(sample_fbx2mesh
66
fbx2mesh.cc
77
${PROJECT_SOURCE_DIR}/samples/framework/mesh.cc
88
${PROJECT_SOURCE_DIR}/samples/framework/mesh.h)
99
target_link_libraries(sample_fbx2mesh
1010
ozz_animation_fbx
1111
ozz_options)
12+
target_copy_shared_libraries(sample_fbx2mesh)
1213
set_target_properties(sample_fbx2mesh
1314
PROPERTIES FOLDER "samples/tools")
1415

samples/look_at/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_executable(sample_look_at
2525
"${CMAKE_CURRENT_BINARY_DIR}/media/mesh.ozz")
2626
target_link_libraries(sample_look_at
2727
sample_framework)
28+
target_copy_shared_libraries(sample_look_at)
2829

2930
set_target_properties(sample_look_at
3031
PROPERTIES FOLDER "samples")

samples/millipede/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ add_custom_command(
77
add_executable(sample_millipede
88
sample_millipede.cc
99
${CMAKE_CURRENT_BINARY_DIR}/README.md)
10-
1110
target_link_libraries(sample_millipede
1211
ozz_animation_offline
1312
sample_framework)
13+
target_copy_shared_libraries(sample_millipede)
1414

1515
set_target_properties(sample_millipede
1616
PROPERTIES FOLDER "samples")

0 commit comments

Comments
 (0)