diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1609b0b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,91 @@ +cmake_minimum_required(VERSION 3.7) +project(vbindiff) + +SET(PACKAGE_VERSION 3.0_beta6) +SET(WINDOWS_PACKAGE_VERSION "3,0,200,6") + +set(CMAKE_CXX_STANDARD 14) + +configure_file( + "${PROJECT_SOURCE_DIR}/config.h.cmake-in" + "${PROJECT_BINARY_DIR}/config.h" +) +include_directories(${PROJECT_BINARY_DIR}) + +set(SOURCE_FILES + vbindiff.cpp + tables.h + GetOpt/GetOpt.cpp + GetOpt/GetOpt.hpp) + +if (WIN32) + set(SOURCE_FILES ${SOURCE_FILES} + win32/ConWin.cpp + win32/ConWin.hpp + win32/FileIO.hpp) + include_directories(BEFORE win32) + + configure_file( + "${PROJECT_SOURCE_DIR}/win32/version.h.cmake-in" + "${PROJECT_BINARY_DIR}/version.h" + ) + + if (CMAKE_COMPILER_IS_GNUCC) + set (CMAKE_RC_COMPILER_INIT windres) + enable_language(RC) + set (CMAKE_RC_COMPILE_OBJECT + " -O coff -I${PROJECT_BINARY_DIR} -I${PROJECT_SOURCE_DIR}/win32/mingw ") + endif () + set (SOURCE_FILES ${SOURCE_FILES} "${PROJECT_SOURCE_DIR}/win32/vbindiff.rc") +else () + find_package(Curses REQUIRED) + include_directories(${CURSES_INCLUDE_DIR}) + find_library(CURSES_PANEL_LIBRARY NAMES panel DOC "The curses panel library") + if (NOT CURSES_PANEL_LIBRARY) + message(FATAL_ERROR "A required curses' panel library not found.") + endif () + # Add panels to the library path + set (CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_PANEL_LIBRARY}) + + set(SOURCE_FILES ${SOURCE_FILES} + curses/ConWin.cpp + curses/ConWin.hpp + curses/FileIO.hpp) + include_directories(BEFORE curses) + + set(PROJECT_FLAGS "-Wall -Wno-narrowing -D_FILE_OFFSET_BITS=64") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_FLAGS}") +endif () + +set(LINK_LIBS ${CURSES_LIBRARIES}) + +if (MINGW) + find_library(libssp NAMES libssp.a) + set(LINK_LIBS ${LINK_LIBS} ${libssp}) +endif() + +add_executable(vbindiff ${SOURCE_FILES}) + +target_link_libraries(vbindiff ${LINK_LIBS}) + +if (NOT WIN32) + include(GNUInstallDirs) + install(TARGETS vbindiff RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/vbindiff.1 + COMMAND ${PROJECT_SOURCE_DIR}/tools/genfile.pl + ARGS ${PROJECT_SOURCE_DIR}/tools/vbindiff.pod.tt --output=${PROJECT_BINARY_DIR}/vbindiff.1 + DEPENDS tools/vbindiff.pod.tt + ) + add_custom_target(man ALL SOURCES ${PROJECT_BINARY_DIR}/vbindiff.1) + + if (CMAKE_INSTALL_MANDIR) + set(INSTALL_MANDIR ${CMAKE_INSTALL_MANDIR}) + else() + # CMake does not seem to define CMAKE_INSTALL_MANDIR on some platforms + set(INSTALL_MANDIR share/man) + endif() + install(FILES vbindiff.1 DESTINATION ${INSTALL_MANDIR}/man1) +endif () diff --git a/README.md b/README.md index 0a4b05b..2408af8 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,30 @@ This repository uses a submodule to pull in my [Free GetOpt](https://github.com/ 1. Clone this repository and `cd` into it. 2. Run `git submodule update --init` -3. If you're working on a Unix system, run `autoreconf -i` +3. There are two ways to build VBinDiff: using [Autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) or using [CMake](https://cmake.org/) + * Autotools: + * If you're working on a Unix system, run `autoreconf -i` + * Now you're ready to use the normal `./configure && make` process on Unix, or open `win32/vbindiff.dsw` on Windows. + * CMake: + * Example usage on Unix-like systems (including Windows with MinGW): + ``` + mkdir build + cd build + cmake .. + make + ``` + Try also `ccmake ..` or `cmake-gui ..` in place of `cmake ..` above. + * Windows / Visual Studio: See [CMake support in Visual Studio](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/) or use the same approach as on Unix-like systems and then open the generated project file: + ``` + mkdir build + cd build + cmake -G "Visual Studio 15 2017 Win64" .. + ``` + Now open the generated project file in Visual Studio. + See [cmake-generators(7)](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) for the list of available generators / supported Visual Studio versions. + + -Now you're ready to use the normal `./configure && make` process on Unix, or open `win32/vbindiff.dsw` on Windows. To build the documentation, you'll also need [Perl](https://www.perl.org/), [Date::Format](https://metacpan.org/module/Date::Format), and [Template-Toolkit](https://metacpan.org/release/Template-Toolkit). For Windows, I recommend [Strawberry Perl](http://strawberryperl.com/), which comes with the necessary modules. On Unix, your distro may have packages, or you can install from [CPAN](https://metacpan.org/). Package names for some distros are: diff --git a/build_w32.sh b/build_w32.sh new file mode 100755 index 0000000..b93d9ce --- /dev/null +++ b/build_w32.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Target triple (i686): +TARGET=i686-w64-mingw32 + +BUILD_DIR=./build-w32 + +. ./build_windows.sh diff --git a/build_w64.sh b/build_w64.sh new file mode 100755 index 0000000..383a2a3 --- /dev/null +++ b/build_w64.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Target triple (x86_64): +TARGET=x86_64-w64-mingw32 + +BUILD_DIR=./build-w64 + +. ./build_windows.sh diff --git a/build_windows.sh b/build_windows.sh new file mode 100644 index 0000000..ac90c84 --- /dev/null +++ b/build_windows.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# +# Cross compilation for Windows +# This works on Arch Linux out of the box, just install mingw-w64-cmake from +# AUR. (e.g. with yaourt -ySa mingw-w64-cmake) +# +# For other distros, having a look at Arch's package might be useful: +# https://aur.archlinux.org/cgit/aur.git/tree/?h=mingw-w64-cmake + +set -x -e + +rm -rf ${BUILD_DIR} +mkdir ${BUILD_DIR} +cd ${BUILD_DIR} + +${TARGET}-cmake -DCMAKE_EXE_LINKER_FLAGS="-static" -DCMAKE_BUILD_TYPE="Release" .. +make diff --git a/config.h.cmake-in b/config.h.cmake-in new file mode 100644 index 0000000..24abe76 --- /dev/null +++ b/config.h.cmake-in @@ -0,0 +1,6 @@ +#ifndef VBINDIFF_CONFIG_H_CMAKE_IN +#define VBINDIFF_CONFIG_H_CMAKE_IN + +#define PACKAGE_VERSION "@PACKAGE_VERSION@" + +#endif //VBINDIFF_CONFIG_H_CMAKE_IN diff --git a/tools/genfile.pl b/tools/genfile.pl index def0b82..cdab1e9 100755 --- a/tools/genfile.pl +++ b/tools/genfile.pl @@ -71,8 +71,9 @@ $output =~ s/^\s*([>|].+)\n.*\n// or die; # The user can override this with the --output option: my $outfile = ($redirect || $1); + $outfile =~ s/^>//; - open(OUT, $outfile) or die; + open(OUT, '>', $outfile) or die; print OUT $output or die; close OUT or die; } # end foreach $file diff --git a/win32/mingw/winres.h b/win32/mingw/winres.h new file mode 100644 index 0000000..aa87ae8 --- /dev/null +++ b/win32/mingw/winres.h @@ -0,0 +1,20 @@ +// winres.h + +#if __GNUC__ >= 3 +#pragma GCC system_header +#endif + +#define VS_VERSION_INFO 1 + +#ifndef WINVER +#define WINVER 0x0501 // default to Windows XP +#endif + +#include + +// Remove possible incorrect value +#ifdef IDC_STATIC +#undef IDC_STATIC +#endif +#define IDC_STATIC (-1) + diff --git a/win32/mingw/winresrc.h b/win32/mingw/winresrc.h new file mode 100644 index 0000000..0953e20 --- /dev/null +++ b/win32/mingw/winresrc.h @@ -0,0 +1,31 @@ +#ifndef _WINRESRC_H +#define _WINRESRC_H + +#if __GNUC__ >= 3 +#pragma GCC system_header +#endif + +#ifndef WINVER +#define WINVER 0x0500 +#endif + +#ifndef _WIN32_IE +#define _WIN32_IE 0x0501 +#endif + +#ifndef _WIN32_WINDOWS +#define _WIN32_WINDOWS 0x0410 +#endif + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0500 +#endif + +#include +#include +#include +#include +#include +#include + +#endif // _WINRESRC_H diff --git a/win32/version.h.cmake-in b/win32/version.h.cmake-in new file mode 100644 index 0000000..3d33201 --- /dev/null +++ b/win32/version.h.cmake-in @@ -0,0 +1,7 @@ +#ifndef VBINDIFF_VERSION_H_CMAKE_IN +#define VBINDIFF_VERSION_H_CMAKE_IN + +#define PACKAGE_VERSION "@PACKAGE_VERSION@" +#define PACKAGE_VERSION_NUM @WINDOWS_PACKAGE_VERSION@ + +#endif //VBINDIFF_VERSION_H_CMAKE_IN