Commit dbe69603 authored by Grumbel's avatar Grumbel

Added 'make install' command and rewrote datadir handling

Fixes #12
parent f1738124
......@@ -17,6 +17,8 @@
cmake_minimum_required(VERSION 2.8)
project(jstest-gtk)
include(GNUInstallDirs)
option(WARNINGS "Switch on extra warnings" OFF)
option(WERROR "Turn warnings into errors" OFF)
......@@ -56,14 +58,10 @@ file(
COPY ${JSTEST_GTK_DATA}
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/)
add_library(binreloc STATIC ${CMAKE_CURRENT_SOURCE_DIR}/external/binreloc-2.0/binreloc.c)
set_property(TARGET binreloc PROPERTY COMPILE_DEFINITIONS ENABLE_BINRELOC)
file(GLOB JSTEST_GTK_SOURCES src/*.cpp)
add_executable(jstest-gtk ${JSTEST_GTK_SOURCES})
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/external/binreloc-2.0/
${GTKMM_INCLUDE_DIRS}
${SIGCPP_INCLUDE_DIRS}
${X11_INCLUDE_DIRS})
......@@ -73,10 +71,31 @@ set_property(TARGET jstest-gtk PROPERTY COMPILE_OPTIONS
${X11_CFLAGS_OTHER}
${WARNINGS_CXX_FLAGS})
target_link_libraries(jstest-gtk
binreloc
${CMAKE_THREAD_LIBS_INIT}
${GTKMM_LIBRARIES}
${SIGCPP_LIBRARIES}
${X11_LIBRARIES})
install(TARGETS jstest-gtk
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/jstest-gtk.sh.in
${CMAKE_BINARY_DIR}/jstest-gtk.sh)
install(FILES
${CMAKE_BINARY_DIR}/jstest-gtk.sh
RENAME jstest-gtk
PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
PATTERN "*~" EXCLUDE)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/jstest-gtk.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
# EOF #
This diff is collapsed.
/*
* BinReloc - a library for creating relocatable executables
* Written by: Hongli Lai <h.lai@chello.nl>
* http://autopackage.org/
*
* This source code is public domain. You can relicense this code
* under whatever license you want.
*
* See http://autopackage.org/docs/binreloc/ for
* more information and how to use this.
*/
#ifndef __BINRELOC_H__
#define __BINRELOC_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). */
typedef enum {
/** Cannot allocate memory. */
BR_INIT_ERROR_NOMEM,
/** Unable to open /proc/self/maps; see errno for details. */
BR_INIT_ERROR_OPEN_MAPS,
/** Unable to read from /proc/self/maps; see errno for details. */
BR_INIT_ERROR_READ_MAPS,
/** The file format of /proc/self/maps is invalid; kernel bug? */
BR_INIT_ERROR_INVALID_MAPS,
/** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
BR_INIT_ERROR_DISABLED
} BrInitError;
#ifndef BINRELOC_RUNNING_DOXYGEN
/* Mangle symbol names to avoid symbol collisions with other ELF objects. */
#define br_init gJdn38894613193140_br_init
#define br_init_lib gJdn38894613193140_br_init_lib
#define br_find_exe gJdn38894613193140_br_find_exe
#define br_find_exe_dir gJdn38894613193140_br_find_exe_dir
#define br_find_prefix gJdn38894613193140_br_find_prefix
#define br_find_bin_dir gJdn38894613193140_br_find_bin_dir
#define br_find_sbin_dir gJdn38894613193140_br_find_sbin_dir
#define br_find_data_dir gJdn38894613193140_br_find_data_dir
#define br_find_locale_dir gJdn38894613193140_br_find_locale_dir
#define br_find_lib_dir gJdn38894613193140_br_find_lib_dir
#define br_find_libexec_dir gJdn38894613193140_br_find_libexec_dir
#define br_find_etc_dir gJdn38894613193140_br_find_etc_dir
#define br_strcat gJdn38894613193140_br_strcat
#define br_build_path gJdn38894613193140_br_build_path
#define br_dirname gJdn38894613193140_br_dirname
#endif
int br_init (BrInitError *error);
int br_init_lib (BrInitError *error);
char *br_find_exe (const char *default_exe);
char *br_find_exe_dir (const char *default_dir);
char *br_find_prefix (const char *default_prefix);
char *br_find_bin_dir (const char *default_bin_dir);
char *br_find_sbin_dir (const char *default_sbin_dir);
char *br_find_data_dir (const char *default_data_dir);
char *br_find_locale_dir (const char *default_locale_dir);
char *br_find_lib_dir (const char *default_lib_dir);
char *br_find_libexec_dir (const char *default_libexec_dir);
char *br_find_etc_dir (const char *default_etc_dir);
/* Utility functions */
char *br_strcat (const char *str1, const char *str2);
char *br_build_path (const char *dir, const char *file);
char *br_dirname (const char *path);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __BINRELOC_H__ */
#!/bin/sh
exec "@CMAKE_INSTALL_FULL_LIBEXECDIR@/@PROJECT_NAME@" --datadir "@CMAKE_INSTALL_FULL_DATADIR@/@PROJECT_NAME@/" "$@"
......@@ -24,8 +24,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include "binreloc.h"
#include "joystick_test_widget.hpp"
#include "joystick_list_widget.hpp"
#include "joystick_map_widget.hpp"
......@@ -35,9 +33,9 @@
Main* Main::current_ = 0;
Main::Main(const std::string& datadir_) :
Main::Main() :
Gtk::Application("com.gmail.grumbel.jstest-gtk", Gio::APPLICATION_HANDLES_OPEN),
datadir(datadir_),
datadir("data/"),
m_simple_ui(false)
{
current_ = this;
......@@ -108,6 +106,7 @@ Main::run(int argc, char** argv)
<< " -h, --help Display this help and exit\n"
<< " -v, --version Display version information and exit\n"
<< " --simple Hide graphical representation of axis\n"
<< " --datadir DIR Load application data from DIR\n"
<< "\n"
<< "Report bugs to Ingo Ruhnke <grumbel@gmail.com>.\n";
return 0;
......@@ -122,6 +121,19 @@ Main::run(int argc, char** argv)
{
m_simple_ui = true;
}
else if (strcmp("--datadir", argv[i]) == 0)
{
i += 1;
if (i >= argc)
{
std::cout << "Error: " << argv[0] << ": argument to --datadir is missing" << std::endl;
return EXIT_FAILURE;
}
else
{
datadir = argv[i];
}
}
else if (argv[i][0] == '-')
{
std::cout << "Error: " << argv[0] << ": unrecognized option '" << argv[i] << "'" << std::endl;
......@@ -131,7 +143,7 @@ Main::run(int argc, char** argv)
{
if (!device_files.empty())
{
std::cout << "Error: multiple device files given, only one allowed: " << argv[i] << std::endl;
std::cout << "Error: " << argv[0] << ": multiple device files given, only one allowed: " << argv[i] << std::endl;
return EXIT_FAILURE;
}
......@@ -167,31 +179,6 @@ Main::run(int argc, char** argv)
return 0;
}
std::string find_datadir()
{
BrInitError error;
if (!br_init(&error))
{
std::ostringstream out;
out << "Error: Couldn't init binreloc: " << error;
throw std::runtime_error(out.str());
}
else
{
char* c_prefix = br_find_exe_dir(NULL);
if (!c_prefix)
{
throw std::runtime_error("Error: Couldn't find prefix");
}
else
{
std::string prefix = c_prefix;
free(c_prefix);
return prefix + "/data/";
}
}
}
int main(int argc, char** argv)
{
try
......@@ -209,6 +196,7 @@ int main(int argc, char** argv)
Glib::RefPtr<Main> Main::create()
{
return Glib::RefPtr<Main>(new Main(find_datadir()));
return Glib::RefPtr<Main>(new Main);
}
/* EOF */
......@@ -43,7 +43,7 @@ private:
void on_dialog_hide(Gtk::Dialog* dialog);
public:
Main(const std::string& datadir);
Main();
~Main();
JoystickTestWidget* show_device_property_dialog(const std::string& filename, Gtk::Window* parent = nullptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment