Skip to content

Commit

Permalink
Simplify win; other OS's will prob break
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrettSJohnson committed May 11, 2024
1 parent 9cad8ce commit 6361421
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ add_library(${TARGET_NAME} SHARED

if (MSVC)
target_compile_options(${TARGET_NAME} PRIVATE "/MP")
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ${SHARED_SUFFIX})
elseif (APPLE)
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ${SHARED_SUFFIX})
target_compile_options(${TARGET_NAME} PRIVATE ${ALL_COMP_ARGS})
else()
target_compile_options(${TARGET_NAME} PRIVATE ${ALL_COMP_ARGS})
endif()

set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ${SHARED_SUFFIX})

target_compile_features(${TARGET_NAME} PRIVATE cxx_std_17)

set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
Expand Down
30 changes: 8 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def build_cmake(self, ext):
build_temp = pathlib.Path(self.build_temp) / target_name
build_temp.mkdir(parents=True, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
if not sys.platform == "darwin":
if sys.platform == "linux": # TODO: Recheck linux
extdir.mkdir(parents=True, exist_ok=True)

def concat_paths(paths):
Expand All @@ -196,7 +196,6 @@ def concat_paths(paths):
lib_mode = "RUNTIME" if WIN else "LIBRARY"

shared_suffix = sysconfig.get_config_var('EXT_SUFFIX')
print(f"shared_suffix: {shared_suffix}")

cmake_args = [
f"-DTARGET_NAME={target_name}",
Expand All @@ -222,6 +221,13 @@ def concat_paths(paths):
self.spawn(['cmake', str(cwd)] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.'] + build_args)

if WIN:
# Move up from VS release folder
cmake_lib_loc = pathlib.Path(lib_output_dir, "Release", f"{target_name}{shared_suffix}")
if cmake_lib_loc.exists():
shutil.move(cmake_lib_loc, extdir)

# Troubleshooting: if fail on line above then delete all possible
# temporary CMake files including "CMakeCache.txt" in top level dir.
os.chdir(str(cwd))
Expand Down Expand Up @@ -273,29 +279,9 @@ def install_lib_to(self, sub_dir_list: list[str], lib_name: str) -> None:
dst = pathlib.Path(self.install_platlib, *sub_dir_list, f"{lib_name}{suffix}")
self.copy(str(lib_path), dst)

def delete_conflicting_cmake_dir(self, sub_dir_list: list[str], lib_name: str) -> None:
"""
Deletes the conflicting directory if it exists.
:sub_dir_list: The subdirectories where the library is located
relative to the build_lib and install_platlib directories.
:lib_name: The filename of the library (without the extension).
"""
cmake_folder = pathlib.Path(self.build_lib, *sub_dir_list, f"{lib_name}{sysconfig.get_config_var('EXT_SUFFIX')}")
print(cmake_folder)
print(f"DELETE {cmake_folder}")
print(cmake_folder.exists())
if cmake_folder.exists() and cmake_folder.is_dir():
shutil.rmtree(cmake_folder)
print(cmake_folder.exists())
# if lib_name == "_champ":
# exit(1)
def run(self):
self.delete_conflicting_cmake_dir(["pymol"], "_cmd")
self.delete_conflicting_cmake_dir(["chempy", "champ"], "_champ")
super().run()
self.install_pymol_path()
self.install_lib_to(["pymol"], "_cmd")
self.install_lib_to(["chempy", "champ"], "_champ")

if not self.no_launcher:
self.make_launch_script()
Expand Down

0 comments on commit 6361421

Please sign in to comment.