forked from gemini3d/cmake-python-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
84 lines (64 loc) · 2.17 KB
/
CMakeLists.txt
File metadata and controls
84 lines (64 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
cmake_minimum_required(VERSION 3.19...3.25)
# -- must override compiler to be gcc on Linux and clang on Macos.
# otherwise, Autotools is too shaky.
# Intel compiler icx/icpx works but is more than 100x slower to build.
if(APPLE)
set(CC clang)
elseif(UNIX)
set(CC gcc)
elseif(WIN32)
set(CC cl)
else()
message(FATAL_ERROR "Unsupported platform ${CMAKE_SYSTEM_NAME}")
endif()
find_program(CMAKE_C_COMPILER NAMES ${CC} REQUIRED)
project(CPython
LANGUAGES C
)
include(ExternalProject)
include(cmake/options.cmake)
include(cmake/ExtProjCMake.cmake)
include(cmake/ExtProjAutotools.cmake)
# -- main program
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/libraries.json json_meta)
find_package(Autotools)
# -- includes needed for Python Autotools, especially Python >= 3.11 due to https://github.com/python/cpython/pull/29483/files
string(APPEND CMAKE_C_FLAGS " -I${CMAKE_INSTALL_PREFIX}/include")
# -- libraries needed for Python Autotools
set(LDFLAGS $ENV{LDFLAGS})
foreach(l lib lib64)
string(APPEND LDFLAGS " ${CMAKE_LIBRARY_PATH_FLAG}${CMAKE_INSTALL_PREFIX}/${l}")
string(APPEND LDFLAGS " -Wl,-rpath,${CMAKE_INSTALL_PREFIX}/${l}")
endforeach()
if(APPLE)
find_path(macinc
NAMES stdio.h
PATHS /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
)
if(macinc)
string(APPEND CMAKE_C_FLAGS " -I${macinc}")
endif()
# Clang: hinting macinc breaks readline etc. with conflicting headers
# GCC: needs the macinc hints
find_library(macsys
NAMES System
NO_DEFAULT_PATH
PATHS /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
)
if(macsys)
get_filename_component(lmac ${macsys} DIRECTORY)
string(APPEND LDFLAGS " ${CMAKE_LIBRARY_PATH_FLAG}${lmac}")
string(APPEND LDFLAGS " -Wl,-rpath,${lmac}")
endif()
endif()
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${LDFLAGS}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${LDFLAGS}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " ${LDFLAGS}")
include(python.cmake)
if(DEFINED ENV{CONDA_PREFIX})
message(STATUS "Conda Python detected as active. You may wish to
conda deactivate
to avoid conflicts with the Python build system."
)
endif()
message(STATUS "CMake ${CMAKE_VERSION} Python ${python_tag}")