Windows: Create import library from .def file and no sources
CMake does not currently model something like add_library(foo SHARED foo.def)
, with no other sources, to produce a .lib
import library on Windows without running a linker to produce the corresponding .dll
or .exe
file.
Original Description
I have a project that builds node.lib
with custom .def file (my compiler is MSVC)
project(nodelib)
add_custom_target(nodelib_def ALL
COMMAND ${NODEJS_EXECUTABLE} ${CMAKE_SOURCE_DIR}/generateNodeLibDef.js
COMMENT "Generating .def file"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(nodelib ALL
COMMAND ${CMAKE_AR}
/def:${CMAKE_SOURCE_DIR}/node.def
/out:${CMAKE_BINARY_DIR}/node.lib
${CMAKE_STATIC_LINKER_FLAGS}
DEPENDS ${CMAKE_JS_NODELIB_DEF}
COMMENT "Building node.lib"
)
add_dependencies(nodelib nodelib_def)
install(FILES ${CMAKE_BINARY_DIR}/node.lib DESTINATION lib)
I'm trying to rewrite add_custom_target
with add_library
:
add_library(node STATIC)
set_target_properties(node PROPERTIES LINK_FLAGS "/def:${CMAKE_SOURCE_DIR}/node.def")
I'm getting the following error:
CMake Error at C:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake:623 (_add_library):
No SOURCES given to target: node
Call Stack (most recent call first):
CMakeLists.txt:10 (add_library)
CMake Generate step failed. Build files cannot be regenerated correctly.
ninja: build stopped: subcommand failed.
Can I somehow use add_library
? Maybe there is something I'm missing
Edited by Brad King