1

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.

user183394
  • 1,033
  • 1
  • 11
  • 20
  • Another way of posing the Q perhaps is: how do you ensure that a library is installed in /usr/lib64 on a RHEL 6.x platform - so far the most popular server platform in data centers? One more alternative is perhaps how to use `cmake` to configure `cpack` so that a certain `%dir` is excluded from the generated `spec` file? – user183394 Jul 27 '13 at 23:14
  • Can you specify: 1. the status of your build tree/location of files when you have finished building 2. where are the files after you run install 3. where you would like your files to be instead – Antonio Jul 27 '13 at 23:29
  • @Antonio: Thanks for responding. Regarding your Qs: 1. status: successful build without errors. location: `$HOME/clang3.3/libs/build_libcxx` (I always use out-of-source-build); 2. `$HOME/clang3.3/libs/build_libcxx/lib64`; 3. Both shared and static libraries to `/usr/lib64`. Right now, shared library files *.so* also show up in `/usr/lib` - IMHO undesirable. – user183394 Jul 28 '13 at 01:16
  • I think the tip given in this might be helpful: http://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-version-of-the-sam?lq=1 Maybe a better approach is to create my own `CMakeLists.txt`, add two libraries, install the include files, and then be done with it. – user183394 Jul 28 '13 at 03:42

2 Answers2

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 DESTINATIONs. Regenerate the Makefile in the build subdirectory, and then make && make package. All library files go into /usr/lib64 as desired.

user183394
  • 1,033
  • 1
  • 11
  • 20
0

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 ...?

Antonio
  • 19,451
  • 13
  • 99
  • 197
  • I have been thinking perhaps I should use the original `CMakeList.txt` and modify it until it install the resulting shared library in `/usr/lib64` (for a 64bit library build) instead of `/usr/lib` as it does now. But being new to `cmake`, I need to do some studies. The original doesn't have an explicit target (the `cxx` target is "implicitly" defined AFAICT). – user183394 Jul 28 '13 at 01:31
  • 1) Fixed. Edited the original post. It was due to cut-n-paste. My real `CMakeLists.txt` does have the space. 2) According to my `make -j4` output, the sequence shown is: (1) `[ 4%] Built target abilib_headers` (2) `[ 6%] [ 8%] [ 10%] Scanning dependencies of target cxx` (3) `[ 66%] Linking CXX static library lib64/libc++.a` (4) `[ 66%] Built target c++` (5) `[100%] Building CXX object lib/CMakeFiles/cxx.dir/__/src/future.cpp.o` `Linking CXX shared library ../lib64/libc++.so` – user183394 Jul 28 '13 at 01:52