问题
I have been trying to build RPM
packages for libc++
3.3 on a RHEL 6.4 box. I need both static and shared libraries. So, I learned some basics of cmake
and then modified the bundled CMakeList.txt
. Got that part to work.
But since in RHEL 6.x, all 64-bit libraries should go to /usr/lib64
instead of /usr/lib
, I have been attempting to use the following to get the job done:
(A) During building, I use
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX})
to have all library files (*.so*
and *.a
) located in lib64
rather than lib
.
(B) Using a ADD_LIBRARY...
command as shown below
ADD_LIBRARY(c++ STATIC ...
together with
set_target_properties(c++ PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX})
INSTALL(TARGETS c++
ARCHIVE DESTINATION lib${LIB_SUFFIX})
to get the static library installed in /usr/lib64
.
(C) In addition, with
INSTALL(FILES ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/libc++.so DESTINATION lib${LIB_SUFFIX})
INSTALL(FILES ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/libc++.so.1 DESTINATION lib${LIB_SUFFIX})
INSTALL(FILES ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/libc++.so.1.0 DESTINATION lib${LIB_SUFFIX})
to have shared libary also installed in /usr/lib64
too.
But a copy of the shared library is still installed in /usr/lib
in the resulting RPM. How can I prevent it?
If I were to write a RPM spec
file, the _libdir
macro automatically handles this. With cmake
, given the fact that I am still new to it, I would appreciate a hint/pointer as to the right directive to use.
回答1:
Actually, with a helpful person in the cmake
mailing list, I am now able to rid of the %dir /usr/lib
in the generated spec
file. It's actually quite simple: just cd to $CMAKE_SOURCE_DIR/lib
and edit the CMakeLists.txt
there. Append ${LIB_SUFFIX}
to the two install DESTINATION
s. Regenerate the Makefile
in the build
subdirectory, and then make && make package
. All library files go into /usr/lib64
as desired.
回答2:
What I can see:
1) There's a missing space in ARCHIVE_OUTPUT_DIRECTORY${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX})
, should be ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX})
2) When are your .so files going to be build if you use ADD_LIBRARY(c++ STATIC ...
?
来源:https://stackoverflow.com/questions/17894736/how-to-enable-cmake-to-exclude-a-subdirectory-from-install