Skip to content

Commit cff38f4

Browse files
authored
Fix shared library install on Windows: place DLLs in bin directory (#3225)
### Description of changes: CMake classifies DLL files as `RUNTIME` artifacts, not `LIBRARY` artifacts. Our install rules only specified `LIBRARY DESTINATION` and `ARCHIVE DESTINATION`, so `cmake --install` was silently skipping the DLL files on Windows. This adds `RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}` to the install rules for both `crypto` and `ssl`. On non-Windows platforms the clause is harmlessly ignored since `.so`/`.dylib` are `LIBRARY` type. ### Testing: Added a `build_and_install` step to `run_windows_tests.bat` that builds with `BUILD_SHARED_LIBS=1`, runs `cmake --install`, and asserts that `crypto.dll` and `ssl.dll` are present in the install prefix's `bin/` directory. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 4ab2b63 commit cff38f4

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

crypto/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,14 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.12")
916916
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
917917
LIBRARY
918918
DESTINATION ${CMAKE_INSTALL_LIBDIR}
919-
NAMELINK_COMPONENT Development)
919+
NAMELINK_COMPONENT Development
920+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
920921
else()
921922
install(TARGETS crypto
922923
EXPORT crypto-targets
923924
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
924-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
925+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
926+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
925927
endif()
926928

927929
if(MSVC AND CMAKE_BUILD_TYPE_LOWER MATCHES "relwithdebinfo" AND FIPS)

ssl/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.12")
118118
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
119119
LIBRARY
120120
DESTINATION ${CMAKE_INSTALL_LIBDIR}
121-
NAMELINK_COMPONENT Development)
121+
NAMELINK_COMPONENT Development
122+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
122123
else()
123124
install(TARGETS ssl
124125
EXPORT ssl-targets
125126
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
126-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
127+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
128+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
127129
endif()
128130

129131
if(MSVC AND CMAKE_BUILD_TYPE_LOWER MATCHES "relwithdebinfo" AND FIPS)

tests/ci/run_windows_tests.bat

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ call :build_and_test Release "-DOPENSSL_NO_ASM=1" || goto error
4040
@rem tests or copy them around so Windows can find it in the same directory. Instead just put the dll's location onto the path
4141
set PATH=%BUILD_DIR%;%BUILD_DIR%\crypto;%BUILD_DIR%\ssl;%PATH%
4242
call :build_and_test Release "-DBUILD_SHARED_LIBS=1" || goto error
43+
@rem Reuse the build tree from the preceding shared build to verify that
44+
@rem `cmake --install` places DLLs in bin/ and import libraries in lib/.
45+
call :verify_install || goto error
4346
call :build_and_test Release "-DBUILD_SHARED_LIBS=1 -DFIPS=1" || goto error
4447
if /i not "%ARCH_OPTION%" == "arm64" (
4548
@rem For FIPS on Windows/x86-64 we also have a RelWithDebInfo build to generate debug symbols.
@@ -110,3 +113,37 @@ exit /b %errorlevel%
110113
:error
111114
echo Failed with error #%errorlevel%.
112115
exit /b 1
116+
117+
@rem Runs `cmake --install` against the already-configured %BUILD_DIR% and
118+
@rem verifies that the expected shared-library artifacts land in the
119+
@rem conventional Windows install layout: DLLs in bin/, import libs in lib/.
120+
@rem Assumes the caller has already done a BUILD_SHARED_LIBS=1 build.
121+
:verify_install
122+
@echo on
123+
set INSTALL_DIR=%TEMP%\awslc_install
124+
rmdir /s /q "%INSTALL_DIR%" 2>nul
125+
126+
@echo LOG: %date%-%time% running cmake install into %INSTALL_DIR%
127+
cmake --install "%BUILD_DIR%" --prefix "%INSTALL_DIR%" || goto error
128+
129+
@echo LOG: %date%-%time% verifying install layout
130+
dir "%INSTALL_DIR%\bin\"
131+
dir "%INSTALL_DIR%\lib\"
132+
if not exist "%INSTALL_DIR%\bin\crypto.dll" (
133+
echo ERROR: crypto.dll not found in %INSTALL_DIR%\bin\
134+
goto error
135+
)
136+
if not exist "%INSTALL_DIR%\bin\ssl.dll" (
137+
echo ERROR: ssl.dll not found in %INSTALL_DIR%\bin\
138+
goto error
139+
)
140+
if not exist "%INSTALL_DIR%\lib\crypto.lib" (
141+
echo ERROR: crypto.lib not found in %INSTALL_DIR%\lib\
142+
goto error
143+
)
144+
if not exist "%INSTALL_DIR%\lib\ssl.lib" (
145+
echo ERROR: ssl.lib not found in %INSTALL_DIR%\lib\
146+
goto error
147+
)
148+
@echo LOG: %date%-%time% install verification passed
149+
exit /b 0

0 commit comments

Comments
 (0)