Add "ObjectLibrary" test to build and use OBJECT libraries. Build multiple object libraries in separate directories with different flags. Use a custom command to generate a source file in one OBJECT library. Reference the OBJECT libraries for inclusion in a STATIC library, a SHARED library, and an EXECUTABLE target. Use the static and shared libraries each in executables that end up using the object library symbols. Verify that object library symbols are exported from the shared library.
18 lines
501 B
CMake
18 lines
501 B
CMake
# Add -fPIC so objects can be used in shared libraries.
|
|
# TODO: Need property for this.
|
|
if(CMAKE_SHARED_LIBRARY_C_FLAGS)
|
|
set(CMAKE_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_C_FLAGS}")
|
|
endif()
|
|
|
|
add_definitions(-DA)
|
|
|
|
add_custom_command(
|
|
OUTPUT a1.c
|
|
DEPENDS a1.c.in
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in
|
|
${CMAKE_CURRENT_BINARY_DIR}/a1.c
|
|
)
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
add_library(A OBJECT a1.c a2.c)
|