[cmake-developers] [CMake 0015607]: Lack of 64bit support (AIX / XL compiler)

Mantis Bug Tracker mantis at public.kitware.com
Wed Jun 10 06:35:15 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=15607 
====================================================================== 
Reported By:                Martin Baute
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15607
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-06-10 06:35 EDT
Last Modified:              2015-06-10 06:35 EDT
====================================================================== 
Summary:                    Lack of 64bit support (AIX / XL compiler)
Description: 
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.

Steps to Reproduce: 
/* 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 )


Additional Information: 
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
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-06-10 06:35 Martin Baute   New Issue                                    
======================================================================



More information about the cmake-developers mailing list