@@ -24,68 +24,9 @@ FetchContent_Declare(
2424)
2525FetchContent_MakeAvailable(pybind11)
2626
27- # Try to find the Python executable.
28- #
29- # If it's given as part of the Cmake arguments given by "scikit build", then use that.
30- # Otherwise, fall back to using plain old "python".
31- # If *THAT* doesn't work, give up.
32- if (DEFINED PYTHON_EXECUTABLE)
33- set (SVS_PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE} " )
34- else ()
35- set (SVS_PYTHON_EXECUTABLE "python" )
36- endif ()
37-
38- # The micro architectures to compile for.
39- if (NOT DEFINED SVS_MICROARCHS)
40- set (SVS_MICROARCHS native)
41- endif ()
42-
4327# Include the SVS library directly.
4428add_subdirectory ("../.." "${CMAKE_CURRENT_BINARY_DIR} /svs" )
4529
46- # Run the python script to get optimization flags for the desired back-ends.
47- #
48- # FLAGS_SCRIPT - Path to the Python script that will take the compiler, compiler version,
49- # and list of desired microarchitectures and generate optimization flags for each
50- # microarchitecture.
51- #
52- # FLAGS_TEXT_FILE - List of optimization flags for each architecture.
53- # Expected format:
54- # -march=arch1,-mtune=arch1
55- # -march=arch2,-mtune=arch2
56- # ...
57- # -march=archN,-mtune=archN
58- #
59- # The number of lines should be equal to the number of microarchitectures.
60- # NOTE: The entries within each line are separated by a comma on purpose to allow CMake
61- # to read the whole file as a List and then use string replacement on the commas to turn
62- # each line into a list in its own right.
63- #
64- # TEMP_JSON - JSON Manifest file describing the generated binaries. This is meant to be
65- # included in the Python package to allow the Python code to reason about the packaged
66- # libraries and select the correct one for loading.
67- #
68- set (FLAGS_SCRIPT "${CMAKE_CURRENT_LIST_DIR} /microarch.py" )
69- set (FLAGS_TEXT_FILE "${CMAKE_CURRENT_BINARY_DIR} /optimization_flags.txt" )
70- set (FLAGS_MANIFEST_JSON "${CMAKE_CURRENT_BINARY_DIR} /flags_manifest.json" )
71-
72- execute_process (
73- COMMAND
74- ${SVS_PYTHON_EXECUTABLE}
75- ${FLAGS_SCRIPT}
76- ${FLAGS_TEXT_FILE}
77- ${FLAGS_MANIFEST_JSON}
78- --compiler ${CMAKE_CXX_COMPILER_ID}
79- --compiler-version ${CMAKE_CXX_COMPILER_VERSION}
80- --microarchitectures ${SVS_MICROARCHS}
81- COMMAND_ERROR_IS_FATAL ANY
82- )
83-
84- file (STRINGS "${FLAGS_TEXT_FILE} " OPTIMIZATION_FLAGS)
85- message ("Flags: ${OPTIMIZATION_FLAGS} " )
86- list (LENGTH OPTIMIZATION_FLAGS OPT_FLAGS_LENGTH)
87- message ("Length of flags: ${OPT_FLAGS_LENGTH} " )
88-
8930# C++ files makind up the python bindings.
9031set (CPP_FILES
9132 src/allocator.cpp
@@ -98,50 +39,26 @@ set(CPP_FILES
9839 src/svs_mkl.cpp
9940)
10041
101- # Generate a shared library for each target microarchitecture.
102- foreach (MICRO OPT_FLAGS IN ZIP_LISTS SVS_MICROARCHS OPTIMIZATION_FLAGS)
103- set (LIB_NAME "_svs_${MICRO} " )
104-
105- pybind11_add_module(${LIB_NAME} MODULE ${CPP_FILES} )
106- target_link_libraries (${LIB_NAME} PUBLIC svs::svs)
107- # Dependency "fmt::fmt" obtained from "svs"
108- target_link_libraries (${LIB_NAME} PRIVATE svs::compile_options fmt::fmt)
109-
110- string (REPLACE "," ";" OPT_FLAGS ${OPT_FLAGS} )
111- message ("OPT Flags: ${OPT_FLAGS} " )
112- target_compile_options (${LIB_NAME} PRIVATE ${OPT_FLAGS} )
113-
114- # Header files.
115- target_include_directories (
42+ set (LIB_NAME "_svs" )
43+ pybind11_add_module(${LIB_NAME} MODULE ${CPP_FILES} )
44+ target_link_libraries (${LIB_NAME} PRIVATE pybind11::module)
45+ target_link_libraries (${LIB_NAME} PUBLIC svs::svs)
46+ # Dependency "fmt::fmt" obtained from "svs"
47+ target_link_libraries (${LIB_NAME} PRIVATE svs::compile_options fmt::fmt svs_x86_options_base)
48+ target_include_directories (
49+ ${LIB_NAME}
50+ PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /include >
51+ )
52+ if (DEFINED SKBUILD)
53+ install (TARGETS ${LIB_NAME} DESTINATION .)
54+ set_target_properties (
11655 ${LIB_NAME}
117- PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /include >
56+ PROPERTIES
57+ INSTALL_RPATH "$ORIGIN/${CMAKE_INSTALL_LIBDIR} "
11858 )
119-
120- # Comunicate to the C++ library the desired name of the library
121- target_compile_options (${LIB_NAME} PRIVATE "-DSVS_MODULE_NAME=${LIB_NAME} " )
122-
123- # If scikit build is running the compilation process,
124- if (DEFINED SKBUILD)
125- install (TARGETS ${LIB_NAME} DESTINATION .)
126-
127- # The extension module may need to load build or included libraries when loaded.
128-
129- # Placing build depedencies in the package and using relative RPATHs that
130- # don't point outside of the package means that the built package is
131- # relocatable. This allows for safe binary redistribution.
132- set_target_properties (
133- ${LIB_NAME}
134- PROPERTIES
135- INSTALL_RPATH "$ORIGIN/${CMAKE_INSTALL_LIBDIR} "
136- )
137- endif ()
138- endforeach ()
59+ endif ()
13960
14061if (DEFINED SKBUILD)
141- # Install the manifest JSON file.
142- # This is kind of a hack to avoid the needing to explicitly move JSON file into the
143- # source folder of the python library.
144- install (FILES ${FLAGS_MANIFEST_JSON} DESTINATION .)
14562
14663 # Install header files.
14764 install (
0 commit comments