MantisBT - CMake
View Issue Details
0015607CMakeCMakepublic2015-06-10 06:352016-06-10 14:31
Martin Baute 
Kitware Robot 
normalminoralways
closedmoved 
CMake 3.2.3 
 
0015607: Lack of 64bit support (AIX / XL compiler)
On AIX using IBM's XL compiler, the default is for various tools (compiler, linker, ar, ...) to handle and generate 32bit binaries. To get 64bit binaries, explicit flags are necessary: -q64 for the compiler during compilation and linkage, -X64 to 'ar', 'CreateExportList' and probably a couple others I have forgotten.

As of now, setting these has to be done by the client (including a couple of tweaks, see "Steps to Reproduce"). This wouldn't be too bad, except for 64bit shared libraries.

To export symbols from the lib, the XL-supplied tool CreateExportList needs to be called with -X64 as well. Looking at Modules/Compiler/XL.cmake:

set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
  "${CMAKE_XL_CreateExportList} <OBJECT_DIR>/objects.exp <OBJECTS>"
  ...

There is no flag to be set for CreateExportList (which would require "-X64" in front of "<OBJECT_DIR>/objects.exp"). Manually setting the whole of CMAKE_${lang}_CREATE_SHARED_LIBRARY to something *with* appropriate flags is very heavy-handed, hardcoding the "-X64" into the CMake-owned file even more so. The only solution I could come up with was to hardcode CMAKE_XL_CreateExportList before calling project(), which is not a light touch either.

All told, I feel that CMake should provide a mechanics to set 32bit / 64bit / 32/64bit mode on AIX (and other platforms supporting such), which sets the various flags appropriately without further intervention by client CMakeLists.txt. Unfortunately I am not competent enough with CMake's inner workings to provide a patch, or even a suggestion.
/* mylib.cpp */

#include <iostream>
void mylib( void )
{
    std::cout << "Hello world!\n";
    return;
}

/* mytest.cpp */
void mylib( void );

int main( void )
{
    mylib();
    return 0;
}


## CMakeLists.txt ##
cmake_minimum_required( VERSION 3.2.3 FATAL_ERROR )

# This should not be necessary -- CMakeLists.txt is supposed to be
# (mostly) toolchain-agnostic!
find_program( CMAKE_XL_CreateExportList
    NAMES CreateExportList
    DOC "IBM XL CreateExportList tool"
    )
if ( AIX64 )
    set( CMAKE_XL_CreateExportList "/usr/vacpp/bin/CreateExportList -X64" )
endif()
# end_rant

project( aixproblems )

option( AIX64 "Create 64bit binaries, default: ON." ON )

add_library( mylib mylib.cpp )
add_executable( mytest mytest.cpp )

# This should not be necessary -- CMakeLists.txt is supposed to be
# (mostly) toolchain-agnostic!
if ( AIX64 )
    set_property( TARGET mylib mytest APPEND_STRING PROPERTY COMPILE_FLAGS "-q64 " )
    set_property( TARGET mylib mytest APPEND_STRING PROPERTY LINK_FLAGS "-q64 " )
    set_property( TARGET mylib mytest APPEND_STRING PROPERTY STATIC_LIBRARY_FLAGS "-X64 " )
    # AIX 'ar' requires "-X64" *before* cr / r.
    set( CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> <LINK_FLAGS> cr <TARGET> <OBJECTS>" )
    set( CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> r <TARGET> <OBJECTS>" )
    # ...and I have probably forgoten half a dozen settings,
    # and broken a couple of rules as well.
endif()
# end_rant

target_link_libraries( mytest mylib )
Mailing list thread of another CMake user with the same problem (which finally made me find a workaround for the CreateExportList issue):

https://www.mail-archive.com/cmake%40cmake.org/msg51270.html [^]
No tags attached.
Issue History
2015-06-10 06:35Martin BauteNew Issue
2015-06-10 07:48Martin BauteNote Added: 0038898
2015-06-10 08:15Martin BauteNote Edited: 0038898bug_revision_view_page.php?bugnote_id=38898#r1804
2015-06-10 08:35Brad KingNote Added: 0038900
2015-06-10 09:03Martin BauteNote Added: 0038901
2015-06-10 09:10Brad KingNote Added: 0038902
2015-06-10 09:10Brad KingStatusnew => backlog
2016-06-10 14:29Kitware RobotNote Added: 0042791
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0038898)
Martin Baute   
2015-06-10 07:48   
(edited on: 2015-06-10 08:15)
Ah. Typo.

    /usr/vacpp/bin/CreateExportList

in the "Steps to Reproduce" should of course be

    ${CMAKE_XL_CreateExportList}

And for the default "ON" on the AIX64 option to work, you need to put the option() lines on top. (I.e., the code I posted was not the code that worked as advertised. My bad.)

(0038900)
Brad King   
2015-06-10 08:35   
Until CMake gains the proposed capability, IIRC one may keep OBJECT_MODE=64 in the environment to tell the XL/AIX tools to use 64-bit mode.
(0038901)
Martin Baute   
2015-06-10 09:03   
Ah... well, I feel kind of stupid now. OBJECT_MODE=64 as environment variable indeed works flawlessly, including CreateExportList.

Sorry to have wasted your time.
(0038902)
Brad King   
2015-06-10 09:10   
Re 0015607:0038901: Great, I'm glad that works for you.

It would still be reasonable for CMake to know how to help with this one day, so I'm moving this to the backlog for now.
(0042791)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.