[CMake] AIX shared libraries

Marc CHEVRIER marc.chevrier at gmail.com
Tue Dec 18 04:36:39 EST 2018


Hi,

To manage specific flags for ar command, you can rely on rules override (see variable CMAKE_USER_MAKE_RULES_OVERRIDE and CMAKE_USER_MAKE_RULES_OVERRIDE_<LANG>).

I have attached some example I used in the past to manage cleanly 32 and 64 bits builds on AIX.
And to use these files, set variable CMAKE_USER_MAKE_RULES_OVERRIDE_CXX before the project command:
...
set (CMAKE_USER_MAKE_RULES_OVERRIDE_CXX /to/path/${CMAKE_CXX_COMPILER_ID}-CXX-Override.cmake)
…
project (…)


To create an archive holding the shared object may be the most efficient is to create a script (bash or Make script is OK) to do both actions and override variable CMAKE_CXX_CREATE_SHARED_LIBRARY:
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
                « /to/my/link/script <TARGET> <CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>  <SONAME_FLAG><TARGET_SONAME> -o <OBJECT_DIR>/shr.so <OBJECTS> <LINK_LIBRARIES>)


Le 17 déc. 2018 à 23:07 +0100, Rob Boehne <robb at datalogics.com>, a écrit :
> AIX supports two types of shared libraries, AIX-style, and System 5 (SYSV) compatibility libraries.  CMake is currently set up to exclusively work with SYSV-style (read the ld man pages for -brtl).
> To do this I’m attempting to set the commands to override linking shared libraries.  The default setup forces generating an exports list, which also gives me problems because I explicitly provide one (that is then overridden by the generated list, which comes out empty in my case).  The set commands below almost work, one of the problems is that I can’t see any way to pass flags to commands like “/bin/ar”.  Under AIX, tools like ar, nm, etc. have a strict “object file mode” that can be altered with the -X command line argument.  I couldn’t find any place to pass -X64 or -X32 to /bin/ar, and setting CMAKE_AR with a space in it results in CMAKE_AR==”/bin/ar;-X64” which is not what I want.  Adding double quotes fails because they aren’t escaped, so the command ends up being  sent with argv[0]==”/bin/ar -X64” which fails.  Escaping the space like you see below results in the same behavior.   I don’t have any static archives in the project, but I’m pretty sure there would be problems with them.   I want to create the output of the first command to look like the target filename but with a file extension of “so” rather than “a” but I don’t see any way to do that.
>
>     elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX")
>         if(${CMAKE_CXX_COMPILER_ID} STREQUAL "XL")
>             if(CMAKE_SIZEOF_VOID_P MATCHES "8")
>                 set(CMAKE_AR /bin/ar\ -X64)
>             else()
>                 set(CMAKE_AR /bin/ar\ -X32)
>             endif()
>             # override the broken commands cmake uses to build shared libs on AIX with XLC
>             set(CMAKE_SHARED_LIBRARY_SUFFIX ".a")
>             set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
>             set(CMAKE_SHARED_LINKER_FLAGS_INIT "")
>             set(CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES ".so")
>             set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-bM:SRE -bnoentry")
>             set(CMAKE_CXX_CREATE_SHARED_LIBRARY
>                 "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>  <SONAME_FLAG><TARGET_SONAME> -o <OBJECT_DIR>/shr.so <OBJECTS> <LINK_LIBRARIES>;<CMAKE_AR> -cru <TARGET> <OBJECT_DIR>/shr.so"
>                  )
>
>
>
> Rob Boehne
> Senior Software Architect | Datalogics, Inc.
> +1.312.853.8351 | robb at datalogics.com
> datalogics.com | blogs.datalogics.com
> Connect with us: Facebook | Twitter | LinkedIn | YouTube
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181218/1d87bb73/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CDC7B71C5C07488EBC57ECC24B80DA5D.png
Type: image/png
Size: 124449 bytes
Desc: not available
URL: <https://cmake.org/pipermail/cmake/attachments/20181218/1d87bb73/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: XL-CXX-RulesOverride.cmake
Type: application/octet-stream
Size: 407 bytes
Desc: not available
URL: <https://cmake.org/pipermail/cmake/attachments/20181218/1d87bb73/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: XL-RulesOverride.cmake
Type: application/octet-stream
Size: 1560 bytes
Desc: not available
URL: <https://cmake.org/pipermail/cmake/attachments/20181218/1d87bb73/attachment-0003.obj>


More information about the CMake mailing list