CMake: generate or extract the header needed for a shared library

I am currently working on a larger project that is not supported.

Explanation He tries to use CMake, but not very intuitive. Instead of including the shared libraries and headers from each submodule, you can set a flag at the top level of the CMakeList that starts add_subdirectory, sneaking the top level CMAKE_BUILD_DIR and setting it there. These CMakeLists exclusively use the RECUSE glob to find all sources, and most of the operations are not target based but global. Therefore, the main target compiles properly. Here is a small snippet of the main CMakeList

set(MY_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(MY_SOURCE_BASE_DIR "${MY_BASE_DIR}/myproject")

# includes
include(build/global.cmake)
#include(externalLibs/mz-cmaketools-master/global.cmake)


# configuration options
option(MOD1 "" ON)
option(MOD2 "" ON)
option(MOD3 "" OFF)
option(MOD4 "" OFF)
option(MOD5 "" ON)
option(MOD6 "" OFF)
option(MOD7 "" ON)

message("-- Building myproject unit-tests - ${ENABLE_MYPROJECT_TEST}")
set(CMAKE_ECLIPSE_MAKE_ARGUMENTS "-j4")

if(MOD1)
    message(STATUS "Building viral_core + viral_recon")
    add_subdirectory(${MY_BASE_DIR}/externalLibs/viral/trunk/linux)


include_directories(${MY_BASE_DIR}/externalLibs/viral/trunk/source/)
    else(MOD1)
        if(MOD3)
            message(WARNING "Building viral_core + viral_recon")
            add_subdirectory(${MY_BASE_DIR}/externalLibs/viral/trunk/linux)
            include_directories(${MY_BASE_DIR}/externalLibs/viral/trunk/source/)
        endif(MOD3)
    endif(MOD1)

# external libraries
include(${MY_BASE_DIR}/externalLibs.cmake)


include_directories(
  ${MY_BASE_DIR}
  ${MY_SOURCE_BASE_DIR}
  ${MY_BASE_DIR}/externalLibs/viral/trunk/source/
)


# depending on the supported robots we have different dependencies
if( MOD1 ) 
        set(OPT1 TRUE)
endif()

...

# collect binaries
set(LIBRARY_OUTPUT_PATH ${MY_BASE_DIR} CACHE PATH "Library output path")
set(EXECUTABLE_OUTPUT_PATH ${MY_BASE_DIR} CACHE PATH "Executable output path")
message("-- Setting executable output path: ${EXECUTABLE_OUTPUT_PATH}")
message("-- Setting library output path   : ${LIBRARY_OUTPUT_PATH}")


# collect sources

file(GLOB MY 
    "${MY_SOURCE_BASE_DIR}/*.h"
    "${MY_SOURCE_BASE_DIR}/*.cpp"
)
source_group(base FILES ${MY_BASE})#

file(GLOB MY_UTIL 
    "${MY_SOURCE_BASE_DIR}/util/*.h"
    "${MY_SOURCE_BASE_DIR}/util/*.cpp"
)
source_group(util FILES ${MY_UTIL})

file(GLOB_RECURSE MY_KINEMATICS 
    "${MY_SOURCE_BASE_DIR}/kinematics/*.h"
    "${MY_SOURCE_BASE_DIR}/kinematics/*.cpp"
) 
source_group(kinematics FILES ${MY_KINEMATICS})

file(GLOB MY_COLLISION
    "${MY_SOURCE_BASE_DIR}/collision/pqp/*.cpp"
    "${MY_SOURCE_BASE_DIR}/collision/PQP*.cpp"
)
source_group(collision FILES ${MY_COLLISION})
...
add_library(MY SHARED
    ${MY_COLLISION}
    ${MY_UTIL}
    ${MY_KINEMATICS}
    ...}
)
....

      

As a result, the project creates several libraries, but does not publish the necessary headers to use them. These libraries are located at the top level of the build directory. (no installation step)

Question

Is there a way to make CMake export the included header for lib (target). To be more precise, these headers should only appear in the source folder and below; headers from / usr / ... should not be considered. It is also legal if the headers are combined into one header. But out of ~ 1700 titles, only ~ 40 are relevant, so the simple RECURSE find does not seem adequate to me.

I've looked at GENERATE_EXPORT_HEADER but don't think this is what I'm looking for. And I don't have permission to change the project, so I want to make a patch in the SVN repository and I DO NOT want to make another copy of the repository because there are about 10 different options used there.

I would appreciate a solution or strategy

This is my first question on stackoverflow, so please be merciful :)

+3


source to share





All Articles