@@ -40,76 +40,18 @@ function(bundle_static_library tgt_name bundled_tgt_name library_name)
40
40
list (REMOVE_DUPLICATES static_libs)
41
41
list (REMOVE_DUPLICATES dep_libs)
42
42
43
- set (bundled_tgt_full_name
44
- ${CMAKE_BINARY_DIR} /${CMAKE_STATIC_LIBRARY_PREFIX}${library_name}${CMAKE_STATIC_LIBRARY_SUFFIX} )
45
-
46
- if (APPLE )
47
- find_program (lib_tool libtool REQUIRED)
48
-
49
- foreach (tgt IN LISTS static_libs)
50
- list (APPEND static_libs_full_names $<TARGET_FILE:${tgt} >)
51
- endforeach ()
52
-
53
- add_custom_command (
54
- COMMAND ${lib_tool} -static -o ${bundled_tgt_full_name} ${static_libs_full_names}
55
- OUTPUT ${bundled_tgt_full_name}
56
- COMMENT "Bundling ${bundled_tgt_name} "
57
- VERBATIM )
58
- elseif (UNIX OR MINGW)
59
- file (WRITE ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar.in
60
- "CREATE ${bundled_tgt_full_name} \n " )
61
-
62
- foreach (tgt IN LISTS static_libs)
63
- file (APPEND ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar.in
64
- "ADDLIB $<TARGET_FILE:${tgt} >\n " )
65
- endforeach ()
66
-
67
- file (APPEND ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar.in "SAVE\n " )
68
- file (APPEND ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar.in "END\n " )
69
-
70
- file (GENERATE
71
- OUTPUT ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar
72
- INPUT ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar.in)
73
-
74
- set (ar_tool ${CMAKE_AR} )
75
- if (CMAKE_INTERPROCEDURAL_OPTIMIZATION)
76
- set (ar_tool ${CMAKE_CXX_COMPILER_AR} )
77
- endif ()
78
-
79
- add_custom_command (
80
- COMMAND ${ar_tool} -M < ${CMAKE_BINARY_DIR} /${bundled_tgt_name} .ar
81
- OUTPUT ${bundled_tgt_full_name}
82
- COMMENT "Bundling ${bundled_tgt_name} "
83
- VERBATIM )
84
- elseif (WIN32 )
85
- # https://stackoverflow.com/a/38096930/1806760
86
- get_filename_component (vs_bin_path "${CMAKE_LINKER} " DIRECTORY )
87
-
88
- find_program (lib_tool lib HINTS "${vs_bin_path} " REQUIRED)
89
-
90
- foreach (tgt IN LISTS static_libs)
91
- list (APPEND static_libs_full_names $<TARGET_FILE:${tgt} >)
92
- endforeach ()
93
-
94
- add_custom_command (
95
- COMMAND ${lib_tool} /NOLOGO /OUT:${bundled_tgt_full_name} ${static_libs_full_names}
96
- OUTPUT ${bundled_tgt_full_name}
97
- COMMENT "Bundling ${bundled_tgt_name} "
98
- VERBATIM )
99
- else ()
100
- message (FATAL_ERROR "Unknown bundle scenario!" )
101
- endif ()
102
-
103
- add_custom_target (bundling_target ALL DEPENDS ${bundled_tgt_full_name} )
104
- add_dependencies (bundling_target ${tgt_name} )
105
-
106
- add_library (${bundled_tgt_name} STATIC IMPORTED )
107
- set_target_properties (${bundled_tgt_name}
108
- PROPERTIES
109
- IMPORTED_LOCATION ${bundled_tgt_full_name}
110
- INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${tgt_name} ,INTERFACE_INCLUDE_DIRECTORIES >
111
- INTERFACE_LINK_LIBRARIES "${dep_libs} " )
112
- #IMPORTED_LINK_INTERFACE_LIBRARIES "${dep_libs}") # Deprecated
113
- add_dependencies (${bundled_tgt_name} bundling_target)
114
-
115
- endfunction ()
43
+ foreach (tgt IN LISTS static_libs)
44
+ list (APPEND static_libs_objects $<TARGET_OBJECTS:${tgt} >)
45
+ endforeach ()
46
+
47
+ add_library (${bundled_tgt_name} STATIC ${static_libs_objects} )
48
+ set_target_properties (${bundled_tgt_name} PROPERTIES
49
+ INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${tgt_name} ,INTERFACE_INCLUDE_DIRECTORIES >
50
+ INTERFACE_LINK_LIBRARIES "${dep_libs} "
51
+ OUTPUT_NAME "${library_name} "
52
+ SYMLINK_NAME "${library_name} .o"
53
+ )
54
+ add_custom_command (TARGET ${bundled_tgt_name} POST_BUILD
55
+ COMMAND ${CMAKE_COMMAND} -E create_symlink "$<TARGET_FILE_NAME:${bundled_tgt_name} >" "$<TARGET_FILE_DIR:${bundled_tgt_name} >/$<TARGET_PROPERTY:${bundled_tgt_name} ,SYMLINK_NAME>"
56
+ )
57
+ endfunction ()
0 commit comments