[CMAKE] Support WITH_DBG and NO_DBG overrides in spec2def

This is to be able to build ucrtbase without debug and later ucrtbased with debug.
This commit is contained in:
Timo Kreuzer 2025-01-27 13:51:05 +02:00
parent 01cd8472c7
commit 6a4dbedd1e
2 changed files with 19 additions and 20 deletions

View file

@ -431,16 +431,11 @@ function(fixup_load_config _target)
DEPENDS native-pefixup)
endfunction()
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(__spec2def_dbg_arg "--dbg")
endif()
function(generate_import_lib _libname _dllname _spec_file __version_arg)
function(generate_import_lib _libname _dllname _spec_file __version_arg __dbg_arg)
# Generate the def for the import lib
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
COMMAND native-spec2def ${__version_arg} ${__spec2def_dbg_arg} -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def ${__version_arg} ${__dbg_arg} -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
# With this, we let DLLTOOL create an import library
@ -490,7 +485,7 @@ endfunction()
function(spec2def _dllname _spec_file)
cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY;WITH_DBG;NO_DBG" "VERSION" "" ${ARGN})
# Get library basename
get_filename_component(_file ${_dllname} NAME_WE)
@ -510,10 +505,14 @@ function(spec2def _dllname _spec_file)
set(__version_arg "--version=${DLL_EXPORT_VERSION}")
endif()
if(__spec2def_WITH_DBG OR (DBG AND NOT __spec2def_NO_DBG))
set(__dbg_arg "--dbg")
endif()
# Generate exports def and C stubs file for the DLL
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${__spec2def_dbg_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${__dbg_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
# Do not use precompiled headers for the stub file
@ -525,7 +524,7 @@ function(spec2def _dllname _spec_file)
set(_extraflags --no-private-warnings)
endif()
generate_import_lib(lib${_file} ${_dllname} ${_spec_file} ${_extraflags} "${__version_arg}")
generate_import_lib(lib${_file} ${_dllname} ${_spec_file} ${_extraflags} "${__version_arg}" "${__dbg_arg}")
endif()
endfunction()

View file

@ -332,12 +332,7 @@ function(fixup_load_config _target)
# msvc knows how to generate a load_config so no hacks here
endfunction()
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(__spec2def_dbg_arg "--dbg")
endif()
function(generate_import_lib _libname _dllname _spec_file __version_arg)
function(generate_import_lib _libname _dllname _spec_file __version_arg __dbg_arg)
set(_def_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
set(_asm_stubs_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_stubs.asm)
@ -346,7 +341,7 @@ function(generate_import_lib _libname _dllname _spec_file __version_arg)
# Generate the def, asm stub and alias files
add_custom_command(
OUTPUT ${_asm_stubs_file} ${_def_file} ${_asm_impalias_file}
COMMAND native-spec2def --ms ${__version_arg} ${__spec2def_dbg_arg} -a=${SPEC2DEF_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} -i=${_asm_impalias_file} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def --ms ${__version_arg} ${__dbg_arg} -a=${SPEC2DEF_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} -i=${_asm_impalias_file} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
# Compile the generated asm stub file
@ -394,9 +389,10 @@ elseif(ARCH STREQUAL "arm64")
else()
set(SPEC2DEF_ARCH i386)
endif()
function(spec2def _dllname _spec_file)
cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY;WITH_DBG;NO_DBG" "VERSION" "" ${ARGN})
# Get library basename
get_filename_component(_file ${_dllname} NAME_WE)
@ -416,17 +412,21 @@ function(spec2def _dllname _spec_file)
set(__version_arg "--version=${DLL_EXPORT_VERSION}")
endif()
if(__spec2def_WITH_DBG OR (DBG AND NOT __spec2def_NO_DBG))
set(__dbg_arg "--dbg")
endif()
# Generate exports def and C stubs file for the DLL
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${__spec2def_dbg_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${__dbg_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
# Do not use precompiled headers for the stub file
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
if(__spec2def_ADD_IMPORTLIB)
generate_import_lib(lib${_file} ${_dllname} ${_spec_file} "${__version_arg}")
generate_import_lib(lib${_file} ${_dllname} ${_spec_file} "${__version_arg}" "${__dbg_arg}")
if(__spec2def_NO_PRIVATE_WARNINGS)
set_property(TARGET lib${_file} APPEND PROPERTY STATIC_LIBRARY_OPTIONS /ignore:4104)
endif()