-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
86 lines (79 loc) · 3.2 KB
/
CMakeLists.txt
File metadata and controls
86 lines (79 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
cmake_minimum_required(VERSION 3.27)
project(Examples)
# Install and make available nlohmann_json
include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
FetchContent_MakeAvailable(json)
# Function to setup runtime dependencies for any target
function(setup_c2pa_runtime_deps target_name)
# Copy C shared library to executable directory on all platforms
if(DEFINED C2PA_C_LIB)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${C2PA_C_LIB}"
$<TARGET_FILE_DIR:${target_name}>
COMMENT "Copying c2pa_c library to ${target_name} directory"
)
endif()
# When c2pa_cpp is SHARED, copy it next to the executable (same as consumers)
if(TARGET c2pa_cpp)
get_target_property(c2pa_cpp_type c2pa_cpp TYPE)
if(c2pa_cpp_type STREQUAL "SHARED_LIBRARY")
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:c2pa_cpp>
$<TARGET_FILE_DIR:${target_name}>
COMMENT "Copying c2pa_cpp library to ${target_name} directory"
)
endif()
endif()
# On Linux, set RPATH to look in the executable's directory
if(UNIX AND NOT APPLE)
set_target_properties(${target_name} PROPERTIES
BUILD_RPATH "$ORIGIN"
INSTALL_RPATH "$ORIGIN"
BUILD_WITH_INSTALL_RPATH TRUE
)
# Force override any inherited RPATH
set_property(TARGET ${target_name} PROPERTY BUILD_RPATH "$ORIGIN")
set_property(TARGET ${target_name} PROPERTY INSTALL_RPATH "$ORIGIN")
endif()
# On macOS, override the RPATH to remove hardcoded paths
if(APPLE)
set_target_properties(${target_name} PROPERTIES
BUILD_RPATH "@executable_path"
INSTALL_RPATH "@executable_path"
BUILD_WITH_INSTALL_RPATH TRUE
)
# Force override any inherited RPATH
set_property(TARGET ${target_name} PROPERTY BUILD_RPATH "@executable_path")
set_property(TARGET ${target_name} PROPERTY INSTALL_RPATH "@executable_path")
endif()
endfunction()
# Example executables (link to shared c2pa_cpp + C lib, same deployment as consumers)
add_executable(training training.cpp)
if(WIN32)
target_link_libraries(training PRIVATE nlohmann_json::nlohmann_json c2pa_cpp "${C2PA_C_IMPLIB}")
else()
target_link_libraries(training PRIVATE nlohmann_json::nlohmann_json c2pa_cpp "${C2PA_C_LIB}")
endif()
if(NOT MSVC)
target_compile_options(training PRIVATE -Wno-deprecated-declarations)
endif()
if(MSVC)
target_compile_options(training PRIVATE /wd4996)
endif()
setup_c2pa_runtime_deps(training)
add_executable(demo demo.cpp)
if(WIN32)
target_link_libraries(demo PRIVATE nlohmann_json::nlohmann_json c2pa_cpp "${C2PA_C_IMPLIB}")
else()
target_link_libraries(demo PRIVATE nlohmann_json::nlohmann_json c2pa_cpp "${C2PA_C_LIB}")
endif()
if(NOT MSVC)
target_compile_options(demo PRIVATE -Wno-deprecated-declarations)
endif()
if(MSVC)
target_compile_options(demo PRIVATE /wd4996)
endif()
setup_c2pa_runtime_deps(demo)