@@ -9,46 +9,73 @@ endif()
99
1010if (CMAKE_BUILD_TYPE  STREQUAL  "Debug" )
1111	set (Python3_FIND_ABI "ON"  "ANY"  "ANY" )
12- 	find_package (Python3 COMPONENTS Development)
12+ 	find_package (Python3 COMPONENTS Interpreter  Development)
1313
1414	# Fallback to release if not found 
1515	if (NOT  Python3_Development_FOUND)
1616		set (Python3_FIND_ABI)
17- 		find_package (Python3 COMPONENTS Development REQUIRED)
17+ 		find_package (Python3 COMPONENTS Interpreter  Development REQUIRED)
1818	endif ()
1919else ()
20- 	find_package (Python3 COMPONENTS Development REQUIRED)
20+ 	find_package (Python3 COMPONENTS Interpreter Development REQUIRED)
21+ endif ()
22+ 
23+ # Select the proper library 
24+ if (NOT  Python3_LIBRARY AND  Python3_LIBRARIES)
25+ 	# Go through the list and handle keyword-separated structure 
26+ 	set (index 0)
27+ 	list (LENGTH  Python3_LIBRARIES lib_len)
28+ 	while (index LESS  lib_len)
29+ 		list (GET  Python3_LIBRARIES ${index}  item)
30+ 
31+ 		# Check if it's a keyword (debug/optimized) 
32+ 		if (item STREQUAL  "debug"  OR  item STREQUAL  "optimized"  OR  item STREQUAL  "general" )
33+ 			set (keyword ${item} )
34+ 			math (EXPR  next "${index}  + 1" )
35+ 			list (GET  Python3_LIBRARIES ${next}  lib_path)
36+ 
37+ 			# Match the right keyword 
38+ 			if ((CMAKE_BUILD_TYPE  STREQUAL  "Debug"  AND  keyword STREQUAL  "debug" ) OR 
39+ 			   (NOT  CMAKE_BUILD_TYPE  STREQUAL  "Debug"  AND  keyword STREQUAL  "optimized" ) OR 
40+ 			   (keyword STREQUAL  "general" ))  # general applies to all configs 
41+ 				set (Python3_LIBRARY ${lib_path} )
42+ 			endif ()
43+ 
44+ 			math (EXPR  index "${index}  + 2" )  # Skip keyword and path 
45+ 		else ()
46+ 			# Plain list without keywords (single-config or fallback) 
47+ 			set (Python3_LIBRARY ${item} )
48+ 			math (EXPR  index "${index}  + 1" )
49+ 		endif ()
50+ 	endwhile ()
2151endif ()
2252
2353# Copy Python DLL into project output directory 
2454# TODO: https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies 
2555# TODO: https://gist.github.com/micahsnyder/5d98ac8548b429309ec5a35bca9366da 
2656include (Portability)
2757
28- if (PROJECT_OS_FAMILY STREQUAL  win32  AND  Python3_LIBRARIES  AND  Python3_ROOT_DIR  AND   NOT   CMAKE_BUILD_TYPE   STREQUAL   "Debug" )
29- 	foreach  ( library ${Python3_LIBRARIES} ) 
30- 		if  ( ${library}   MATCHES  "[^_d][ .]lib$" )
31- 			 # Get the library path with dll suffix  
32- 			string  ( REGEX  REPLACE  "[.]lib$"   ".dll"  LIB_PATH  ${library} )
33- 			 # Get the library name  
34- 			get_filename_component  (LIB_NAME  " ${LIB_PATH} "   NAME )
35- 			 # Find the library in the Python3 root path 
36- 			find_file  (Python3_LIBRARY_NAME_PATH  ${LIB_NAME} 
37- 				 PATHS   ${Python3_ROOT_DIR} 
38- 				NO_DEFAULT_PATH 
39- 			) 
40- 			if  (Python3_LIBRARY_NAME_PATH) 
41- 				break  ( )
42- 			endif  () 
43- 		endif  ( )
44- 	endforeach  ( )
58+ if (PROJECT_OS_FAMILY STREQUAL  win32  AND  Python3_LIBRARY )
59+ 	# Get the  library path with dll suffix 
60+ 	string  ( REGEX  REPLACE  "[.]lib$"    ".dll"  LIB_PATH  " ${Python3_LIBRARY} "
61+ 	# Get the library name  
62+ 	get_filename_component  (LIB_NAME  " ${LIB_PATH} "   NAME )
63+ 	# Get the python root folder  
64+ 	if  ( NOT  Python3_ROOT_DIR )
65+ 		get_filename_component  (Python3_ROOT_DIR  " ${Python3_EXECUTABLE} "   DIRECTORY ) 
66+ 	endif  () 
67+ 	# Find the library in the Python3 root path 
68+ 	find_file  (Python3_LIBRARY_NAME_PATH  " ${LIB_NAME} " 
69+ 		PATHS   " ${Python3_ROOT_DIR} " 
70+ 		NO_DEFAULT_PATH 
71+ 	)
72+ 	# Copy the DLL to the output directory 
73+ 	execute_process  ( COMMAND   ${CMAKE_COMMAND}  -E make_directory  " ${PROJECT_OUTPUT_DIR} " 
74+ 	file  (COPY  " ${Python3_LIBRARY_NAME_PATH} "   DESTINATION   " ${PROJECT_OUTPUT_DIR} " 
4575endif ()
4676
47- if (Python3_LIBRARY_NAME_PATH)
48- 	execute_process (COMMAND  ${CMAKE_COMMAND}  -E make_directory ${PROJECT_OUTPUT_DIR} )
49- 	file (COPY "${Python3_LIBRARY_NAME_PATH} "  DESTINATION  ${PROJECT_OUTPUT_DIR} )
50- else ()
51- 	set (Python3_LIBRARY_NAME_PATH "${Python3_LIBRARIES} " )
77+ if (NOT  Python3_LIBRARY_NAME_PATH)
78+ 	set (Python3_LIBRARY_NAME_PATH "${Python3_LIBRARY} " )
5279endif ()
5380
5481# 
@@ -91,6 +118,7 @@ set(headers
91118	${include_path} /py_loader_port.h
92119	${include_path} /py_loader_threading.h
93120	${include_path} /py_loader_dict.h
121+ 	${include_path} /py_loader_symbol_fallback.h
94122)
95123
96124set (sources 
@@ -174,7 +202,7 @@ target_link_libraries(${target}
174202	${META_PROJECT_NAME} ::metacall # MetaCall library 
175203
176204	# Delay load for MSVC 
177- 	$<$<CXX_COMPILER_ID:MSVC >:${Python3_LIBRARIES } > # Python library 
205+ 	$<$<CXX_COMPILER_ID:MSVC >:${Python3_LIBRARY } > # Python library 
178206	$<$<CXX_COMPILER_ID:MSVC >:delayimp>
179207
180208	PUBLIC 
0 commit comments