|
| 1 | +# |
| 2 | +# Copyright (c) 2023, Oracle and/or its affiliates. |
| 3 | +# |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without modification, are |
| 7 | +# permitted provided that the following conditions are met: |
| 8 | +# |
| 9 | +# 1. Redistributions of source code must retain the above copyright notice, this list of |
| 10 | +# conditions and the following disclaimer. |
| 11 | +# |
| 12 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this list of |
| 13 | +# conditions and the following disclaimer in the documentation and/or other materials provided |
| 14 | +# with the distribution. |
| 15 | +# 3. Neither the name of the copyright holder nor the names of its contributors may be used to |
| 16 | +# endorse or promote products derived from this software without specific prior written |
| 17 | +# permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
| 20 | +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 22 | +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 23 | +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 | +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 27 | +# OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +# |
| 29 | +cmake_minimum_required(VERSION 3.22) |
| 30 | +project(com.oracle.graal.python.hpy.llvm) |
| 31 | + |
| 32 | +function(require_var var) |
| 33 | + if (NOT ${var}) |
| 34 | + message(FATAL_ERROR "${var} needs to be set") |
| 35 | + endif() |
| 36 | +endfunction() |
| 37 | + |
| 38 | +function(check_var var) |
| 39 | + set(${var} PARENT_SCOPE) |
| 40 | + require_var(${var}) |
| 41 | +endfunction() |
| 42 | + |
| 43 | +# set variable from environement variable if the latter exists |
| 44 | +function(setFromEnv varname envname) |
| 45 | + if(DEFINED ENV{${envname}}) |
| 46 | + set(${varname} $ENV{${envname}} PARENT_SCOPE) |
| 47 | + endif() |
| 48 | +endfunction() |
| 49 | + |
| 50 | +require_var(LLVM_MODE) |
| 51 | + |
| 52 | +set(TARGET_LIB "hpy-${LLVM_MODE}") |
| 53 | +# set(LIB_OUTPUT_DIR "${PROJECT_OUTPUT_DIR}/lib") |
| 54 | + |
| 55 | +# don't install into the system but into the MX project's output dir |
| 56 | +set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) |
| 57 | + |
| 58 | +check_var(GRAALVM_HPY_INCLUDE_DIR) |
| 59 | +check_var(GRAALVM_PYTHON_INCLUDE_DIR) |
| 60 | +check_var(TRUFFLE_H_INC) |
| 61 | + |
| 62 | +file(GLOB_RECURSE SRC_FILES |
| 63 | + LIST_DIRECTORIES TRUE |
| 64 | + "${CMAKE_CURRENT_LIST_DIR}/src/*.c") |
| 65 | + |
| 66 | +# only for Windows but to avoid a CMake warning |
| 67 | +check_var(GRAALVM_LLVM_LIB_DIR) |
| 68 | + |
| 69 | +# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob |
| 70 | +add_library(${TARGET_LIB} SHARED) |
| 71 | + |
| 72 | +target_sources(${TARGET_LIB} PRIVATE ${SRC_FILES}) |
| 73 | +target_include_directories(${TARGET_LIB} PRIVATE |
| 74 | + "${GRAALVM_HPY_INCLUDE_DIR}" |
| 75 | + "${GRAALVM_PYTHON_INCLUDE_DIR}" |
| 76 | + "${TRUFFLE_H_INC}" |
| 77 | +) |
| 78 | + |
| 79 | +if(WIN32) |
| 80 | + target_link_directories(${TARGET_LIB} PRIVATE ${GRAALVM_LLVM_LIB_DIR}) |
| 81 | + target_link_libraries(${TARGET_LIB} graalvm-llvm) |
| 82 | + target_compile_options(${TARGET_LIB} PRIVATE /Z7 /O2 /WX) |
| 83 | +else() |
| 84 | + target_compile_options(${TARGET_LIB} PRIVATE |
| 85 | + -DHPY_UNIVERSAL_ABI |
| 86 | + -DNDEBUG |
| 87 | + -DGRAALVM_PYTHON_LLVM |
| 88 | + -Werror |
| 89 | + -Wno-int-to-pointer-cast |
| 90 | + -Wno-int-conversion |
| 91 | + -Wno-void-pointer-to-int-cast |
| 92 | + -Wno-incompatible-pointer-types-discards-qualifiers |
| 93 | + -Wno-pointer-type-mismatch |
| 94 | + -Wno-braced-scalar-init |
| 95 | + -Wno-deprecated-declarations |
| 96 | + ) |
| 97 | +endif() |
| 98 | + |
| 99 | +if(APPLE) |
| 100 | + target_link_options(${TARGET_LIB} PRIVATE -undefined dynamic_lookup) |
| 101 | +endif() |
| 102 | + |
| 103 | +install(TARGETS ${TARGET_LIB} DESTINATION bin) |
0 commit comments