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

Statically link our code #99

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 51 additions & 92 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(SDL_REQUIRED_VERSION 2.0.6)
project(antimicrox)

if(POLICY CMP0071)
cmake_policy(SET CMP0071 NEW)
cmake_policy(SET CMP0071 NEW)
endif()

if(UNIX)
Expand All @@ -40,9 +40,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)


if (UNIX AND NOT APPLE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "force cmake prefix to be set for /usr" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "force cmake prefix to be set for /usr" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif(UNIX AND NOT APPLE)

include(CheckCXXCompilerFlag)
Expand Down Expand Up @@ -71,10 +71,6 @@ set(ANTIMICROX_MAJOR_VERSION 3)
set(ANTIMICROX_MINOR_VERSION 1)
set(ANTIMICROX_PATCH_VERSION 3)

# antilib soname version
set(ANTILIB_MAJOR_VERSION 1)
set(ANTILIB_VERSION "${ANTILIB_MAJOR_VERSION}")

option(WITH_TESTS "Allow tests for classes" OFF)

if(WITH_TESTS)
Expand All @@ -86,7 +82,6 @@ if(UNIX)
option(WITH_UINPUT "Compile with support for uinput. uinput will be usable to simulate events." ON)
option(WITH_XTEST "Compile with support for XTest. XTest will be usable to simulate events." ON)
option(APPDATA "Build project with AppData file support." ON)
option(ANTILIB_PATH "Set your own path for antilib" OFF)
endif(UNIX)

option(UPDATE_TRANSLATIONS "Call lupdate to update translation files from source." OFF)
Expand All @@ -101,7 +96,7 @@ if(UNIX)
pkg_check_modules(SDL2 REQUIRED sdl2)

if(WITH_X11)
find_package(X11 REQUIRED)
find_package(X11 REQUIRED COMPONENTS ${X11_X11_xcb_LIB})
endif(WITH_X11)

if(WITH_XTEST AND NOT WITH_X11)
Expand All @@ -124,7 +119,7 @@ endif(UNIX)

set(antimicrox_MAIN
src/main.cpp
)
)

set(antimicrox_SOURCES
src/aboutdialog.cpp
Expand Down Expand Up @@ -361,7 +356,7 @@ if(ATTACH_FAKE_CLASSES)

LIST(APPEND antimicrox_HEADERS
src/fakeclasses/xbox360wireless.h
)
)
endif(ATTACH_FAKE_CLASSES)

set(antimicrox_FORMS
Expand Down Expand Up @@ -441,40 +436,44 @@ if(UNIX)
endif(UNIX)

if (UNIX)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Concurrent REQUIRED)
#find_package(Qt5Test REQUIRED)

if (WITH_X11)
find_package(Qt5X11Extras REQUIRED)
endif()

find_package(Qt5Widgets ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Core ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Gui ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Network ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5LinguistTools ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Concurrent ${QT_REQUIRED_VERSION} REQUIRED)
#find_package(Qt5Test REQUIRED)

if (WITH_X11)
find_package(Qt5X11Extras REQUIRED)
endif()

QT5_WRAP_CPP(antimicrox_HEADERS_MOC ${antimicrox_HEADERS})
QT5_WRAP_UI(antimicrox_FORMS_HEADERS ${antimicrox_FORMS})
QT5_ADD_RESOURCES(antimicrox_RESOURCES_RCC ${antimicrox_RESOURCES})
QT5_WRAP_CPP(antimicrox_HEADERS_MOC ${antimicrox_HEADERS})
QT5_WRAP_UI(antimicrox_FORMS_HEADERS ${antimicrox_FORMS})
QT5_ADD_RESOURCES(antimicrox_RESOURCES_RCC ${antimicrox_RESOURCES})

add_subdirectory("share/antimicrox/translations")
add_subdirectory("share/antimicrox/translations")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif(UNIX)

if(UNIX)
list(APPEND QT_LIBS Qt5::Widgets)
list(APPEND QT_LIBS Qt5::Core)
list(APPEND QT_LIBS Qt5::Gui)
list(APPEND QT_LIBS Qt5::Network)
list(APPEND QT_LIBS Qt5::Concurrent)

if(WITH_X11)
LIST(APPEND LIBS ${X11_X11_LIB})
LIST(APPEND LIBS ${X11_Xi_LIB})
LIST(APPEND EXTRA_LIBS ${X11_X11_LIB})
LIST(APPEND EXTRA_LIBS ${X11_Xi_LIB})
LIST(APPEND EXTRA_LIBS ${X11_X11_xcb_LIB})
LIST(APPEND QT_LIBS Qt5::X11Extras)
endif(WITH_X11)

if(WITH_XTEST)
LIST(APPEND LIBS ${X11_XTest_LIB})
LIST(APPEND EXTRA_LIBS ${X11_XTest_LIB})
endif(WITH_XTEST)

