From f1979a74d96a0ed31e4e4ba9674d3131a08a3574 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Sat, 26 Sep 2020 18:42:25 +0100 Subject: [PATCH] Windows build now working properly Was opening PNG files (which are binary...) with `r` instead of `rb` which caused problems on windows Added `libsndfile-1` back into FindLibSndFile.cmake, since it's needed Package `sndfile.dll` instead of `libsndfile-1.dll` since thats what the binary looks for --- .gitignore | 16 ++++++++-------- CMakeLists.txt | 4 ++-- README.md | 4 ++-- build_windows.sh | 1 + cmake/FindLibSndFile.cmake | 2 +- src/pngio.c | 7 ++++--- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 9605959..85d013c 100644 --- a/.gitignore +++ b/.gitignore @@ -48,11 +48,11 @@ *.wav aptdec -# VSCode -.vscode - -# CMake -build - -libpng*/ -zlib*/ +.vscode/ +build/ +libpng/ +zlib/ +winbuild/ +winpath/ +libsndfile-1.0.29-win64.zip +libsndfile-1.0.29-win64/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ea82d23..c16bbcd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(aptdec) file(GLOB_RECURSE C_SOURCE_FILES src/*.c) add_executable(aptdec ${C_SOURCE_FILES}) -add_compile_definitions(PALETTE_DIR="${CMAKE_SOURCE_DIR}/palettes") +add_compile_definitions(PALETTE_DIR="../palettes") # Math target_link_libraries(aptdec PRIVATE m) @@ -53,7 +53,7 @@ else() set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") install(TARGETS aptdec DESTINATION "bin/") - install(FILES libpng16.dll libsndfile-1.dll libzlib.dll DESTINATION "bin/") + install(FILES libpng16.dll sndfile.dll libzlib.dll DESTINATION "bin/") install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") endif() diff --git a/README.md b/README.md index 08f4ee3..b900464 100644 --- a/README.md +++ b/README.md @@ -123,9 +123,9 @@ cmake .. make ``` -Since cmake is now being used for building, windows support has come. You can build for windows with the `build_windows.sh` script, you will need wine and mingw64 installed: +Since CMake is now being used for building, windows support has come. You can build for windows with the `build_windows.sh` script, you will need the following: ``` -./build_windows.sh +sudo apt install wget cmake make mingw-w64 git unzip ``` ## Further Reading diff --git a/build_windows.sh b/build_windows.sh index c2e094a..fcfebd0 100755 --- a/build_windows.sh +++ b/build_windows.sh @@ -37,6 +37,7 @@ cp "libsndfile-1.0.29-win64/include/sndfile.h" $TEMP_PATH/include/sndfile.h # Copy DLL's into root for CPack cp $TEMP_PATH/bin/*.dll ../ +mv ../libsndfile-1.dll ../sndfile.dll # Build aptdec mkdir -p winbuild && cd winbuild diff --git a/cmake/FindLibSndFile.cmake b/cmake/FindLibSndFile.cmake index 6b381b1..cd58900 100644 --- a/cmake/FindLibSndFile.cmake +++ b/cmake/FindLibSndFile.cmake @@ -1,7 +1,7 @@ # Find libsndfile FIND_PATH(LIBSNDFILE_INCLUDE_DIR sndfile.h) -SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile) +SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile libsndfile-1) FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES} PATH) IF(LIBSNDFILE_INCLUDE_DIR AND LIBSNDFILE_LIBRARY) diff --git a/src/pngio.c b/src/pngio.c index aa9b945..a350d19 100644 --- a/src/pngio.c +++ b/src/pngio.c @@ -142,7 +142,8 @@ int mapOverlay(char *filename, rgb_t **crow, int nrow, int zenith, int MCIR) { } int readRawImage(char *filename, float **prow, int *nrow) { - FILE *fp = fopen(filename, "r"); + FILE *fp = fopen(filename, "rb"); + printf("%s", filename); if(!fp) { fprintf(stderr, "Cannot open %s\n", filename); return 0; @@ -206,12 +207,12 @@ int readRawImage(char *filename, float **prow, int *nrow) { } int readPalette(char *filename, rgb_t **pixels) { - FILE *fp = fopen(filename, "r"); + FILE *fp = fopen(filename, "rb"); if(!fp) { char buffer[1024]; // PALETTE_DIR is set through CMake sprintf(buffer, PALETTE_DIR"/%s", filename); - fp = fopen(buffer, "r"); + fp = fopen(buffer, "rb"); if(!fp){ fprintf(stderr, "Cannot open %s\n", filename); return 0;