From 4a4d8b4e26e5b5405cb44970e832e9d22bc58ec4 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 11 Dec 2019 13:51:16 +0100 Subject: [PATCH] Fix zlib dependencies and CMAKE_MODULE_PATH forwarding --- deps/CMakeLists.txt | 1 + deps/OpenCSG/CMakeLists.txt.in | 2 + deps/OpenCSG/OpenCSG.cmake | 4 ++ .../ZLIB/0001-Respect-BUILD_SHARED_LIBS.patch | 51 ++++++++++++++++ deps/ZLIB/ZLIB.cmake | 10 ++++ deps/deps-unix-common.cmake | 5 +- deps/deps-windows.cmake | 59 ++++++++++--------- 7 files changed, 102 insertions(+), 30 deletions(-) create mode 100644 deps/ZLIB/0001-Respect-BUILD_SHARED_LIBS.patch create mode 100644 deps/ZLIB/ZLIB.cmake diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 8af8a8f96..d5c510853 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -67,6 +67,7 @@ function(prusaslicer_add_cmake_project projectname) ${_gen} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local + -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules -DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local -DCMAKE_DEBUG_POSTFIX:STRING=d -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} diff --git a/deps/OpenCSG/CMakeLists.txt.in b/deps/OpenCSG/CMakeLists.txt.in index 83f3665b6..37da0f789 100644 --- a/deps/OpenCSG/CMakeLists.txt.in +++ b/deps/OpenCSG/CMakeLists.txt.in @@ -9,6 +9,8 @@ elseif (MSVC) endif() find_package(OpenGL REQUIRED) + +set(GLEW_VERBOSE ON) find_package(GLEW 1.13.0 REQUIRED) set(_srcfiles diff --git a/deps/OpenCSG/OpenCSG.cmake b/deps/OpenCSG/OpenCSG.cmake index fb904d53d..d9de5e152 100644 --- a/deps/OpenCSG/OpenCSG.cmake +++ b/deps/OpenCSG/OpenCSG.cmake @@ -6,6 +6,10 @@ prusaslicer_add_cmake_project(OpenCSG DEPENDS dep_GLEW ) +if (TARGET dep_ZLIB) + add_dependencies(dep_OpenCSG dep_ZLIB) +endif() + if (MSVC) add_debug_dep(dep_OpenCSG) endif () \ No newline at end of file diff --git a/deps/ZLIB/0001-Respect-BUILD_SHARED_LIBS.patch b/deps/ZLIB/0001-Respect-BUILD_SHARED_LIBS.patch new file mode 100644 index 000000000..e65ec0e65 --- /dev/null +++ b/deps/ZLIB/0001-Respect-BUILD_SHARED_LIBS.patch @@ -0,0 +1,51 @@ +From 0c64e33bc2e4e7c011f5a64f5d9c7571a434cc86 Mon Sep 17 00:00:00 2001 +From: tamasmeszaros +Date: Sat, 16 Nov 2019 13:43:17 +0100 +Subject: [PATCH] Respect BUILD_SHARED_LIBS + +--- + CMakeLists.txt | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0fe939d..01dfea1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -183,10 +183,12 @@ if(MINGW) + set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) + endif(MINGW) + +-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +-set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) +-set_target_properties(zlib PROPERTIES SOVERSION 1) ++add_library(zlib ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) ++if (BUILD_SHARED_LIBS) ++ target_sources(zlib PRIVATE ${ZLIB_DLL_SRCS}) ++ set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) ++ set_target_properties(zlib PROPERTIES SOVERSION 1) ++endif() + + if(NOT CYGWIN) + # This property causes shared libraries on Linux to have the full version +@@ -201,7 +203,7 @@ endif() + + if(UNIX) + # On unix-like platforms the library is almost always called libz +- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) ++ set_target_properties(zlib PROPERTIES OUTPUT_NAME z) + if(NOT APPLE) + set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") + endif() +@@ -211,7 +213,7 @@ elseif(BUILD_SHARED_LIBS AND WIN32) + endif() + + if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) +- install(TARGETS zlib zlibstatic ++ install(TARGETS zlib + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) +-- +2.16.2.windows.1 + diff --git a/deps/ZLIB/ZLIB.cmake b/deps/ZLIB/ZLIB.cmake new file mode 100644 index 000000000..574f5b134 --- /dev/null +++ b/deps/ZLIB/ZLIB.cmake @@ -0,0 +1,10 @@ +prusaslicer_add_cmake_project(ZLIB + GIT_REPOSITORY https://github.com/madler/zlib.git + GIT_TAG v1.2.11 + PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df && + ${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-Respect-BUILD_SHARED_LIBS.patch + CMAKE_ARGS + -DSKIP_INSTALL_FILES=ON # Prevent installation of man pages et al. + -DCMAKE_POSITION_INDEPENDENT_CODE=ON +) + diff --git a/deps/deps-unix-common.cmake b/deps/deps-unix-common.cmake index b6e6653cd..ad06ae77f 100644 --- a/deps/deps-unix-common.cmake +++ b/deps/deps-unix-common.cmake @@ -7,7 +7,10 @@ else () set(TBB_MINGW_WORKAROUND "") endif () -find_package(ZLIB REQUIRED) +find_package(ZLIB QUIET) +if (NOT ZLIB_FOUND) + include(ZLIB/ZLIB.cmake) +endif () ExternalProject_Add(dep_tbb EXCLUDE_FROM_ALL 1 diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index 276129a8d..fc1823dc7 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -149,36 +149,37 @@ ExternalProject_Add(dep_nlopt add_debug_dep(dep_nlopt) -ExternalProject_Add(dep_zlib - EXCLUDE_FROM_ALL 1 - URL "https://zlib.net/zlib-1.2.11.tar.xz" - URL_HASH SHA256=4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066 - CMAKE_GENERATOR "${DEP_MSVC_GEN}" - CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}" - CMAKE_ARGS - -DSKIP_INSTALL_FILES=ON # Prevent installation of man pages et al. - "-DINSTALL_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}\\fallout" # I found no better way of preventing zlib from creating & installing DLLs :-/ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - "-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local" - BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj - INSTALL_COMMAND "" -) +include(ZLIB/ZLIB.cmake) +# ExternalProject_Add(dep_zlib +# EXCLUDE_FROM_ALL 1 +# URL "https://zlib.net/zlib-1.2.11.tar.xz" +# URL_HASH SHA256=4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066 +# CMAKE_GENERATOR "${DEP_MSVC_GEN}" +# CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}" +# CMAKE_ARGS +# -DSKIP_INSTALL_FILES=ON # Prevent installation of man pages et al. +# "-DINSTALL_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}\\fallout" # I found no better way of preventing zlib from creating & installing DLLs :-/ +# -DCMAKE_POSITION_INDEPENDENT_CODE=ON +# "-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local" +# BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj +# INSTALL_COMMAND "" +# ) -add_debug_dep(dep_zlib) +add_debug_dep(dep_ZLIB) # The following steps are unfortunately needed to remove the _static suffix on libraries -ExternalProject_Add_Step(dep_zlib fix_static - DEPENDEES install - COMMAND "${CMAKE_COMMAND}" -E rename zlibstatic.lib zlib.lib - WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" -) -if (${DEP_DEBUG}) - ExternalProject_Add_Step(dep_zlib fix_static_debug - DEPENDEES install - COMMAND "${CMAKE_COMMAND}" -E rename zlibstaticd.lib zlibd.lib - WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" - ) -endif () +# ExternalProject_Add_Step(dep_zlib fix_static +# DEPENDEES install +# COMMAND "${CMAKE_COMMAND}" -E rename zlibstatic.lib zlib.lib +# WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" +# ) +# if (${DEP_DEBUG}) +# ExternalProject_Add_Step(dep_zlib fix_static_debug +# DEPENDEES install +# COMMAND "${CMAKE_COMMAND}" -E rename zlibstaticd.lib zlibd.lib +# WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" +# ) +# endif () if (${DEPS_BITS} EQUAL 32) set(DEP_LIBCURL_TARGET "x86") @@ -273,7 +274,7 @@ ExternalProject_Add(dep_blosc #URL_HASH SHA256=7463a1df566704f212263312717ab2c36b45d45cba6cd0dccebf91b2cc4b4da9 GIT_REPOSITORY https://github.com/Blosc/c-blosc.git GIT_TAG e63775855294b50820ef44d1b157f4de1cc38d3e #v1.17.0 - DEPENDS dep_zlib + DEPENDS dep_ZLIB CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}" CMAKE_ARGS @@ -300,7 +301,7 @@ ExternalProject_Add(dep_openexr EXCLUDE_FROM_ALL 1 GIT_REPOSITORY https://github.com/openexr/openexr.git GIT_TAG eae0e337c9f5117e78114fd05f7a415819df413a #v2.4.0 - DEPENDS dep_zlib + DEPENDS dep_ZLIB CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}" CMAKE_ARGS