diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-07-06 07:37:47 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-07-06 12:07:48 +0200 |
commit | 069ebb6212aa096adb1ded0823ac4194db9b0d03 (patch) | |
tree | a31c1026a6a0349e7867713ca85e83e8ff79b1be | |
parent | 56e9f634d5dd4122278a8f1c5f8e9fe39ed3652e (diff) |
gui, api, csv: support hier(7) on Unix
This affects platforms such as FreeBSD, Cygwin or Linux.
-rwxr-xr-x | CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmake/opentrack-boilerplate.cmake | 18 | ||||
-rw-r--r-- | cmake/opentrack-hier.cmake | 19 | ||||
-rw-r--r-- | cmake/opentrack-install.cmake | 12 | ||||
-rw-r--r-- | csv/CMakeLists.txt | 1 | ||||
-rw-r--r-- | csv/csv.cpp | 7 | ||||
-rw-r--r-- | gui/CMakeLists.txt | 5 | ||||
-rw-r--r-- | gui/main.cpp | 2 | ||||
-rw-r--r-- | gui/ui.cpp | 1 | ||||
-rw-r--r-- | opentrack/CMakeLists.txt | 1 | ||||
-rw-r--r-- | opentrack/library-path.cpp | 4 | ||||
-rw-r--r-- | opentrack/library-path.hpp | 2 | ||||
-rw-r--r-- | opentrack/plugin-support.hpp | 39 |
13 files changed, 81 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6457b3c5..b5dc355e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,5 @@ file(GLOB opentrack-subprojects ) foreach(i ${opentrack-subprojects}) get_filename_component(i ${i} DIRECTORY) - get_filename_component(j ${i} NAME) - message(STATUS "project ${j}") add_subdirectory(${i}) endforeach() diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake index 3838ca41..54643c42 100644 --- a/cmake/opentrack-boilerplate.cmake +++ b/cmake/opentrack-boilerplate.cmake @@ -1,3 +1,18 @@ +include(opentrack-hier) + +set(new-hier-path "#pragma once +#define OPENTRACK_LIBRARY_PATH \"${opentrack-hier-path}\" +") + +set(hier-path-filename "${CMAKE_BINARY_DIR}/opentrack-library-path.h") +set(orig-hier-path "") +if(EXISTS ${hier-path-filename}) + file(READ ${hier-path-filename} orig-hier-path) +endif() +if(NOT (orig-hier-path STREQUAL new-hier-path)) + file(WRITE ${hier-path-filename} "${new-hier-path}") +endif() + function(opentrack_set_globs n) set(dir ${PROJECT_SOURCE_DIR}) file(GLOB ${n}-c ${dir}/*.cpp ${dir}/*.c ${dir}/*.h ${dir}/*.hpp) @@ -42,6 +57,7 @@ function(opentrack_boilerplate__ n files_ no-library_ static_ no-compat_ compile set(link-mode STATIC) endif() add_library(${n} ${link-mode} ${files_}) + message(STATUS "module ${n}") endif() if(NOT no-library_) opentrack_compat(${n}) @@ -75,7 +91,7 @@ function(opentrack_boilerplate__ n files_ no-library_ static_ no-compat_ compile string(REPLACE "-" "_" n_ ${n_}) target_compile_definitions(${n} PRIVATE "BUILD_${n_}") if((NOT static_) AND (NOT no-library_)) - install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) + install(TARGETS ${n} ${opentrack-hier-str}) endif() endfunction() diff --git a/cmake/opentrack-hier.cmake b/cmake/opentrack-hier.cmake new file mode 100644 index 00000000..8462531a --- /dev/null +++ b/cmake/opentrack-hier.cmake @@ -0,0 +1,19 @@ +if(WIN32 OR APPLE OR CYGWIN)
+ set(opentrack-hier-pfx ".")
+ set(opentrack-hier-path "/./")
+ set(opentrack-hier-doc ".")
+ set(opentrack-hier-str RUNTIME DESTINATION . LIBRARY DESTINATION .)
+else()
+ set(opentrack-hier-pfx "libexec/opentrack")
+ set(opentrack-hier-path "/../libexec/opentrack/")
+ set(opentrack-hier-doc "share/doc/opentrack")
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${opentrack-hier-pfx}")
+ set(opentrack-hier-str ARCHIVE DESTINATION lib/opentrack LIBRARY DESTINATION ${opentrack-hier-pfx} RUNTIME DESTINATION bin)
+endif()
+
+set(opentrack-binary-suffix "")
+if(APPLE)
+ set(opentrack-binary-suffix ".bin")
+elseif(WIN32)
+ set(opentrack-binary-suffix ".exe")
+endif()
diff --git a/cmake/opentrack-install.cmake b/cmake/opentrack-install.cmake index 598572fa..a6ad1bad 100644 --- a/cmake/opentrack-install.cmake +++ b/cmake/opentrack-install.cmake @@ -1,17 +1,19 @@ +include(opentrack-hier) + set(opentrack-perms PERMISSIONS WORLD_READ WORLD_EXECUTE OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE) if(WIN32) install(FILES "${CMAKE_SOURCE_DIR}/bin/cleye.config" DESTINATION .) endif() -install(FILES ${CMAKE_SOURCE_DIR}/README.md DESTINATION .) +install(FILES ${CMAKE_SOURCE_DIR}/README.md DESTINATION ${opentrack-hier-doc}) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty-notices DESTINATION .) -install(DIRECTORY "${CMAKE_SOURCE_DIR}/settings" "${CMAKE_SOURCE_DIR}/contrib" DESTINATION .) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty-notices DESTINATION ${opentrack-hier-doc}) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/settings" "${CMAKE_SOURCE_DIR}/contrib" DESTINATION ${opentrack-hier-doc}) -install(FILES "${CMAKE_SOURCE_DIR}/bin/freetrackclient.dll" DESTINATION . ${opentrack-perms}) +install(FILES "${CMAKE_SOURCE_DIR}/bin/freetrackclient.dll" DESTINATION ${opentrack-hier-pfx} ${opentrack-perms}) install(FILES "${CMAKE_SOURCE_DIR}/bin/NPClient.dll" "${CMAKE_SOURCE_DIR}/bin/NPClient64.dll" "${CMAKE_SOURCE_DIR}/bin/TrackIR.exe" - DESTINATION . ${opentrack-perms}) + DESTINATION ${opentrack-hier-pfx} ${opentrack-perms}) diff --git a/csv/CMakeLists.txt b/csv/CMakeLists.txt index b4c41673..1590ec59 100644 --- a/csv/CMakeLists.txt +++ b/csv/CMakeLists.txt @@ -1 +1,2 @@ opentrack_boilerplate(opentrack-csv) +target_link_libraries(opentrack-csv opentrack-api) diff --git a/csv/csv.cpp b/csv/csv.cpp index 09944154..668da442 100644 --- a/csv/csv.cpp +++ b/csv/csv.cpp @@ -10,6 +10,7 @@ */ #include "csv.h" +#include "opentrack/library-path.hpp" #include <QTextDecoder> #include <QFile> #include <QCoreApplication> @@ -98,7 +99,11 @@ bool CSV::getGameData(int id, unsigned char* table, QString& gamename) QString id_str(move(QString::number(id))); - QFile file(QCoreApplication::applicationDirPath() + "/settings/facetracknoir supported games.csv"); + static const QString libexec_path(QStringLiteral("./") + + QString(opentrack_library_path) + + QStringLiteral("/settings/facetracknoir supported games.csv")); + + QFile file(QCoreApplication::applicationDirPath() + libexec_path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return false; diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index b7448b4c..a2a04af1 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -1,3 +1,4 @@ +include(opentrack-hier) opentrack_boilerplate(opentrack NO-LIBRARY) if(WIN32) @@ -12,9 +13,7 @@ endif() add_executable(opentrack ${opentrack-win32-executable} ${opentrack-all}) -if(NOT WIN32) - set_target_properties(opentrack PROPERTIES SUFFIX ".bin") -endif() +set_target_properties(opentrack PROPERTIES SUFFIX "${opentrack-binary-suffix}") target_link_libraries(opentrack opentrack-logic diff --git a/gui/main.cpp b/gui/main.cpp index 3ae01404..be42ac7a 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -58,6 +58,8 @@ int main(int argc, char** argv) QApplication::setAttribute(Qt::AA_X11InitThreads, true); QApplication app(argc, argv); + MainWindow::set_working_directory(); + auto w = std::make_shared<MainWindow>(); w->show(); @@ -85,7 +85,6 @@ MainWindow::MainWindow() : det_timer.start(1000); ensure_tray(); - set_working_directory(); if (!QFile(group::ini_pathname()).exists()) { diff --git a/opentrack/CMakeLists.txt b/opentrack/CMakeLists.txt index 6dc6a96d..13b054ca 100644 --- a/opentrack/CMakeLists.txt +++ b/opentrack/CMakeLists.txt @@ -1,2 +1,3 @@ opentrack_boilerplate(opentrack-api NO-COMPAT) target_link_libraries(opentrack-api opentrack-compat) +target_include_directories(opentrack-api PUBLIC ${CMAKE_BINARY_DIR}) diff --git a/opentrack/library-path.cpp b/opentrack/library-path.cpp new file mode 100644 index 00000000..683dc346 --- /dev/null +++ b/opentrack/library-path.cpp @@ -0,0 +1,4 @@ +#include "library-path.hpp" +#include "opentrack-library-path.h" + +const char* opentrack_library_path = OPENTRACK_LIBRARY_PATH; diff --git a/opentrack/library-path.hpp b/opentrack/library-path.hpp new file mode 100644 index 00000000..49a3adb4 --- /dev/null +++ b/opentrack/library-path.hpp @@ -0,0 +1,2 @@ +#include "export.hpp" +extern "C" OPENTRACK_API_EXPORT const char* opentrack_library_path; diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp index b228b8d4..dbb985dc 100644 --- a/opentrack/plugin-support.hpp +++ b/opentrack/plugin-support.hpp @@ -9,6 +9,7 @@ #include "plugin-api.hpp" #include "opentrack-compat/options.hpp" +#include "library-path.hpp" #include <QWidget> #include <QDebug> @@ -29,22 +30,21 @@ #include <QStringList> #if defined(__APPLE__) -# define OPENTRACK_SONAME "dylib" +# define OPENTRACK_SOLIB_EXT "dylib" #elif defined(_WIN32) -# define OPENTRACK_SONAME "dll" +# define OPENTRACK_SOLIB_EXT "dll" #else -# define OPENTRACK_SONAME "so" +# define OPENTRACK_SOLIB_EXT "so" #endif #include <iostream> #ifdef _MSC_VER -# define OPENTRACK_LIB_PREFIX "" +# define OPENTRACK_SOLIB_PREFIX "" #else -# define OPENTRACK_LIB_PREFIX "lib" +# define OPENTRACK_SOLIB_PREFIX "lib" #endif - extern "C" typedef void* (*OPENTRACK_CTOR_FUNPTR)(void); extern "C" typedef Metadata* (*OPENTRACK_METADATA_FUNPTR)(void); @@ -108,29 +108,30 @@ struct dylib final { static QList<mem<dylib>> enum_libraries() { - const char* filters_n[] = { "opentrack-filter-*.", - "opentrack-tracker-*.", - "opentrack-proto-*." + const char* filters_n[] = { OPENTRACK_SOLIB_PREFIX "opentrack-filter-*." OPENTRACK_SOLIB_EXT, + OPENTRACK_SOLIB_PREFIX "opentrack-tracker-*." OPENTRACK_SOLIB_EXT, + OPENTRACK_SOLIB_PREFIX "opentrack-proto-*." OPENTRACK_SOLIB_EXT, }; const Type filters_t[] = { Filter, Tracker, Protocol }; - QDir settingsDir( QCoreApplication::applicationDirPath() ); + static const QString libexec_path(QStringLiteral("./") + opentrack_library_path); + + QDir settingsDir(libexec_path); QList<mem<dylib>> ret; for (int i = 0; i < 3; i++) { - QString filter = filters_n[i]; - auto t = filters_t[i]; - QStringList filenames = settingsDir.entryList(QStringList { OPENTRACK_LIB_PREFIX + filter + OPENTRACK_SONAME }, - QDir::Files, - QDir::Name); - for (int i = 0; i < filenames.size(); i++) { + QString glob = filters_n[i]; + Type t = filters_t[i]; + QStringList filenames = settingsDir.entryList(QStringList { glob }, QDir::Files, QDir::Name); + + for (const QString& filename : filenames) + { QIcon icon; QString longName; - QString str = filenames.at(i); - auto lib = std::make_shared<dylib>(str, t); - qDebug() << "Loading" << str; + auto lib = std::make_shared<dylib>(libexec_path + QStringLiteral("/") + filename, t); + qDebug() << "Loading" << filename; std::cout.flush(); if (!get_metadata(lib, longName, icon)) continue; |