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
Changes from 4 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
63 changes: 12 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,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 @@ -84,7 +80,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 Down Expand Up @@ -465,6 +460,8 @@ if(UNIX)
if(WITH_X11)
LIST(APPEND LIBS ${X11_X11_LIB})
LIST(APPEND LIBS ${X11_Xi_LIB})
LIST(APPEND LIBS X11::xcb)
LIST(APPEND LIBS Qt5::X11Extras)
endif(WITH_X11)

if(WITH_XTEST)
Expand All @@ -489,57 +486,24 @@ if(UNIX)
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()
if(UNIX)
add_executable(antimicrox
AriaMoradi marked this conversation as resolved.
Show resolved Hide resolved
${antimicrox_MAIN}
${antimicrox_HEADERS_MOC}
${antimicrox_SOURCES}
${antimicrox_FORMS_HEADERS}
${antimicrox_RESOURCES_RCC}
)


add_executable(antimicrox ${antimicrox_MAIN})
target_link_libraries (antimicrox antilib Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::Concurrent)
target_link_libraries(antimicrox Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::Concurrent ${LIBS})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where's ${SDL_LIBRARY}? Maybe that contained xcb?

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.

pkg_check_modules(XXX REQUIRED yyy) provides XXX_LIBRARIES which in the case is SDL2_LIBRARIES

this is a oddity in the ways we find libraries.
we could just use find_package(SDL2 REQUIRED) which provides SDL_LIBRARIES and SDL_LIBRARY(they are the same).

So i think in a previous version we used find_package but later it was changed to pkg_check_modules but they forgot to remove the variable.(I can't think of any reasons other than older cmake versions behaving differently)

anyways, I could refactor further and bring back find_package?

ref: https://cmake.org/cmake/help/latest/module/FindSDL.html
ref: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html

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.

and before my changes it was empty(not set) so removing it wont change anything.


endif(UNIX)
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")
endif(UNIX)

Expand Down Expand Up @@ -646,9 +610,6 @@ It is a new fork of discontinued AntiMicro.")
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