Path: blob/master/runtime/compiler/CMakeLists.txt
5986 views
################################################################################1# Copyright (c) 2017, 2022 IBM Corp. and others2#3# This program and the accompanying materials are made available under4# the terms of the Eclipse Public License 2.0 which accompanies this5# distribution and is available at https://www.eclipse.org/legal/epl-2.0/6# or the Apache License, Version 2.0 which accompanies this distribution and7# is available at https://www.apache.org/licenses/LICENSE-2.0.8#9# This Source Code may also be made available under the following10# Secondary Licenses when the conditions for such availability set11# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12# General Public License, version 2 with the GNU Classpath13# Exception [1] and GNU General Public License, version 2 with the14# OpenJDK Assembly Exception [2].15#16# [1] https://www.gnu.org/software/classpath/license.html17# [2] http://openjdk.java.net/legal/assembly-exception.html18#19# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20################################################################################2122include(CheckCXXCompilerFlag)23# This CMakeLists is included by the VM CMake lists, and works after composition24# has occurred.25#26# Relies on a few pieces of OMR, and a few pieces of the VM CMakeLists.27#28# Longer term, this will of course have to collapse into the VM builds.2930if(OMR_ARCH_X86)31# On Windows, the proper binary format is not auto detected.32if(OMR_OS_WINDOWS)33if(OMR_ENV_DATA64)34set(CMAKE_ASM_NASM_OBJECT_FORMAT win64)35else()36set(CMAKE_ASM_NASM_OBJECT_FORMAT win32)37endif()38endif()39enable_language(ASM_NASM)40# We have to manually append "/" to the paths as NASM versions older than v2.14 requires trailing / in the directory paths.41set(asm_inc_dirs42"-I${j9vm_SOURCE_DIR}/oti/"43"-I${j9vm_BINARY_DIR}/oti/"44"-I${CMAKE_CURRENT_SOURCE_DIR}/"45"-I${CMAKE_CURRENT_SOURCE_DIR}/x/runtime/"46"-I${CMAKE_CURRENT_SOURCE_DIR}/x/amd64/runtime/"47"-I${CMAKE_CURRENT_SOURCE_DIR}/x/i386/runtime/"48)49omr_append_flags(CMAKE_ASM_NASM_FLAGS ${asm_inc_dirs})50# For whatever reason cmake does not apply compile definitions when building nasm objects.51# The if guard is here in case they ever start doing so.52if(NOT CMAKE_ASM_NASM_COMPILE_OBJECT MATCHES "<DEFINES>")53# Tack on defines immediately following the compiler name.54string(REPLACE55"<CMAKE_ASM_NASM_COMPILER>"56"<CMAKE_ASM_NASM_COMPILER> <DEFINES>"57CMAKE_ASM_NASM_COMPILE_OBJECT58"${CMAKE_ASM_NASM_COMPILE_OBJECT}"59)60endif()61endif()6263# Using the linker option -static-libgcc results in an error on OSX. The option -static-libstdc++ is unused.64# Therefore these options have been excluded from OSX.65if((OMR_TOOLCONFIG STREQUAL "gnu") AND (NOT OMR_OS_OSX))66check_cxx_compiler_flag("-static-libstdc++" ALLOWS_STATIC_LIBCPP)67endif()6869# This target is created so that various subdirectories can add dependencies to it.70# The j9jit target will then depend on it, propagating the dependencies.71# This is required because at the time we include the subdirectories, the j9jit target72# does not yet exist (and as such can't have dependencies addded to it).73add_custom_target(j9jit_generate)7475# On Windows, exceptions are controlled via the preprocessor define _HAS_EXCEPTIONS.76# We need to enable it again, after OMR platform config removed it.77get_directory_property(compile_defs COMPILE_DEFINITIONS)78list(REMOVE_ITEM compile_defs "_HAS_EXCEPTIONS=0")79set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS ${compile_defs})8081omr_add_tracegen(env/j9jit.tdf)8283# this is a workaround because the JIT code includes the tracegen header as <env/ut_j9jit.h>84add_custom_command(85OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/env/ut_j9jit.h86DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ut_j9jit.h87COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/ut_j9jit.h" "${CMAKE_CURRENT_BINARY_DIR}/env/ut_j9jit.h"88VERBATIM89)9091add_custom_target(j9jit_tracegen DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/env/ut_j9jit.h)9293# J9VM_OPT_JITSERVER94if(J9VM_OPT_JITSERVER)95message(STATUS "JITServer is enabled")9697if(OPENSSL_BUNDLE_LIB_PATH) # --enable-openssl-bundling98set(OPENSSL_ROOT_DIR ${OPENSSL_BUNDLE_LIB_PATH})99set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,$ORIGIN/..")100elseif(OPENSSL_DIR) # --with-openssl=fetched only101set(OPENSSL_ROOT_DIR ${OPENSSL_DIR})102endif()103104find_package(OpenSSL REQUIRED)105include_directories(${OPENSSL_INCLUDE_DIR})106endif()107108# TODO We should get rid of this, but it's still required by the compiler_support module in OMR.109set(J9SRC ${j9vm_SOURCE_DIR})110111# include compiler support module from OMR112include(OmrCompilerSupport)113114# Override masm2gas with J9JIT version until we've115# resolved the divergence.116set(masm2gas_path build/scripts/masm2gas.pl )117get_filename_component(masm2gas_path ${masm2gas_path} ABSOLUTE)118set(MASM2GAS_PATH ${masm2gas_path} CACHE INTERNAL "MASM2GAS PATH")119120# The list of files that are added to the compiler in addition121# To the defaults provided by create_omr_compiler_library122set(J9JIT_FILES "" CACHE INTERNAL "The computed list of j9jit files")123124# Used inside added subdirectories to help125# fill in the object list126macro(j9jit_files)127set(J9JIT_FILES ${J9JIT_FILES} ${ARGN} CACHE INTERNAL "The computed list of j9jit files")128endmacro(j9jit_files)129130j9jit_files(${CMAKE_CURRENT_BINARY_DIR}/ut_j9jit.c)131132# Add our subdirectories.133add_subdirectory(codegen)134add_subdirectory(compile)135add_subdirectory(control)136add_subdirectory(env)137add_subdirectory(il)138add_subdirectory(ilgen)139add_subdirectory(infra)140add_subdirectory(optimizer)141add_subdirectory(ras)142add_subdirectory(runtime)143144if(J9VM_OPT_JITSERVER)145add_subdirectory(net)146endif()147148if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${TR_HOST_ARCH}")149add_subdirectory(${TR_HOST_ARCH})150endif()151152if(NOT TR_TARGET_ARCH STREQUAL TR_HOST_ARCH AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${TR_TARGET_ARCH}")153add_subdirectory(${TR_TARGET_ARCH})154endif()155156# Some files in OMR provide duplicate or extra functionality not needed157# in J9, so we need to remove them.158set(REMOVED_OMR_FILES159${omr_SOURCE_DIR}/compiler/codegen/CCData.cpp160${omr_SOURCE_DIR}/compiler/control/CompileMethod.cpp161${omr_SOURCE_DIR}/compiler/control/CompilationController.cpp162${omr_SOURCE_DIR}/compiler/env/FEBase.cpp163${omr_SOURCE_DIR}/compiler/optimizer/FEInliner.cpp164${omr_SOURCE_DIR}/compiler/env/JitConfig.cpp165${omr_SOURCE_DIR}/compiler/env/PersistentAllocator.cpp166${omr_SOURCE_DIR}/compiler/env/SystemSegmentProvider.cpp167${omr_SOURCE_DIR}/compiler/infra/OMRMonitor.cpp168${omr_SOURCE_DIR}/compiler/runtime/Trampoline.cpp169${omr_SOURCE_DIR}/compiler/runtime/Runtime.cpp170${omr_SOURCE_DIR}/compiler/ilgen/IlInjector.cpp171${omr_SOURCE_DIR}/compiler/ilgen/OMRBytecodeBuilder.cpp172${omr_SOURCE_DIR}/compiler/ilgen/OMRIlBuilder.cpp173${omr_SOURCE_DIR}/compiler/ilgen/OMRIlType.cpp174${omr_SOURCE_DIR}/compiler/ilgen/OMRIlValue.cpp175${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorder.cpp176${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorderBinaryBuffer.cpp177${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorderBinaryFile.cpp178${omr_SOURCE_DIR}/compiler/ilgen/OMRJitBuilderRecorderTextFile.cpp179${omr_SOURCE_DIR}/compiler/ilgen/OMRMethodBuilder.cpp180${omr_SOURCE_DIR}/compiler/ilgen/OMRThunkBuilder.cpp181${omr_SOURCE_DIR}/compiler/ilgen/OMRTypeDictionary.cpp182${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineOperandArray.cpp183${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineOperandStack.cpp184${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineRegister.cpp185${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineRegisterInStruct.cpp186${omr_SOURCE_DIR}/compiler/ilgen/OMRVirtualMachineState.cpp187)188189get_target_property(compiler_defines j9vm_compiler_defines INTERFACE_COMPILE_DEFINITIONS)190# Extra defines not provided by the create_omr_compiler_library call.191set(TARGET_DEFINES192J9_PROJECT_SPECIFIC193${compiler_defines}194)195196# When VM is built with CMake, we should just use the197# INTERFACE specification of target_link_libraries,198# though that would also involve teaching MASM2GAS and199# PASM2ASM about target includes.200#201# In the meantime, like the makefiles, this is using202# the includes from the SDK.203set(J9_INCLUDES204# From jitinclude.mk205${omr_SOURCE_DIR}/thread206${omr_SOURCE_DIR}/gc/include207# endjitinclude.mk208../ # Frustratingly there are some #include "frob/baz.hpp" references in the compiler which require this.209${j9vm_SOURCE_DIR}/codert_vm210${j9vm_SOURCE_DIR}/gc_include211${j9vm_SOURCE_DIR}/gc_glue_java212${j9vm_SOURCE_DIR}/jit_vm213${j9vm_SOURCE_DIR}/nls214${j9vm_SOURCE_DIR}/oti215${j9vm_SOURCE_DIR}/include216${j9vm_SOURCE_DIR}/util217${j9vm_BINARY_DIR}218${j9vm_BINARY_DIR}/oti219${omr_BINARY_DIR}220${CMAKE_CURRENT_BINARY_DIR}221)222223# Platform-specific lists of flags, derived directly from the makefiles.224set(J9_SHAREDFLAGS225${OMR_PLATFORM_COMPILE_OPTIONS}226)227set(J9_CFLAGS228${OMR_PLATFORM_C_COMPILE_OPTIONS}229)230set(J9_CXXFLAGS231${OMR_PLATFORM_CXX_COMPILE_OPTIONS}232)233234if(OMR_OS_LINUX OR OMR_OS_OSX)235list(APPEND J9_SHAREDFLAGS236-fno-strict-aliasing237-Wno-deprecated238-Wno-enum-compare239-Wno-write-strings240-fomit-frame-pointer241-fasynchronous-unwind-tables242-Wreturn-type243-pthread244)245246# Platform-specific CXX flags, also derived from the makefiles.247list(APPEND J9_CXXFLAGS248-fno-threadsafe-statics249-Wno-invalid-offsetof250)251if(NOT J9VM_OPT_JITSERVER)252list(APPEND J9_CXXFLAGS -fno-rtti)253endif()254255list(APPEND J9_CFLAGS -std=gnu89)256elseif(OMR_OS_WINDOWS)257list(APPEND J9_SHAREDFLAGS258-D_WIN32259-DWIN32260-DSUPPORTS_THREAD_LOCAL261-DWINDOWS262)263elseif(OMR_OS_AIX)264list(APPEND J9_SHAREDFLAGS265-DAIXPPC266-DRS6000267-D_XOPEN_SOURCE_EXTENDED=1268-D_ALL_SOURCE269-DSUPPORTS_THREAD_LOCAL270)271if(OMR_ENV_DATA64)272list(APPEND J9_SHAREDFLAGS -q64)273if(OMR_TOOLCONFIG STREQUAL "xlc")274# Modify the arch tuning value we inherit from OMR.275list(REMOVE_ITEM TR_COMPILE_OPTIONS "-qarch=pwr7")276list(APPEND TR_COMPILE_OPTIONS "-qarch=ppc64grsq")277278if(CMAKE_C_COMPILER_IS_XLCLANG)279# xlclang/xlclang++ options280list(APPEND SPP_FLAGS -qlanglvl=extc99)281set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lc++")282endif()283endif()284else()285list(APPEND J9_SHAREDFLAGS -q32)286endif()287elseif(OMR_OS_ZOS)288list(APPEND TARGET_DEFINES289J9VM_TIERED_CODE_CACHE290MAXMOVE291)292set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/lpp/hzc/lib")293else()294message(SEND_ERROR "unsupported platform")295endif()296297if(OMR_ARCH_S390)298list(APPEND TARGET_DEFINES COMPRESS_AOT_DATA)299endif()300301# Add optional user-specified compiler flags that only apply to the JIT.302list(APPEND J9_CFLAGS ${J9JIT_EXTRA_CFLAGS})303list(APPEND J9_CXXFLAGS ${J9JIT_EXTRA_CXXFLAGS})304305# Note: J9_CFLAGS and J9_CXXFLAGS are appended after J9_SHAREDFLAGS so that306# OMR_PLATFORM_C_COMPILE_OPTIONS and OMR_PLATFORM_CXX_COMPILE_OPTIONS307# end up after OMR_PLATFORM_COMPILE_OPTIONS, which matches the rest308# of the VM build (see cmake/modules/OmrPlatform.cmake in OMR).309# This allows the user to pass extra compiler options via310# OMR_PLATFORM_C_COMPILE_OPTIONS and OMR_PLATFORM_CXX_COMPILE_OPTIONS311# to override the defaults specified by OMR_PLATFORM_COMPILE_OPTIONS,312# e.g. in order to produce a debug build.313omr_stringify(J9_CFLAGS_STR ${J9_SHAREDFLAGS} ${J9_CFLAGS})314omr_stringify(J9_CXXFLAGS_STR ${J9_SHAREDFLAGS} ${J9_CXXFLAGS})315316# Note: This is explicitly overriding what's provided by317# the VM CMakeLists, as they pass -fno-exceptions318# right now, and the JIT needs exceptions.319set(CMAKE_CXX_FLAGS "${J9_CXXFLAGS_STR}")320set(CMAKE_C_FLAGS "${J9_CFLAGS_STR}")321322if(OMR_ARCH_X86 OR OMR_ARCH_S390)323set(OMR_WARNINGS_AS_ERRORS ON)324set(OMR_ENHANCED_WARNINGS OFF)325else()326set(OMR_WARNINGS_AS_ERRORS OFF)327set(OMR_ENHANCED_WARNINGS OFF)328endif()329330create_omr_compiler_library(NAME j9jit331SHARED332OUTPUT_NAME j9jit${J9VM_VERSION_SUFFIX}333OBJECTS ${J9_FILES} ${J9JIT_FILES} ${NOT_EXFRRED}334DEFINES J9_PROJECT_SPECIFIC ${TARGET_DEFINES}335INCLUDES ${J9_INCLUDES}336FILTER ${REMOVED_OMR_FILES}337)338339if(OMR_OS_ZOS)340# Workaround a compile problem on z/OS by appending "-O" (to override "-O3").341set_property(SOURCE "optimizer/VectorAPIExpansion.cpp" APPEND PROPERTY COMPILE_FLAGS "-O")342endif()343344add_dependencies(j9jit345omrgc_hookgen346j9jit_tracegen347j9jit_generate348)349350target_link_libraries(j9jit351PRIVATE352j9vm_interface353j9avl354j9codert_vm355j9hashtable356j9jit_vm357j9pool358j9stackmap359j9util360j9utilcore361j9hookable362j9thr363${CMAKE_DL_LIBS}364)365366# This is a bit hokey, but cmake can't track the fact that files are generated across directories.367# Note: while these are only needed on Z, setting the properties unconditionally has no ill-effect.368set_source_files_properties(369${CMAKE_CURRENT_BINARY_DIR}/z/runtime/Math.s370${CMAKE_CURRENT_BINARY_DIR}/z/runtime/PicBuilder.s371${CMAKE_CURRENT_BINARY_DIR}/z/runtime/Recompilation.s372${CMAKE_CURRENT_BINARY_DIR}/z/runtime/ValueProf.s373PROPERTIES374GENERATED TRUE375)376377if(OMR_OS_LINUX)378set_property(TARGET j9jit APPEND_STRING PROPERTY379LINK_FLAGS " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/build/scripts/j9jit.linux.exp")380target_link_libraries(j9jit PRIVATE m)381elseif(OMR_OS_WINDOWS)382target_sources(j9jit PRIVATE build/scripts/j9jit.def)383elseif(OMR_OS_AIX)384set_property(TARGET j9jit APPEND_STRING PROPERTY385LINK_FLAGS " -Wl,-bE:${CMAKE_CURRENT_SOURCE_DIR}/build/scripts/j9jit.aix.exp")386endif()387388if((OMR_TOOLCONFIG STREQUAL "gnu") AND ALLOWS_STATIC_LIBCPP)389# We assume that if the compiler allows -static-libstdc++390# it will also allow -static-libgcc.391set_property(TARGET j9jit APPEND_STRING PROPERTY392LINK_FLAGS " -static-libgcc -static-libstdc++")393endif()394395if(OMR_ARCH_S390)396if(OMR_OS_ZOS)397target_include_directories(j9jit BEFORE PRIVATE /usr/lpp/hzc/include)398target_link_libraries(j9jit PRIVATE zz)399else()400target_link_libraries(j9jit PRIVATE j9zlib)401endif()402endif()403404set_property(TARGET j9jit PROPERTY LINKER_LANGUAGE CXX)405406# Note: ddrgen can't handle the templates used in the JIT.407target_enable_ddr(j9jit NO_DEBUG_INFO)408409file(GLOB_RECURSE headers410${CMAKE_CURRENT_SOURCE_DIR}/runtime/*.h411${CMAKE_CURRENT_SOURCE_DIR}/runtime/*.hpp412)413414ddr_add_headers(j9jit415${headers}416)417418ddr_set_add_targets(omrddr j9jit)419420if(OMR_OS_ZOS)421# Make sure that -Wc,EXPORTALL is applied.422omr_process_exports(j9jit)423endif()424425install(426TARGETS j9jit427LIBRARY DESTINATION ${j9vm_SOURCE_DIR}428RUNTIME DESTINATION ${j9vm_SOURCE_DIR}429)430431432