mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 18:42:56 +00:00
[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
This commit is contained in:
parent
b398f3fe30
commit
7c9159f25f
3 changed files with 37 additions and 65 deletions
|
@ -271,7 +271,7 @@ function(add_importlibs _module)
|
||||||
add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
|
add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
|
||||||
target_link_libraries(${_module} msvcrtex)
|
target_link_libraries(${_module} msvcrtex)
|
||||||
endif()
|
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_dependencies(${_module} lib${LIB})
|
||||||
add_dependency_edge(${_module} ${LIB})
|
add_dependency_edge(${_module} ${LIB})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
|
@ -182,8 +182,7 @@ endfunction()
|
||||||
|
|
||||||
function(add_delay_importlibs MODULE)
|
function(add_delay_importlibs MODULE)
|
||||||
foreach(LIB ${ARGN})
|
foreach(LIB ${ARGN})
|
||||||
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}_delayed.a)
|
target_link_libraries(${MODULE} lib${LIB}_delayed)
|
||||||
add_dependencies(${MODULE} lib${LIB}_delayed)
|
|
||||||
endforeach()
|
endforeach()
|
||||||
target_link_libraries(${MODULE} delayimp)
|
target_link_libraries(${MODULE} delayimp)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -192,50 +191,32 @@ if(NOT ARCH MATCHES i386)
|
||||||
set(DECO_OPTION "-@")
|
set(DECO_OPTION "-@")
|
||||||
endif()
|
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)
|
function(add_importlib_target _exports_file _implib_name)
|
||||||
|
|
||||||
get_filename_component(_name ${_exports_file} NAME_WE)
|
get_filename_component(_name ${_exports_file} NAME_WE)
|
||||||
get_filename_component(_extension ${_exports_file} EXT)
|
get_filename_component(_extension ${_exports_file} EXT)
|
||||||
|
|
||||||
if(${_extension} STREQUAL ".spec")
|
if(${_extension} STREQUAL ".spec")
|
||||||
|
|
||||||
# Normal importlib creation
|
# generate .def
|
||||||
add_custom_command(
|
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 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)
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} native-spec2def)
|
||||||
|
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
|
||||||
|
|
||||||
# Delayed importlib creation
|
#create normal importlib
|
||||||
add_custom_command(
|
add_library(lib${_name} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def)
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_delayed.a
|
set_target_properties(lib${_name} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
|
||||||
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")
|
#create delayed importlib
|
||||||
message("Use of def files for import libs is deprecated: ${_exports_file}")
|
add_library(lib${_name}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def)
|
||||||
add_custom_command(
|
set_target_properties(lib${_name}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
|
||||||
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})
|
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unsupported exports file extension: ${_extension}")
|
message(FATAL_ERROR "Unsupported exports file extension: ${_extension}")
|
||||||
endif()
|
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()
|
endfunction()
|
||||||
|
|
||||||
function(spec2def _dllname _spec_file)
|
function(spec2def _dllname _spec_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)
|
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()
|
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
|
# Thanks MS for creating a stupid linker
|
||||||
function(add_importlib_target _exports_file _implib_name)
|
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
|
# Generate the asm stub file and the export def file
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def
|
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_BINARY_DIR}/importlibs/lib${_name}_exp.def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
|
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)
|
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 our library
|
||||||
add_custom_command(
|
# NOTE: as stub file and def file are generated in one pass, depending on one is like depending on the other
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj
|
add_library(lib${_name} STATIC
|
||||||
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
|
${CMAKE_CURRENT_BINARY_DIR}/lib${_name}_stubs.asm)
|
||||||
DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm")
|
|
||||||
|
|
||||||
# Add neccessary importlibs for redirections
|
# Add necessary importlibs for redirections. Still necessary ?
|
||||||
set(_libraries "")
|
if(ARGN)
|
||||||
set(_dependencies "")
|
target_link_libraries(lib${_name} ${ARGN})
|
||||||
foreach(_lib ${ARGN})
|
endif()
|
||||||
list(APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib")
|
|
||||||
list(APPEND _dependencies ${_lib})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Build the importlib
|
# set correct link rule
|
||||||
add_custom_command(
|
set_target_properties(lib${_name} PROPERTIES LINKER_LANGUAGE "IMPLIB"
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
|
STATIC_LIBRARY_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}\\lib${_name}_exp.def")
|
||||||
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})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
macro(add_delay_importlibs MODULE)
|
macro(add_delay_importlibs MODULE)
|
||||||
foreach(LIB ${ARGN})
|
foreach(LIB ${ARGN})
|
||||||
add_target_link_flags(${MODULE} "/DELAYLOAD:${LIB}.dll")
|
add_target_link_flags(${MODULE} "/DELAYLOAD:${LIB}.dll")
|
||||||
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.LIB)
|
target_link_libraries(${MODULE} lib${LIB})
|
||||||
add_dependencies(${MODULE} lib${LIB})
|
|
||||||
endforeach()
|
endforeach()
|
||||||
target_link_libraries(${MODULE} delayimp)
|
target_link_libraries(${MODULE} delayimp)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue