Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to build with CMake #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
91 changes: 91 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
"<CMAKE_RC_COMPILER> -O coff -I${PROJECT_BINARY_DIR} -I${PROJECT_SOURCE_DIR}/win32/mingw <FLAGS> <DEFINES> <SOURCE> <OBJECT>")
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 ()
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 8 additions & 0 deletions build_w32.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Target triple (i686):
TARGET=i686-w64-mingw32

BUILD_DIR=./build-w32

. ./build_windows.sh
8 changes: 8 additions & 0 deletions build_w64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Target triple (x86_64):
TARGET=x86_64-w64-mingw32

BUILD_DIR=./build-w64

. ./build_windows.sh
17 changes: 17 additions & 0 deletions build_windows.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions config.h.cmake-in
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tools/genfile.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions win32/mingw/winres.h
Original file line number Diff line number Diff line change
@@ -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 <winresrc.h>

// Remove possible incorrect value
#ifdef IDC_STATIC
#undef IDC_STATIC
#endif
#define IDC_STATIC (-1)

31 changes: 31 additions & 0 deletions win32/mingw/winresrc.h
Original file line number Diff line number Diff line change
@@ -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 <winuser.h>
#include <commctrl.h>
#include <dde.h>
#include <winnt.h>
#include <dlgs.h>
#include <winver.h>

#endif // _WINRESRC_H
7 changes: 7 additions & 0 deletions win32/version.h.cmake-in
Original file line number Diff line number Diff line change
@@ -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