From 5963a7036199a2d86ffefdc9118e74837b8cc7ef Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Sun, 19 Nov 2017 22:28:34 +0200 Subject: [PATCH 1/9] Initial CMake config --- CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++++ config.h.cmake-in | 6 ++++++ 2 files changed, 42 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 config.h.cmake-in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a3e4187 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.7) +project(vbindiff) + +SET(PACKAGE_VERSION 3.0_beta6) + +set(CMAKE_CXX_STANDARD 14) + +configure_file( + "${PROJECT_SOURCE_DIR}/config.h.cmake-in" + "${PROJECT_BINARY_DIR}/config.h" +) +include_directories(${PROJECT_BINARY_DIR}) + +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 + vbindiff.cpp + tables.h + curses/ConWin.cpp + curses/ConWin.hpp + curses/FileIO.hpp + GetOpt/GetOpt.cpp + GetOpt/GetOpt.hpp) + +include_directories(BEFORE curses) + +add_executable(vbindiff ${SOURCE_FILES}) + +target_link_libraries(vbindiff ${CURSES_LIBRARIES}) 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 From d7d851955a9d0215e2c71bfe215e73c8aaa53b51 Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Mon, 20 Nov 2017 00:00:31 +0200 Subject: [PATCH 2/9] Make CMake win32 target work --- CMakeLists.txt | 49 +++++++++++++++++++++++++++++----------- win32/mingw/winres.h | 20 ++++++++++++++++ win32/mingw/winresrc.h | 31 +++++++++++++++++++++++++ win32/version.h.cmake-in | 7 ++++++ 4 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 win32/mingw/winres.h create mode 100644 win32/mingw/winresrc.h create mode 100644 win32/version.h.cmake-in diff --git a/CMakeLists.txt b/CMakeLists.txt index a3e4187..26ea175 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.7) project(vbindiff) SET(PACKAGE_VERSION 3.0_beta6) +SET(PACKAGE_VERSION_NUM "3,0,200,6") set(CMAKE_CXX_STANDARD 14) @@ -11,25 +12,47 @@ configure_file( ) include_directories(${PROJECT_BINARY_DIR}) -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 vbindiff.cpp tables.h - curses/ConWin.cpp - curses/ConWin.hpp - curses/FileIO.hpp GetOpt/GetOpt.cpp GetOpt/GetOpt.hpp) -include_directories(BEFORE curses) +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) +endif() add_executable(vbindiff ${SOURCE_FILES}) 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..20e6e6e --- /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 @PACKAGE_VERSION_NUM@ + +#endif //VBINDIFF_VERSION_H_CMAKE_IN From e207492ee8da9d56f6065a0fea11fdb4fe15a16f Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Mon, 20 Nov 2017 00:01:24 +0200 Subject: [PATCH 3/9] Add cross-compilation scripts for Arch Linux targetting win32/64 --- build_w32.sh | 8 ++++++++ build_w64.sh | 8 ++++++++ build_windows.sh | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100755 build_w32.sh create mode 100755 build_w64.sh create mode 100644 build_windows.sh 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 From cf588759da910f94e585cd9353bf1b0fdc45fa72 Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Tue, 21 Nov 2017 13:34:17 +0200 Subject: [PATCH 4/9] CMake: Use the same C/C++ flags as in Makefile --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26ea175..394f0c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,10 @@ else() curses/ConWin.hpp curses/FileIO.hpp) include_directories(BEFORE curses) + + set(PROJECT_FLAGS "-Wall -D_FILE_OFFSET_BITS=64") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_FLAGS}") endif() add_executable(vbindiff ${SOURCE_FILES}) From 21ba98853f1cfb3b0b5a316d0308aed5f51a2bd0 Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Tue, 21 Nov 2017 14:13:34 +0200 Subject: [PATCH 5/9] CMake: Add -Wno-narrowing flag to fix macOS build --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 394f0c0..78cd393 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ else() curses/FileIO.hpp) include_directories(BEFORE curses) - set(PROJECT_FLAGS "-Wall -D_FILE_OFFSET_BITS=64") + 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() From f875b639399fd586f86dd4415cbc8ddddbaf2a6f Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Tue, 21 Nov 2017 16:24:35 +0200 Subject: [PATCH 6/9] CMake: Make it clear that "numeric" version info is for Windows --- CMakeLists.txt | 2 +- win32/version.h.cmake-in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78cd393..7de4988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.7) project(vbindiff) SET(PACKAGE_VERSION 3.0_beta6) -SET(PACKAGE_VERSION_NUM "3,0,200,6") +SET(WINDOWS_PACKAGE_VERSION "3,0,200,6") set(CMAKE_CXX_STANDARD 14) diff --git a/win32/version.h.cmake-in b/win32/version.h.cmake-in index 20e6e6e..3d33201 100644 --- a/win32/version.h.cmake-in +++ b/win32/version.h.cmake-in @@ -2,6 +2,6 @@ #define VBINDIFF_VERSION_H_CMAKE_IN #define PACKAGE_VERSION "@PACKAGE_VERSION@" -#define PACKAGE_VERSION_NUM @PACKAGE_VERSION_NUM@ +#define PACKAGE_VERSION_NUM @WINDOWS_PACKAGE_VERSION@ #endif //VBINDIFF_VERSION_H_CMAKE_IN From 4c543bb0ea65f96efff84fbcfcb6c07666ee516b Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Tue, 21 Nov 2017 18:31:07 +0200 Subject: [PATCH 7/9] CMake: Add man generation and installation rules --- CMakeLists.txt | 25 +++++++++++++++++++++++-- tools/genfile.pl | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7de4988..db694b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ if (WIN32) " -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() +else () find_package(Curses REQUIRED) include_directories(${CURSES_INCLUDE_DIR}) find_library(CURSES_PANEL_LIBRARY NAMES panel DOC "The curses panel library") @@ -56,8 +56,29 @@ else() 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() +endif () add_executable(vbindiff ${SOURCE_FILES}) target_link_libraries(vbindiff ${CURSES_LIBRARIES}) + +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/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 From 33f8a376d961d377097fe502b0eee59d352a6161 Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Tue, 21 Nov 2017 19:38:47 +0200 Subject: [PATCH 8/9] CMake: Add documentation to README.md --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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: From efbf1e3b1378b65b944462be2cdbca2950552166 Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Sat, 27 Mar 2021 00:29:36 +0200 Subject: [PATCH 9/9] Newer MinGW versions require explicit linking with libssp when _FORTIFY_SOURCE > 0 --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db694b9..1609b0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,9 +58,16 @@ else () 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 ${CURSES_LIBRARIES}) +target_link_libraries(vbindiff ${LINK_LIBS}) if (NOT WIN32) include(GNUInstallDirs)