list(APPEND LIBS ${SDL2_LIBRARIES})

endif (UNIX)


Expand All @@ -483,66 +482,31 @@ include_directories(
"${CMAKE_CURRENT_BINARY_DIR}/src"
${PROJECT_SOURCE_DIR}
"${PROJECT_SOURCE_DIR}/src"
)
)


if(UNIX)
# Store executable in a bin subdir. Needed here so translations can be loaded.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
endif(UNIX)

if(UNIX)

if(ANTILIB_PATH)
ADD_DEFINITIONS(-DANTILIB_PATH="${ANTILIB_PATH}")

# Generally package manager takes care of this while installing the new library, but not always
# especially with cmake
ADD_DEFINITIONS(-DLD_LIBRARY_PATH="${ANTILIB_PATH}:${LD_LIBRARY_PATH}")

# those instructions have to be before add_executable() or add_library() is called, otherwise it has no effect
set(CMAKE_INSTALL_RPATH "${ANTILIB_PATH}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

add_library( antilib
SHARED
Copy link
Collaborator

@gombosg gombosg Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a suspicion that xcb linking was not needed because this used to be compiled as a shared library, it was only linked dynamically, and xcb is a requirement for qt so it's available at runtime. @pktiuk is this a wild guess?

Copy link
Contributor Author

@AriaMoradi AriaMoradi Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We directly need xcb because some functions fro xcb/xcb.h where used.
And these are not a part of qt in any ways possible..

${antimicrox_HEADERS_MOC}
${antimicrox_SOURCES}
${antimicrox_FORMS_HEADERS}
${antimicrox_RESOURCES_RCC}
)

set_target_properties(antilib PROPERTIES
SOVERSION ${ANTILIB_VERSION}
)


#target_link_libraries (antilib Qt5::Widgets Qt5::Core Qt5::Test Qt5::Gui Qt5::Network Qt5::Concurrent ${SDL_LIBRARY} ${LIBS})
target_link_libraries (antilib Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::Concurrent ${SDL_LIBRARY} ${LIBS})

if (WITH_X11)
target_link_libraries(antilib Qt5::X11Extras)
endif()


add_executable(antimicrox ${antimicrox_MAIN})
target_link_libraries (antimicrox antilib Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::Concurrent)
if(UNIX)
add_executable(antimicrox
${antimicrox_MAIN}
${antimicrox_HEADERS_MOC}
${antimicrox_SOURCES}
${antimicrox_FORMS_HEADERS}
${antimicrox_RESOURCES_RCC}
)

endif(UNIX)
target_link_libraries(antimicrox ${QT_LIBS} ${SDL2_LIBRARIES} ${EXTRA_LIBS})
endif(UNIX)


# Specify out directory for final executable.
if(UNIX)
install(TARGETS antimicrox RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

if(ANTILIB_PATH)
install(TARGETS antilib DESTINATION "${ANTILIB_PATH}")
else()
install(TARGETS antilib DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()

install(FILES ${antimicrox_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/antimicrox")
install(TARGETS antimicrox RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES ${antimicrox_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/antimicrox")
endif(UNIX)

if(UNIX)
Expand Down Expand Up @@ -584,8 +548,7 @@ configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)


# Only way to force install target to be dependent on updateqm.
Expand Down Expand Up @@ -624,9 +587,9 @@ set(CPACK_PACKAGE_FILE_NAME "antimicrox-${ANTIMICROX_MAJOR_VERSION}.${ANTIMICROX
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")

if(UNIX)
set(CPACK_STRIP_FILES "")
set(CPACK_SOURCE_STRIP_FILES "")
endif()
set(CPACK_STRIP_FILES "")
set(CPACK_SOURCE_STRIP_FILES "")
endif()

# Building .deb package
if(CPACK_GENERATOR STREQUAL "DEB")
Expand All @@ -647,10 +610,6 @@ It is a new fork of discontinued AntiMicro.")
#Strip binaries from unnecessary notes, comments, etc
add_custom_command(TARGET antimicrox POST_BUILD
COMMAND strip --strip-unneeded --remove-section=.comment --remove-section=.note "${CMAKE_CURRENT_BINARY_DIR}/bin/antimicrox" VERBATIM)

add_custom_command(TARGET antimicrox POST_BUILD
COMMAND strip --strip-unneeded --remove-section=.comment --remove-section=.note "${CMAKE_CURRENT_BINARY_DIR}/libantilib.so.1" VERBATIM)

endif()

set(CPACK_PACKAGE_EXECUTABLES "antimicrox" "antimicrox")
Expand Down
2 changes: 1 addition & 1 deletion src/qglobalshortcut/qglobalshortcut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <xcb/xcb.h>
#include <X11/Xlib-xcb.h>
#endif

QMultiHash<quint32, QGlobalShortcut *> QGlobalShortcut::shortcuts_;
Expand Down