Build position independent code when compiling Ceres statically.

- Previously, when Ceres was built as a static library we did not
  compile position independent code.  This means that the resulting
  static library could not be linked against shared libraries, but
  could be used by executables.
- To enable the use of a static Ceres library by other shared libraries
  as reported in [1], the static library must be generated from
  position independent code (except on Windows, where PIC does not
  apply).

[1] https://github.com/Itseez/opencv_contrib/pull/290#issuecomment-130389471

Change-Id: I99388f1784ece688f91b162d009578c5c97ddaf6
This commit is contained in:
Alex Stewart
2015-08-12 21:41:43 +01:00
committed by Keir Mierle
parent 860bba588b
commit 887a20ca7f
+15 -2
View File
@@ -182,8 +182,21 @@ endif (MINIGLOG)
add_library(ceres ${CERES_LIBRARY_SOURCE})
set_target_properties(ceres PROPERTIES
VERSION ${CERES_VERSION}
SOVERSION ${CERES_VERSION_MAJOR}
)
SOVERSION ${CERES_VERSION_MAJOR})
# Always build position-independent code (PIC), even when building Ceres as a
# static library so that shared libraries can link against it, not just
# executables (PIC does not apply on Windows).
if (NOT WIN32 AND NOT BUILD_SHARED_LIBS)
# Use the explicit POSITION_INDEPENDENT_CODE target property on CMake versions
# that support it (>= 2.8.9). Otherwise, manually add the -fPIC flag as an
# additional compile definitions for the target.
if (CMAKE_VERSION VERSION_LESS "2.8.9")
set_target_properties(ceres PROPERTIES COMPILE_FLAGS "-fPIC")
else()
set_target_properties(ceres PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
endif()
if (CXX11 AND COMPILER_HAS_CXX11_FLAG)
if (CMAKE_VERSION VERSION_LESS "2.8.12")
message("-- Warning: detected CMake version: ${CMAKE_VERSION} < 2.8.12, "