[CMake] AIX exports, CMAKE_C_CREATE_SHARED_LIBRARY, custom commands and OBJECT_DIR property

Brett Delle Grazie brett.dellegrazie at gmail.com
Thu May 31 10:15:57 EDT 2012


Hi,

Is there any way to supplant / override the C
CMAKE_C_CREATE_SHARED_LIBRARY rule for a specific target (and only
that target) on AIX?
Or alternatively, is there any way to retrieve or construct the
OBJECT_DIR property of a library target (i.e. where the compiled .o
files wind up)
in a custom command?

Specifically:
On AIX we have an externally supplied static library that we are
converting into a shared library. We have:
the static library (sample.a)
a header file (sample.h)
an exports file (sample.exp)

PROJECT(sample)
cmake_minimum_required(VERSION 2.8)
set(USE_FOLDERS ON)

include(GNUInstallDirs)
include(GenerateExportHeader)
add_compiler_export_flags()

set(SAMPLE_SRCS
    sample.h)

# static library variant (supplied)
add_library( sample_static STATIC IMPORTED )
set_target_properties( sample_static PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/sample.a )

# make the shared variant (explicitly supply the export as we don't
really have any sources apart from the headers)
add_library( polaris SHARED ${SAMPLE_SRCS} )
set_target_properties( sample PROPERTIES
    LINKER_LANGUAGE C
    PUBLIC_HEADER "${SAMPLE_SRCS}"
    LINK_FLAGS "-bE:${CMAKE_CURRENT_SOURCE_DIR}/sample.exp -bM:SRE -bnoentry"
    )

With just the above, the build will fail with a missing objects.exp.
This is a file generated by the CMAKE_C_CREATE_SHARED_LIBRARY on AIX
which includes an implicit call to CMAKE_XL_CreateExportList. Since we
don't actually compile any objects, the build fails.

I've tried to add a custom rule below to touch the objects.exp so that
it is supplied along with our actual sample.exp but I'm having trouble
locating the object directory where it looks for the objects.exp file.

# the custom rule below fails because OBJECT_DIR is not a recognised generator
add_custom_command( TARGET sample
                    PRE_LINK
                    COMMAND ${CMAKE_COMMAND} -E touch
$<OBJECT_DIR:sample>/objects.exp
                    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
                    VERBATIM)

Can anyone help with either the custom rule, a pointer on how to
override CMAKE_C_CREATE_SHARED_LIBRARY for just this target or a more
suitable technique?

Thanks,

-- 
Kind Regards,

Brett Delle Grazie


More information about the CMake mailing list