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

Brett Delle Grazie brett.dellegrazie at gmail.com
Mon Jun 11 04:39:32 EDT 2012


On 31 May 2012 15:15, Brett Delle Grazie <brett.dellegrazie at gmail.com> wrote:
> 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( sample 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"
>    )

I missed a:
target_link_libraries( sample sample_static )

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

For the mailing list history:

I raised a defect for this on the CMake Mantis bug tracker:
http://public.kitware.com/Bug/view.php?id=13282

A temporary workaround is presented there which involves pretending
the CreateExportList tool
doesn't exist.

However this affects _all_ shared library builds on AIX with XLC so it
is not a permanent solution
on its own.


>
> Thanks,
>
> --
> Kind Regards,
>
> Brett Delle Grazie



-- 
Best Regards,

Brett Delle Grazie


More information about the CMake mailing list