Skip to content

Commit

Permalink
Fix cabextract CMake build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
micahsnyder committed Jun 8, 2020
1 parent 4954e03 commit 190b899
Show file tree
Hide file tree
Showing 5 changed files with 1,214 additions and 10 deletions.
31 changes: 21 additions & 10 deletions cabextract/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,32 @@ add_executable(cabextract)
target_sources(cabextract
PRIVATE
src/cabextract.c
getopt.c getopt.h
getopt1.c
md5.h md5.c)
if(NOT WIN32)
target_include_directories(cabextract PRIVATE ${PROJECT_SOURCE_DIR})
else()
target_include_directories(cabextract PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/win32)
target_sources(cabextract PRIVATE win32/dirent.h)
target_link_libraries(cabextract Shlwapi.lib)
endif()
target_include_directories(cabextract PRIVATE ${PROJECT_SOURCE_DIR})
target_link_libraries(cabextract MSPack::mspack)
install(TARGETS cabextract DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(cabinfo)
target_sources(cabinfo
PRIVATE
src/cabinfo.c)
target_include_directories(cabinfo PRIVATE ${PROJECT_SOURCE_DIR})
target_link_libraries(cabinfo MSPack::mspack)

enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
add_subdirectory(test)
if(NOT WIN32)
add_executable(cabinfo)
target_sources(cabinfo
PRIVATE
src/cabinfo.c)
target_include_directories(cabinfo PRIVATE ${PROJECT_SOURCE_DIR})
target_link_libraries(cabinfo MSPack::mspack)

enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
add_subdirectory(test)
endif()

#
# The Summary Info.
Expand Down
22 changes: 22 additions & 0 deletions cabextract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,25 @@ cmake --build . --config Release
ctest -C Release -V
cmake --build . --config Release --target install
```
#### Windows=specific build instructions
A build using the bundled mspack files won't work on Windows for a couple of reasons. Instead, you can build cabextract on Windows by first building libmspack and then build cabextract using the ENABLE_EXTERNAL_MSPACK option.
In the example below, we use build and link with the static libmspack library so we don't have to copy mspack.dll into the cabextract.exe directory.
In the libmspack directory:
```ps1
mkdir build ; if($?) {cd build}
cmake -DCMAKE_INSTALL_PREFIX:PATH=install .. -DENABLE_STATIC_LIB=ON
cmake --build . --config Release --target install
```
Then in the cabextract directory something like this*:
```ps1
mkdir build ; if($?) {cd build}
cmake .. -DENABLE_EXTERNAL_MSPACK=ON -DMSPack_INCLUDE_DIR="C:\Users\...\libmspack\build\install\include" -DMSPack_LIBRARY="C:\Users\...\libmspack\install\lib\mspack_static.lib"
cmake --build . --config Debug
.\Debug\cabextract.exe --help

*Important*: set the `MSPack_INCLUDE_DIR` and `MSPack_LIBRARY` variables to your mspack `include` directory and `mspack_static.lib` file
8 changes: 8 additions & 0 deletions cabextract/src/cabextract.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#ifndef _WIN32
#include <fnmatch.h>
#else
#include <shlwapi.h>
#endif
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
Expand Down Expand Up @@ -473,7 +477,11 @@ static int process_cabinet(char *basename) {
int matched = 0;
struct filter *f;
for (f = args.filters; f; f = f->next) {
#ifndef _WIN32
if (!fnmatch(f->filter, &name[fname_offset], FNM_CASEFOLD)) {
#else
if (TRUE == PathMatchSpecA(&name[fname_offset], f->filter)) {
#endif
matched = 1;
break;
}
Expand Down
Loading

0 comments on commit 190b899

Please sign in to comment.