C/C++ and Fortran

 View Only

The IBM Open XL C/C++ compiler is now supported by CMake starting from version 3.23

By Aaron Liu posted Thu February 17, 2022 02:37 PM

  
The IBM Open XL C/C++ compiler, based on LLVM, is now supported since CMake 3.23. The compiler ID with which CMake recognizes this compiler is called IBMClang. In the official release note of CMake 3.23, the announcement mentions support for IBMClang among the significant new features.

Basic support for IBM Open XL C/C++ compiler in CMake 3.23 includes features such as: different C/C++ language levels support, different compiler options support, and the most important one is the support of compiler ID IBMClang. For example, before CMake 3.23, when you build with Open XL C/C++ compiler, you may notice the following weird output:

-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0

Since the major release of CMake 3.23, when you build with Open XL C/C++ compiler, you will see that Open XL C/C++ is supported with compiler ID IBMClang:

-- The C compiler identification is IBMClang 17.1.0.0
-- The CXX compiler identification is IBMClang 17.1.0.0

Starting from CMake 3.23, your build configuration can conditionally control aspects specific to the IBM Open XL C/C++ compiler by using CMAKE_C_COMPILER_ID/CMAKE_CXX_COMPILER_ID STREQUAL/MATCHES IBMClang. For example, if you want to set '-std=c++14' option for the IBM Open XL C++ compiler, and set '-std=c11' option for the IBM Open XL C compiler. You can write code in CMake like the following:

  if (CMAKE_CXX_COMPILER_ID MATCHES IBMClang)
   set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
  endif()

  if (CMAKE_C_COMPILER_ID MATCHES IBMClang)
   set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
  endif()

Or

  if (CMAKE_CXX_COMPILER_ID STREQUAL "IBMClang")
   set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
  endif()

  if (CMAKE_C_COMPILER_ID MATCHES "IBMClang")
   set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
  endif()

You can see that it is very convenient when you have a compiler ID IBMClang!


References:
  1. Next generation of IBM C/C++ & Fortran compilers are generally available on AIX: https://community.ibm.com/community/user/power/blogs/si-yuan-zhang1/2021/09/17/ibm-next-generation-compilers-llvm?CommunityKey=5d23d564-1e3e-47e6-8e47-71b8b65eedfd&tab=recentcommunityblogsdashboard
  2. CMake 3.23 Release Notes: https://cmake.org/cmake/help/git-stage/release/3.23.html#new-features
0 comments
62 views

Permalink