- 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
This commit is contained in:
Jérôme Gardou 2012-02-21 14:32:05 +00:00
parent b398f3fe30
commit 7c9159f25f
3 changed files with 37 additions and 65 deletions

View file

@ -271,7 +271,7 @@ function(add_importlibs _module)
add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
target_link_libraries(${_module} msvcrtex)
endif()
target_link_libraries(${_module} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}${CMAKE_STATIC_LIBRARY_SUFFIX})
target_link_libraries(${_module} lib${LIB})
add_dependencies(${_module} lib${LIB})
add_dependency_edge(${_module} ${LIB})
endforeach()

View file

@ -182,8 +182,7 @@ endfunction()
function(add_delay_importlibs MODULE)
foreach(LIB ${ARGN})
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}_delayed.a)
add_dependencies(${MODULE} lib${LIB}_delayed)
target_link_libraries(${MODULE} lib${LIB}_delayed)
endforeach()
target_link_libraries(${MODULE} delayimp)
endfunction()
@ -192,50 +191,32 @@ if(NOT ARCH MATCHES i386)
set(DECO_OPTION "-@")
endif()
# Cute little hack to produce import libs
set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-lib=<TARGET>")
set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-delaylib=<TARGET>")
function(add_importlib_target _exports_file _implib_name)
get_filename_component(_name ${_exports_file} NAME_WE)
get_filename_component(_extension ${_exports_file} EXT)
if(${_extension} STREQUAL ".spec")
# Normal importlib creation
# generate .def
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def
COMMAND native-spec2def -n=${_implib_name} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
# Delayed importlib creation
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
COMMAND native-spec2def -n=${_implib_name} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_name}_delayed_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}_delayed_implib.def --kill-at --output-delaylib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
elseif(${_extension} STREQUAL ".def")
message("Use of def files for import libs is deprecated: ${_exports_file}")
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} --kill-at --output-delaylib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
#create normal importlib
add_library(lib${_name} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def)
set_target_properties(lib${_name} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
#create delayed importlib
add_library(lib${_name}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def)
set_target_properties(lib${_name}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
else()
message(FATAL_ERROR "Unsupported exports file extension: ${_extension}")
endif()
# Normal importlib target
add_custom_target(
lib${_name}
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a)
# Delayed importlib target
add_custom_target(
lib${_name}_delayed
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a)
endfunction()
function(spec2def _dllname _spec_file)

View file

@ -131,6 +131,9 @@ function(set_rc_compiler)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_result_defs} /I${CMAKE_CURRENT_SOURCE_DIR} ${rc_result_incs} /fo <OBJECT> <SOURCE>" PARENT_SCOPE)
endfunction()
#define those for having real libraries
set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "LINK /LIB /NOLOGO <LINK_FLAGS> /OUT:<TARGET> <OBJECTS>")
# Thanks MS for creating a stupid linker
function(add_importlib_target _exports_file _implib_name)
@ -138,43 +141,31 @@ function(add_importlib_target _exports_file _implib_name)
# Generate the asm stub file and the export def file
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def
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}
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm ${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_exp.def
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}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
# be clear about the language
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm PROPERTIES LANGUAGE "ASM")
# Assemble the stub file
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj
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
DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm")
# Add neccessary importlibs for redirections
set(_libraries "")
set(_dependencies "")
foreach(_lib ${ARGN})
list(APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib")
list(APPEND _dependencies ${_lib})
endforeach()
# Build the importlib
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
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}
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def)
# Add the importlib target
add_custom_target(
lib${_name}
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib)
add_dependencies(lib${_name} asm ${_dependencies})
# add our library
# NOTE: as stub file and def file are generated in one pass, depending on one is like depending on the other
add_library(lib${_name} STATIC
${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm)
# Add necessary importlibs for redirections. Still necessary ?
if(ARGN)
target_link_libraries(lib${_name} ${ARGN})
endif()
# set correct link rule
set_target_properties(lib${_name} PROPERTIES LINKER_LANGUAGE "IMPLIB"
STATIC_LIBRARY_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}\\lib${_name}_exp.def")
endfunction()
macro(add_delay_importlibs MODULE)
foreach(LIB ${ARGN})
add_target_link_flags(${MODULE} "/DELAYLOAD:${LIB}.dll")
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.LIB)
add_dependencies(${MODULE} lib${LIB})
target_link_libraries(${MODULE} lib${LIB})
endforeach()
target_link_libraries(${MODULE} delayimp)
endmacro()