From 8f3b0fce249b10648b7946929361d0e1ee80597f Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 12 Sep 2017 23:32:41 +0200 Subject: [PATCH 1/6] WIP: add dynamic build support --- CMakeLists.txt | 76 +++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2183a28..10f8d18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" ST set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -L${CMAKE_INSTALL_PREFIX}/lib") endif () -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${STATIC_BUILD}") set (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") endif () @@ -106,21 +106,24 @@ pkg_search_module (SDL2 REQUIRED sdl2) pkg_search_module (SDL2_MIXER REQUIRED SDL2_mixer) pkg_search_module (SDL2_IMAGE REQUIRED SDL2_image) pkg_search_module (CURL REQUIRED libcurl) -# Static dependencies for SDL_kitchensink -pkg_search_module (PNG REQUIRED libpng) -pkg_search_module (AVCODEC REQUIRED libavcodec) -pkg_search_module (AVFORMAT REQUIRED libavformat) -pkg_search_module (AVUTIL REQUIRED libavutil) -pkg_search_module (SWSCALE REQUIRED libswscale) -pkg_search_module (SWRESAMPLE REQUIRED libswresample) -if (UNIX AND NOT APPLE) - pkg_search_module (ALSA REQUIRED alsa) - pkg_search_module (PULSE REQUIRED libpulse) +if ("${STATIC_BUILD}") + pkg_search_module (PNG REQUIRED libpng) + # Static dependencies for SDL_kitchensink + pkg_search_module (AVCODEC REQUIRED libavcodec) + pkg_search_module (AVFORMAT REQUIRED libavformat) + pkg_search_module (AVUTIL REQUIRED libavutil) + pkg_search_module (SWSCALE REQUIRED libswscale) + pkg_search_module (SWRESAMPLE REQUIRED libswresample) + + if (UNIX AND NOT APPLE) + pkg_search_module (ALSA REQUIRED alsa) + pkg_search_module (PULSE REQUIRED libpulse) + endif () + + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURL_STATICLIB") endif () -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCURL_STATICLIB") - ########################### ## Main binary dependencies ########################### @@ -130,25 +133,40 @@ add_executable (planetblupi ${sources}) set (planetblupi_DEPS ${Intl_LIBRARIES} ${Iconv_LIBRARIES} - ${SDL2_STATIC_LIBRARIES} - ${SDL2_MIXER_STATIC_LIBRARIES} - ${SDL2_IMAGE_STATIC_LIBRARIES} - ${CURL_STATIC_LIBRARIES} - ${SDLKitchensink_STATIC_LIBRARIES} - ${PNG_STATIC_LIBRARIES} - ${AVCODEC_STATIC_LIBRARIES} - ${AVFORMAT_STATIC_LIBRARIES} - ${AVUTIL_STATIC_LIBRARIES} - ${SWSCALE_STATIC_LIBRARIES} - ${SWRESAMPLE_STATIC_LIBRARIES} ) -if (UNIX AND NOT APPLE) +if ("${STATIC_BUILD}") list (APPEND planetblupi_DEPS - ${ALSA_STATIC_LIBRARIES} - ${PULSE_STATIC_LIBRARIES} + ${Intl_LIBRARIES} + ${Iconv_LIBRARIES} + ${SDL2_STATIC_LIBRARIES} + ${SDL2_MIXER_STATIC_LIBRARIES} + ${SDL2_IMAGE_STATIC_LIBRARIES} + ${CURL_STATIC_LIBRARIES} + ${SDLKitchensink_STATIC_LIBRARIES} + ${PNG_STATIC_LIBRARIES} + ${AVCODEC_STATIC_LIBRARIES} + ${AVFORMAT_STATIC_LIBRARIES} + ${AVUTIL_STATIC_LIBRARIES} + ${SWSCALE_STATIC_LIBRARIES} + ${SWRESAMPLE_STATIC_LIBRARIES} + ) + + if (UNIX AND NOT APPLE) + list (APPEND planetblupi_DEPS + ${ALSA_STATIC_LIBRARIES} + ${PULSE_STATIC_LIBRARIES} + ) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_INSTALL_PREFIX}/lib/pulseaudio") + endif () +else () + list (APPEND planetblupi_DEPS + ${SDL2_LIBRARIES} + ${SDL2_MIXER_LIBRARIES} + ${SDL2_IMAGE_LIBRARIES} + ${CURL_LIBRARIES} + ${SDLKitchensink_LIBRARIES} ) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_INSTALL_PREFIX}/lib/pulseaudio") endif () target_link_libraries (planetblupi PUBLIC ${planetblupi_DEPS}) @@ -231,7 +249,7 @@ endif () ## Deploy ######### -if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") +if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND "${STATIC_BUILD}") # set (CPACK_STRIP_FILES TRUE) set (CPACK_PACKAGE_NAME ${PB_PACKAGE_NAME}) set (CPACK_PACKAGE_VENDOR "blupi.org") From 13bd5a3215cc62fb3641e79316c9942f2e12d5b9 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 12 Sep 2017 23:46:02 +0200 Subject: [PATCH 2/6] Add include directories of packages retrieved --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f8d18..2114cf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,10 +96,18 @@ endif (MINGW) set (CMAKE_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/include) set (CMAKE_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib) + find_package (Intl REQUIRED) +include_directories (${Intl_INCLUDE_DIRS}) + find_package (Iconv REQUIRED) +include_directories (${Iconv_INCLUDE_DIRS}) + find_package (Argagg REQUIRED) +include_directories (${Argagg_INCLUDE_DIRS}) + find_package (SDLKitchensink REQUIRED) +include_directories (${SDLKitchensink_INCLUDE_DIRS}) find_package (PkgConfig REQUIRED) pkg_search_module (SDL2 REQUIRED sdl2) From 38838cfb3fa2a72c190f94a0202ab3084f880b65 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 12 Sep 2017 23:46:43 +0200 Subject: [PATCH 3/6] Remove duplicate entries --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2114cf3..614fea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,8 +145,6 @@ set (planetblupi_DEPS if ("${STATIC_BUILD}") list (APPEND planetblupi_DEPS - ${Intl_LIBRARIES} - ${Iconv_LIBRARIES} ${SDL2_STATIC_LIBRARIES} ${SDL2_MIXER_STATIC_LIBRARIES} ${SDL2_IMAGE_STATIC_LIBRARIES} From 77b42b1d37a8a7c4a99c8c3e3ed1afeef2d7ec79 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 13 Sep 2017 00:03:01 +0200 Subject: [PATCH 4/6] Add pthread linking when dynamic --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 614fea3..58e3d7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,10 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${STATIC_BUILD}") set (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") endif () +if (NOT "${STATIC_BUILD}") + set (CMAKE_EXE_LINKER_FLAGS "-lpthread") +endif () + if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") endif () From 98e29b56b7374ad1687c6f08625b76d296be4fa7 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 13 Sep 2017 00:03:20 +0200 Subject: [PATCH 5/6] Add local include and lib dirs only with static build --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58e3d7a..1c20b2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,8 +98,10 @@ endif (MINGW) # Dependencies -set (CMAKE_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/include) -set (CMAKE_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib) +if ("${STATIC_BUILD}") + set (CMAKE_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/include) + set (CMAKE_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib) +endif () find_package (Intl REQUIRED) include_directories (${Intl_INCLUDE_DIRS}) From 73f916093fb387eefd70b4b4599c18c18cb227ae Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 13 Sep 2017 00:03:51 +0200 Subject: [PATCH 6/6] Pass intl and iconv static lib only with static linking --- CMakeLists.txt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c20b2b..67f3c9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,13 +144,10 @@ endif () add_executable (planetblupi ${sources}) -set (planetblupi_DEPS - ${Intl_LIBRARIES} - ${Iconv_LIBRARIES} -) - if ("${STATIC_BUILD}") - list (APPEND planetblupi_DEPS + set (planetblupi_DEPS + ${Intl_LIBRARIES} + ${Iconv_LIBRARIES} ${SDL2_STATIC_LIBRARIES} ${SDL2_MIXER_STATIC_LIBRARIES} ${SDL2_IMAGE_STATIC_LIBRARIES} @@ -172,7 +169,7 @@ if ("${STATIC_BUILD}") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_INSTALL_PREFIX}/lib/pulseaudio") endif () else () - list (APPEND planetblupi_DEPS + set (planetblupi_DEPS ${SDL2_LIBRARIES} ${SDL2_MIXER_LIBRARIES} ${SDL2_IMAGE_LIBRARIES}