Search code examples
cmakedeblibc++cpack

Cmake/cpack: how to create a libc++ static library deb without headers?


I have been trying to create a deb for LLVM libc++ 3.4 on a Ubuntu 12.04LTS 64bit box tonight. I would like to first create a deb that just consists of just /usr/lib64/libc++.a without any headers. Yes, I know per Debian library packaging guide, I should include the file in a *-dev package, But being new to cmake and cpack, I would like to get there incrementally.

So, I first changed the libcxx-3.4/lib/CMakeLists.txt and added an if check (see line 14 and 18)

$ cat CMakeLists.txt
 1  if (NOT LIBCXX_INSTALL_SUPPORT_HEADERS)
 2    set(LIBCXX_SUPPORT_HEADER_PATTERN PATTERN "support" EXCLUDE)
 3  endif()
 4  
 5  file(COPY .
 6    DESTINATION "${CMAKE_BINARY_DIR}/include/c++/v1"
 7    FILES_MATCHING
 8    PATTERN "*"
 9    PATTERN "CMakeLists.txt" EXCLUDE
10    PATTERN ".svn" EXCLUDE
11    ${LIBCXX_SUPPORT_HEADER_PATTERN}
12    )
13  
14  if (${LIBCXX_ENABLE_SHARED} MATCHES "ON")
15    install(DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1/"
16      DESTINATION include/c++/v1/
17      )
18  endif()

Then, at in the build subdirectory, I issued a

CC=clang CXX=clang++ cmake -j2 -G "Unix Makefiles" -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_LIBCXXABI_INCLUDE_PATHS="../libcxxabi/include" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ../libcxx -DLIBCXX_ENABLE_SHARED=OFF

The created deb still consists of all headers. If I commented out lines 14 to 18, then no headers were included in the package. I am puzzled by this. A variable defined for the parent CMakeLists.txt should be picked up by a child CMakeLists.txt. What did I miss? I would appreciate a hint or two.


Solution

  • I have figured out the answer for my own question. Being new to cmake and cpack, I initially focused on the wrong CMakeLists.txt. The install command for headers in the include/CMakeLists.txt is not the only one. The main CMakeLists.txt file has a marcro in which there is also an install command. That should be disabled too. Specifically:

    In the main CMakeLists.txt, one could do:

       129    message(STATUS "Inside of setup_abi_libs; LIBCXX_ENABLE_SHARED: ${LIBCXX_ENABLE_SHARED}")
       130    if (LIBCXX_ENABLE_SHARED)
       131      install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
       132        DESTINATION include/c++/v1
       133        FILES_MATCHING
       134        PATTERN "*"
       135        )
       136    endif()
       137  endmacro()
    

    Then, in the include/CMakeLists.txt, one could do:

    13  
    14  message(STATUS "Inside of include; LIBCXX_ENABLE_SHARED: ${LIBCXX_ENABLE_SHARED}")
    15  
    16  if (LIBCXX_ENABLE_SHARED)
    17    install(DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1/"
    18      DESTINATION include/c++/v1/
    19      )
    20  endif()
    

    This is the end result that I was trying to obtain but failed last night:

    $ dpkg-deb -c libcxx_3.4-1_amd64.deb 
    drwxrwxr-x root/root         0 2014-03-04 08:59 ./usr/
    drwxrwxr-x root/root         0 2014-03-04 08:59 ./usr/lib64/
    -rw-r--r-- root/root   1928770 2014-03-04 08:58 ./usr/lib64/libc++.a
    

    No more headers. Now I just need to figure out how to change the original CMakeLists.txt files to make a real dev package :)