2012-02-03 19:26:49 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# according to man pkg-config
|
|
|
|
# The package name specified on the pkg-config command line is defined to
|
|
|
|
# be the name of the metadata file, minus the .pc extension. If a library
|
|
|
|
# can install multiple versions simultaneously, it must give each version
|
|
|
|
# its own name (for example, GTK 1.2 might have the package name "gtk+"
|
|
|
|
# while GTK 2.0 has "gtk+-2.0").
|
|
|
|
#
|
|
|
|
# ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install"
|
|
|
|
# -------------------------------------------------------------------------------------------
|
|
|
|
|
2015-05-19 21:15:54 +08:00
|
|
|
macro(fix_prefix lst isown)
|
|
|
|
set(_lst)
|
|
|
|
foreach(item ${${lst}})
|
|
|
|
if(TARGET ${item})
|
|
|
|
get_target_property(item "${item}" LOCATION_${CMAKE_BUILD_TYPE})
|
|
|
|
if("${isown}")
|
|
|
|
get_filename_component(item "${item}" NAME_WE)
|
|
|
|
string(REGEX REPLACE "^lib(.*)" "\\1" item "${item}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(item MATCHES "^-l")
|
|
|
|
list(APPEND _lst "${item}")
|
|
|
|
elseif(item MATCHES "[\\/]")
|
|
|
|
get_filename_component(libdir "${item}" PATH)
|
|
|
|
get_filename_component(libname "${item}" NAME_WE)
|
|
|
|
string(REGEX REPLACE "^lib(.*)" "\\1" libname "${libname}")
|
|
|
|
list(APPEND _lst "-L${libdir}" "-l${libname}")
|
|
|
|
else()
|
|
|
|
list(APPEND _lst "-l${item}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${lst} ${_lst})
|
|
|
|
unset(_lst)
|
|
|
|
endmacro()
|
2012-02-03 19:26:49 +08:00
|
|
|
|
2015-05-19 21:15:54 +08:00
|
|
|
# build the list of opencv libs and dependencies for all modules
|
|
|
|
ocv_get_all_libs(_modules _extra _3rdparty)
|
2012-02-03 19:26:49 +08:00
|
|
|
|
|
|
|
#build the list of components
|
|
|
|
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
# Note:
|
|
|
|
# when linking against static libraries, if libfoo depends on libbar, then
|
|
|
|
# libfoo must come first in the linker flags.
|
2012-02-03 19:26:49 +08:00
|
|
|
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
# world and contrib_world are special targets whose library should come first,
|
|
|
|
# especially for static link.
|
2015-05-19 21:15:54 +08:00
|
|
|
if(_modules MATCHES "opencv_world")
|
|
|
|
set(_modules "opencv_world")
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
endif()
|
|
|
|
|
2015-05-19 21:15:54 +08:00
|
|
|
if(_modules MATCHES "opencv_contrib_world")
|
|
|
|
list(REMOVE_ITEM _modules "opencv_contrib_world")
|
|
|
|
list(INSERT _modules 0 "opencv_contrib_world")
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
endif()
|
|
|
|
|
2015-05-19 21:15:54 +08:00
|
|
|
fix_prefix(_modules TRUE)
|
|
|
|
fix_prefix(_extra FALSE)
|
|
|
|
fix_prefix(_3rdparty TRUE)
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
|
2015-05-19 21:15:54 +08:00
|
|
|
ocv_list_unique(_modules)
|
|
|
|
ocv_list_unique(_extra)
|
|
|
|
ocv_list_unique(_3rdparty)
|
2012-02-03 19:26:49 +08:00
|
|
|
|
2015-05-19 21:15:54 +08:00
|
|
|
set(OPENCV_PC_LIBS
|
|
|
|
"-L\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}"
|
|
|
|
"${_modules}"
|
|
|
|
)
|
|
|
|
if (BUILD_SHARED_LIBS)
|
|
|
|
set(OPENCV_PC_LIBS_PRIVATE "${_extra}")
|
|
|
|
else()
|
|
|
|
set(OPENCV_PC_LIBS_PRIVATE
|
|
|
|
"-L\${exec_prefix}/${OPENCV_3P_LIB_INSTALL_PATH}"
|
|
|
|
"${_3rdparty}"
|
|
|
|
"${_extra}"
|
|
|
|
)
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
2015-05-19 21:15:54 +08:00
|
|
|
string(REPLACE ";" " " OPENCV_PC_LIBS "${OPENCV_PC_LIBS}")
|
|
|
|
string(REPLACE ";" " " OPENCV_PC_LIBS_PRIVATE "${OPENCV_PC_LIBS_PRIVATE}")
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
#generate the .pc file
|
cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation
Using absolute path to locate the components in the "Libs:" field of the
*.pc can badly break cross-compilation, especially when building
statically linked objects.
Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths
when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment
variables are set [1]. This feature is very helpful and common in
cross-compilation framework like Buildroot [2,3].
When there are absolute paths in the *.pc files, pkg-config won't be
able to do the path substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute paths will point to:
- in the best case: a non-existing file (i.e. these files do not exists
on the host system;
- at worst: the host system's libraries. This will make the linking
failed because these host system's libraries will most likely not be
build for the target architecture [4].
So, this patch replace the components' absolute paths by the form:
-L<libdir> -l<libname>
This way, the linker will be able to resolve each dependency path,
whatever the kind of objects/build (shared object or static build) it
is dealing with.
Note that for static link, the library order does matter [5]. The order
of the opencv components has been carefully chosen to comply with this
requirement.
Fixes #3931
This patch is a port of [6] on the master branch.
[1] http://linux.die.net/man/1/pkg-config
[2] http://buildroot.org/
[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in
[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log
[5] http://stackoverflow.com/questions/45135/linker-order-gcc
[6] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2014-10-03 06:32:40 +08:00
|
|
|
set(prefix "${CMAKE_INSTALL_PREFIX}")
|
|
|
|
set(exec_prefix "\${prefix}")
|
|
|
|
set(libdir "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}")
|
|
|
|
set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}")
|
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
if(INSTALL_TO_MANGLED_PATHS)
|
|
|
|
set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc")
|
|
|
|
else()
|
|
|
|
set(OPENCV_PC_FILE_NAME opencv.pc)
|
|
|
|
endif()
|
2013-11-14 23:14:38 +08:00
|
|
|
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in"
|
|
|
|
"${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}"
|
2014-01-29 23:34:02 +08:00
|
|
|
@ONLY)
|
2012-02-03 19:26:49 +08:00
|
|
|
|
|
|
|
if(UNIX AND NOT ANDROID)
|
2014-01-17 20:30:31 +08:00
|
|
|
install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev)
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|