Skip to content

Commit 7c9159f

Browse files
committed
[CMAKE]
- generate 'real' libraries for import libraries This way only the link step relies on them. Should avoid rebuilding half of the tree next time Alex changes ntdll.spec A relinking orgy is more than enough svn path=/trunk/; revision=55776
1 parent b398f3f commit 7c9159f

File tree

3 files changed

+37
-65
lines changed

3 files changed

+37
-65
lines changed

reactos/cmake/CMakeMacros.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function(add_importlibs _module)
271271
add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
272272
target_link_libraries(${_module} msvcrtex)
273273
endif()
274-
target_link_libraries(${_module} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}${CMAKE_STATIC_LIBRARY_SUFFIX})
274+
target_link_libraries(${_module} lib${LIB})
275275
add_dependencies(${_module} lib${LIB})
276276
add_dependency_edge(${_module} ${LIB})
277277
endforeach()

reactos/cmake/gcc.cmake

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ endfunction()
182182

183183
function(add_delay_importlibs MODULE)
184184
foreach(LIB ${ARGN})
185-
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}_delayed.a)
186-
add_dependencies(${MODULE} lib${LIB}_delayed)
185+
target_link_libraries(${MODULE} lib${LIB}_delayed)
187186
endforeach()
188187
target_link_libraries(${MODULE} delayimp)
189188
endfunction()
@@ -192,50 +191,32 @@ if(NOT ARCH MATCHES i386)
192191
set(DECO_OPTION "-@")
193192
endif()
194193

194+
# Cute little hack to produce import libs
195+
set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-lib=<TARGET>")
196+
set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-delaylib=<TARGET>")
195197
function(add_importlib_target _exports_file _implib_name)
196-
197198
get_filename_component(_name ${_exports_file} NAME_WE)
198199
get_filename_component(_extension ${_exports_file} EXT)
199200

200201
if(${_extension} STREQUAL ".spec")
201202

202-
# Normal importlib creation
203+
# generate .def
203204
add_custom_command(
204-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
205+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def
205206
COMMAND native-spec2def -n=${_implib_name} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
206-
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
207207
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
208-
209-
# Delayed importlib creation
210-
add_custom_command(
211-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
212-
COMMAND native-spec2def -n=${_implib_name} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_name}_delayed_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
213-
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}_delayed_implib.def --kill-at --output-delaylib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
214-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
215-
216-
elseif(${_extension} STREQUAL ".def")
217-
message("Use of def files for import libs is deprecated: ${_exports_file}")
218-
add_custom_command(
219-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
220-
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
221-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})
222-
add_custom_command(
223-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
224-
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} --kill-at --output-delaylib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
225-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})
208+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
209+
210+
#create normal importlib
211+
add_library(lib${_name} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def)
212+
set_target_properties(lib${_name} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
213+
214+
#create delayed importlib
215+
add_library(lib${_name}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def)
216+
set_target_properties(lib${_name}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
226217
else()
227218
message(FATAL_ERROR "Unsupported exports file extension: ${_extension}")
228219
endif()
229-
230-
# Normal importlib target
231-
add_custom_target(
232-
lib${_name}
233-
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a)
234-
# Delayed importlib target
235-
add_custom_target(
236-
lib${_name}_delayed
237-
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a)
238-
239220
endfunction()
240221

241222
function(spec2def _dllname _spec_file)

reactos/cmake/msvc.cmake

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -131,50 +131,41 @@ function(set_rc_compiler)
131131
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_result_defs} /I${CMAKE_CURRENT_SOURCE_DIR} ${rc_result_incs} /fo <OBJECT> <SOURCE>" PARENT_SCOPE)
132132
endfunction()
133133

134+
#define those for having real libraries
135+
set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "LINK /LIB /NOLOGO <LINK_FLAGS> /OUT:<TARGET> <OBJECTS>")
136+
134137
# Thanks MS for creating a stupid linker
135138
function(add_importlib_target _exports_file _implib_name)
136139

137140
get_filename_component(_name ${_exports_file} NAME_WE)
138141

139142
# Generate the asm stub file and the export def file
140143
add_custom_command(
141-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def
142-
COMMAND native-spec2def --ms --kill-at -a=${SPEC2DEF_ARCH} --implib -n=${_implib_name} -d=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
144+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm ${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_exp.def
145+
COMMAND native-spec2def --ms --kill-at -a=${SPEC2DEF_ARCH} --implib -n=${_implib_name} -d=${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_exp.def -l=${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
143146
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
147+
# be clear about the language
148+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm PROPERTIES LANGUAGE "ASM")
144149

145-
# Assemble the stub file
146-
add_custom_command(
147-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj
148-
COMMAND ${CMAKE_ASM_COMPILER} /nologo /Cp /Fo${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj /c /Ta ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm
149-
DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm")
150-
151-
# Add neccessary importlibs for redirections
152-
set(_libraries "")
153-
set(_dependencies "")
154-
foreach(_lib ${ARGN})
155-
list(APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib")
156-
list(APPEND _dependencies ${_lib})
157-
endforeach()
158-
159-
# Build the importlib
160-
add_custom_command(
161-
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
162-
COMMAND LINK /LIB /NOLOGO /DEF:${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${_libraries}
163-
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def)
164-
165-
# Add the importlib target
166-
add_custom_target(
167-
lib${_name}
168-
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib)
169-
170-
add_dependencies(lib${_name} asm ${_dependencies})
150+
# add our library
151+
# NOTE: as stub file and def file are generated in one pass, depending on one is like depending on the other
152+
add_library(lib${_name} STATIC
153+
${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm)
154+
155+
# Add necessary importlibs for redirections. Still necessary ?
156+
if(ARGN)
157+
target_link_libraries(lib${_name} ${ARGN})
158+
endif()
159+
160+
# set correct link rule
161+
set_target_properties(lib${_name} PROPERTIES LINKER_LANGUAGE "IMPLIB"
162+
STATIC_LIBRARY_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}\\lib${_name}_exp.def")
171163
endfunction()
172164

173165
macro(add_delay_importlibs MODULE)
174166
foreach(LIB ${ARGN})
175167
add_target_link_flags(${MODULE} "/DELAYLOAD:${LIB}.dll")
176-
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.LIB)
177-
add_dependencies(${MODULE} lib${LIB})
168+
target_link_libraries(${MODULE} lib${LIB})
178169
endforeach()
179170
target_link_libraries(${MODULE} delayimp)
180171
endmacro()

0 commit comments

Comments
 (0)