@@ -30,53 +30,75 @@ cmake_minimum_required(VERSION 3.22)
30
30
project (com.oracle.graal.python.hpy.llvm )
31
31
32
32
function (require_var var )
33
- if (NOT ${var} )
33
+ if (NOT DEFINED ${var} )
34
34
message (FATAL_ERROR "${var} needs to be set" )
35
35
endif ()
36
36
endfunction ()
37
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
38
require_var (LLVM_MODE )
51
39
40
+ # default to CMake's source dir if not explicitly provided
41
+ if (NOT DEFINED SRC_DIR )
42
+ set (SRC_DIR "${CMAKE_SOURCE_DIR} " )
43
+ endif ()
44
+
52
45
set (TARGET_LIB "hpy-${LLVM_MODE} " )
53
- # set(LIB_OUTPUT_DIR "${PROJECT_OUTPUT_DIR}/lib")
54
46
55
47
# don't install into the system but into the MX project's output dir
56
48
set (CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR} )
57
49
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" )
50
+ require_var (GRAALVM_HPY_INCLUDE_DIR )
51
+ require_var (GRAALVM_PYTHON_INCLUDE_DIR )
52
+ require_var (TRUFFLE_H_INC )
65
53
66
- # only for Windows but to avoid a CMake warning
67
- check_var ( GRAALVM_LLVM_LIB_DIR )
54
+ set ( HPY_SRC " ${SRC_DIR} /src" )
55
+ set ( HPY_INC " ${SRC_DIR} /include" )
68
56
69
57
# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob
58
+ set (SRC_FILES ${HPY_SRC} /hpy.c
59
+ ${HPY_SRC} /hpynative.h
60
+ ${HPY_SRC} /hpytypes.h
61
+ )
62
+
63
+ set (HPY_HEADERS ${HPY_INC} /hpy/autogen_hpyslot.h
64
+ ${HPY_INC} /hpy/version.h
65
+ ${HPY_INC} /hpy/hpytype.h
66
+ ${HPY_INC} /hpy/universal/hpyfunc_trampolines.h
67
+ ${HPY_INC} /hpy/universal/autogen_trampolines.h
68
+ ${HPY_INC} /hpy/universal/misc_trampolines.h
69
+ ${HPY_INC} /hpy/universal/autogen_ctx.h
70
+ ${HPY_INC} /hpy/universal/autogen_hpyfunc_trampolines.h
71
+ ${HPY_INC} /hpy/hpydef.h
72
+ ${HPY_INC} /hpy/runtime/argparse.h
73
+ ${HPY_INC} /hpy/runtime/ctx_type.h
74
+ ${HPY_INC} /hpy/runtime/buildvalue.h
75
+ ${HPY_INC} /hpy/runtime/ctx_funcs.h
76
+ ${HPY_INC} /hpy/runtime/structseq.h
77
+ ${HPY_INC} /hpy/runtime/helpers.h
78
+ ${HPY_INC} /hpy/inline_helpers.h
79
+ ${HPY_INC} /hpy/cpython/hpyfunc_trampolines.h
80
+ ${HPY_INC} /hpy/cpython/misc.h
81
+ ${HPY_INC} /hpy/cpython/autogen_api_impl.h
82
+ ${HPY_INC} /hpy/cpython/autogen_hpyfunc_trampolines.h
83
+ ${HPY_INC} /hpy/macros.h
84
+ ${HPY_INC} /hpy/hpymodule.h
85
+ ${HPY_INC} /hpy/autogen_hpyfunc_declare.h
86
+ ${HPY_INC} /hpy/cpy_types.h
87
+ ${HPY_INC} /hpy/hpyfunc.h
88
+ ${HPY_INC} /hpy.h
89
+ )
90
+
70
91
add_library (${TARGET_LIB} SHARED )
71
92
72
- target_sources (${TARGET_LIB} PRIVATE ${SRC_FILES} )
93
+ target_sources (${TARGET_LIB} PRIVATE ${SRC_FILES} ${HPY_HEADERS} )
73
94
target_include_directories (${TARGET_LIB} PRIVATE
74
95
"${GRAALVM_HPY_INCLUDE_DIR} "
75
96
"${GRAALVM_PYTHON_INCLUDE_DIR} "
76
97
"${TRUFFLE_H_INC} "
77
98
)
78
99
79
100
if (WIN32 )
101
+ require_var (GRAALVM_LLVM_LIB_DIR )
80
102
target_link_directories (${TARGET_LIB} PRIVATE ${GRAALVM_LLVM_LIB_DIR} )
81
103
target_link_libraries (${TARGET_LIB} graalvm-llvm )
82
104
target_compile_options (${TARGET_LIB} PRIVATE /Z7 /O2 /WX )
0 commit comments