diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -465,8 +465,10 @@ # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that # 'config-ix' use them during feature checks. It also adds them to both # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' -if(ZOS) - add_target_flags_if_supported("-fzos-le-char-mode=ebcdic") +if (LIBCXX_ASCII_ZOS_BUILD) + add_target_flags_if_supported("-DLIBCXX_BUILDING_LIBCXXABI") + add_target_flags_if_supported("-fzos-le-char-mode=ascii") + add_target_flags_if_supported("-I../${CMAKE_CXX_COMPILER_TARGET}/${LIBCXX_INSTALL_INCLUDE_DIR}") endif() if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") diff --git a/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake b/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake @@ -0,0 +1,25 @@ +# Common +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") +set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_TESTS OFF CACHE BOOL "") +set(LIBCXX_INSTALL_HEADERS OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "") + +set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") +set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "") + +set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "") +set(LLVM_ENABLE_WERROR ON CACHE BOOL "") + +# Target Specific +set(LIBCXX_ASCII_ZOS_BUILD ON CACHE BOOL + "Build ascii version of libcxx library on z/OS.") +set(LIBCXX_DLL_NAME CRTEQCXS CACHE STRING "") +set(LIBCXX_SHARED_OUTPUT_NAME "c++_a" CACHE PATH + "Output name for the shared libc++ runtime library.") +set(LIBCXX_EXCEPTION_ZOS_BUILD OFF CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") diff --git a/libcxx/cmake/caches/s390x-ibm-zos.cmake b/libcxx/cmake/caches/s390x-ibm-zos.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/s390x-ibm-zos.cmake @@ -0,0 +1,25 @@ +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +# Common +set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") +set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_TESTS ON CACHE BOOL "") + +set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXXABI_INCLUDE_TESTS ON CACHE BOOL "") + +set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "") +set(LLVM_ENABLE_WERROR ON CACHE BOOL "") + +# Target Specific +set(LIBCXX_DLL_NAME CRTEQCXE CACHE STRING "") +set(LIBCXX_EXCEPTION_DLL_NAME CRTEQCXP CACHE STRING "") +set(LIBCXX_EXCEPTION_ZOS_BUILD ON CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") + +set(LIBCXXABI_DLL_NAME CRTEQCXA CACHE STRING "") +set(LIBCXXABIXL_DLL_NAME CRTEQXLA CACHE STRING "") + +set(LLVM_EXTERNAL_UNWIND_SOURCE_DIR "$ENV{LLVM_BASE}/zos-unwind" CACHE PATH "The path to the external unwind source directory.") diff --git a/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake b/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake @@ -0,0 +1,25 @@ +# Common +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") +set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_TESTS OFF CACHE BOOL "") +set(LIBCXX_INSTALL_HEADERS OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "") + +set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") +set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "") + +set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "") +set(LLVM_ENABLE_WERROR ON CACHE BOOL "") + +# Target Specific +set(LIBCXX_ASCII_ZOS_BUILD ON CACHE BOOL + "Build ascii version of libcxx library on z/OS.") +set(LIBCXX_DLL_NAME CRTEHCXS CACHE STRING "") +set(LIBCXX_SHARED_OUTPUT_NAME "c++_a" CACHE PATH + "Output name for the shared libc++ runtime library.") +set(LIBCXX_EXCEPTION_ZOS_BUILD OFF CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") diff --git a/libcxx/cmake/caches/s390x32-ibm-zos.cmake b/libcxx/cmake/caches/s390x32-ibm-zos.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/s390x32-ibm-zos.cmake @@ -0,0 +1,26 @@ +# Common +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") +set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "") +set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_TESTS ON CACHE BOOL "") + +set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXXABI_INCLUDE_TESTS ON CACHE BOOL "") + +set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "") +set(LLVM_ENABLE_WERROR ON CACHE BOOL "") + +# Target Specific +set(LIBCXX_DLL_NAME CRTEHCXE CACHE STRING "") +set(LIBCXX_EXCEPTION_DLL_NAME CRTEHCXP CACHE STRING "") +set(LIBCXX_EXCEPTION_ZOS_BUILD ON CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") + +set(LIBCXXABI_DLL_NAME CRTEHCXA CACHE STRING "") +set(LIBCXXABIXL_DLL_NAME CRTEHXLA CACHE STRING "") + +set(LLVM_EXTERNAL_UNWIND_SOURCE_DIR "$ENV{LLVM_BASE}/zos-unwind" CACHE PATH "The path to the external unwind source directory.") diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -196,10 +196,13 @@ # Build the shared library. if (LIBCXX_ENABLE_SHARED) + add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - target_link_libraries(cxx_shared PUBLIC cxx-headers - PRIVATE ${LIBCXX_LIBRARIES}) + if (NOT LIBCXX_ASCII_ZOS_BUILD) + target_link_libraries(cxx_shared PUBLIC cxx-headers + PRIVATE ${LIBCXX_LIBRARIES}) + endif() set_target_properties(cxx_shared PROPERTIES COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" @@ -212,10 +215,24 @@ cxx_add_common_build_flags(cxx_shared) cxx_set_common_defines(cxx_shared) + if(ZOS) + STRING(REGEX REPLACE "-ascii/lib$" "/lib" SIDEDECK_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + target_link_libraries(cxx_shared PRIVATE + "-Wl,${SIDEDECK_DIR}/libunwind.x,${SIDEDECK_DIR}/libc++abi.x") + + add_custom_command(TARGET cxx_shared POST_BUILD + COMMAND + ${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh + $ $ "${LIBCXX_DLL_NAME}" + COMMENT "Rename dll name inside the side deck file" + WORKING_DIRECTORY $ + ) + endif() + # Link against libc++abi if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) target_link_libraries(cxx_shared PRIVATE libcxx-abi-shared-objects) - else() + elseif(NOT ZOS) target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared) endif()