Files
ortools-clone/patches/protobuf.patch
Corentin Le Molgat 02877e28f1 [UNIX][DEPS] Build dependencies as dynamic libs
Unix:
- Rename install_directories rule
  this target creates dependencies/install dir not ortools install dir
- replace $(LIB_SUFFIX) by $L to be consistent with $E and $O suffix
- fix rpath, no need anymore patchelf
  -> remove prerequisite $(PATCHELF) in install_cc
- use build_cmake as build directory
  note: MacOS is case insensitive when creating directory
  and bazel file is named BUILD -> `mkdir build` won't work
- Fix CMD_LNK on mac
- Fix MacOS LINK_FLAGS
- MacOS also use LIB_DIR = lib

Win:
- Fix windows lib suffix $L

Protobuf:
- Need to use PROTOC (like MONO) to add LD_LIBRARY_PATH hack
  -> PROTOC = LD_LIBARY_PATH="..." protoc
  -> replace $(PROTOBUF_DIR)/bin/protoc by $(PROTOC)
- Remove uneeded PROTOBUF_DIR defs
- Apply patch to protobuf to use @rpath on MacOS
- Add rpath to protobuf install rules

Coin-OR
- Use coin-or github repos mirror instead of the svn repo (Fix #379)
- Use the splited Cbc (CoinUtils, Osi, Clp, Cgl, Cbc)
note: usually distro use this layout cf https://repology.org/metapackage/coin-or-cbc/badges
- Fix rpath for all coin-or libraries at post-install using patchelf (linux) or otools (osx)
2018-05-28 08:08:49 +02:00

160 lines
6.0 KiB
Diff

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index f159f60e..83bc4a8c 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -7,6 +7,14 @@ endif()
# CMake policies
cmake_policy(SET CMP0022 NEW)
+# Clear VERSION variables when no VERSION is given to project()
+if (POLICY CMP0048)
+ cmake_policy(SET CMP0048 NEW)
+endif ()
+# On MacOS use @rpath for target's install name
+if (POLICY CMP0042)
+ cmake_policy(SET CMP0042 NEW)
+endif ()
# Project
project(protobuf C CXX)
@@ -21,13 +29,8 @@ else (BUILD_SHARED_LIBS)
endif (BUILD_SHARED_LIBS)
option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT})
include(CMakeDependentOption)
-cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON
- "NOT protobuf_BUILD_SHARED_LIBS" OFF)
-if (MSVC)
- set(protobuf_WITH_ZLIB_DEFAULT OFF)
-else (MSVC)
- set(protobuf_WITH_ZLIB_DEFAULT ON)
-endif (MSVC)
+option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" OFF)
+set(protobuf_WITH_ZLIB_DEFAULT ON)
option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT})
set(protobuf_DEBUG_POSTFIX "d"
CACHE STRING "Default debug postfix")
@@ -157,7 +160,7 @@ if (MSVC)
string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR})
string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR})
configure_file(extract_includes.bat.in extract_includes.bat)
-
+
# Suppress linker warnings about files with no symbols defined.
set(CMAKE_STATIC_LINKER_FLAGS /ignore:4221)
endif (MSVC)
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 441bf553..e98b316f 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -13,6 +13,13 @@ foreach(_library
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${protobuf_source_dir}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+ if (UNIX AND NOT APPLE)
+ set_property(TARGET ${_library}
+ PROPERTY INSTALL_RPATH "$ORIGIN")
+ elseif (APPLE)
+ set_property(TARGET ${_library}
+ PROPERTY INSTALL_RPATH "@loader_path")
+ endif()
install(TARGETS ${_library} EXPORT protobuf-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
@@ -21,6 +28,13 @@ endforeach()
install(TARGETS protoc EXPORT protobuf-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
+if (UNIX AND NOT APPLE)
+ set_property(TARGET protoc
+ PROPERTY INSTALL_RPATH "$ORIGIN/../lib")
+elseif (APPLE)
+ set_property(TARGET protoc
+ PROPERTY INSTALL_RPATH "@loader_path/../lib")
+endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
@@ -100,22 +114,24 @@ configure_file(protobuf-module.cmake.in
configure_file(protobuf-options.cmake
${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
-# Allows the build directory to be used as a find directory.
-export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
- NAMESPACE protobuf::
- FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
-)
-
install(EXPORT protobuf-targets
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
NAMESPACE protobuf::
COMPONENT protobuf-export)
-
-install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/
+install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
- COMPONENT protobuf-export
- PATTERN protobuf-targets.cmake EXCLUDE
-)
+ COMPONENT protobuf-export)
+if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
+ # Allows the build directory to be used as a find directory.
+ export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
+ NAMESPACE protobuf::
+ FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
+ )
+endif()
option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF)
if(protobuf_INSTALL_EXAMPLES)
diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake
index 9e1fab0a..d23bfc9a 100644
--- a/cmake/libprotobuf-lite.cmake
+++ b/cmake/libprotobuf-lite.cmake
@@ -60,5 +60,7 @@ if(MSVC AND protobuf_BUILD_SHARED_LIBS)
PRIVATE LIBPROTOBUF_EXPORTS)
endif()
set_target_properties(libprotobuf-lite PROPERTIES
+ VERSION ${protobuf_VERSION}
OUTPUT_NAME ${LIB_PREFIX}protobuf-lite
DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
+add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite)
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 72db915b..43225696 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -125,5 +125,9 @@ if(MSVC AND protobuf_BUILD_SHARED_LIBS)
PRIVATE LIBPROTOBUF_EXPORTS)
endif()
set_target_properties(libprotobuf PROPERTIES
+ VERSION ${protobuf_VERSION}
OUTPUT_NAME ${LIB_PREFIX}protobuf
DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
+add_library(protobuf::libprotobuf ALIAS libprotobuf)
+# CMake define findProtobuf which import protobuf::* targets
+add_library(Protobuf ALIAS libprotobuf)
diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake
index 107c1c52..4cc2dfc2 100644
--- a/cmake/libprotoc.cmake
+++ b/cmake/libprotoc.cmake
@@ -225,5 +225,7 @@ if(MSVC AND protobuf_BUILD_SHARED_LIBS)
endif()
set_target_properties(libprotoc PROPERTIES
COMPILE_DEFINITIONS LIBPROTOC_EXPORTS
+ VERSION ${protobuf_VERSION}
OUTPUT_NAME ${LIB_PREFIX}protoc
DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
+add_library(protobuf::libprotoc ALIAS libprotoc)
diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake
index 4f07c389..5777b16e 100644
--- a/cmake/protoc.cmake
+++ b/cmake/protoc.cmake
@@ -4,3 +4,4 @@ set(protoc_files
add_executable(protoc ${protoc_files})
target_link_libraries(protoc libprotobuf libprotoc)
+add_executable(protobuf::protoc ALIAS protoc)