From b477da6d93d31357392100a01eb859d0c5a0ec28 Mon Sep 17 00:00:00 2001 From: Ririko Nakamura <monica.t.lu@outlook.com> Date: Wed, 20 Jul 2022 15:41:07 +0800 Subject: [PATCH] Add support to Visual Studio generators in setup.py (#201) * Add support to Visual Studio generators in setup.py * Modifies generator identification pattern --- setup.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a0dc4dc..fa67b96 100644 --- a/setup.py +++ b/setup.py @@ -164,9 +164,22 @@ class BuildCMakeExt(build_ext, object): os.makedirs(self.build_temp) self.spawn(['cmake', '-H'+extension.sourcedir, '-B'+self.build_temp]+ cmake_args) + # Check which generator was used and use the correct command line switches. + generator = '' + cmake_cache_file = os.path.join(self.build_temp, 'CMakeCache.txt') + with open(cmake_cache_file, 'r') as cmake_cache: + for line in cmake_cache.readlines(): + if line.find('CMAKE_GENERATOR:') != -1: + generator = line[line.find('=') + 1:].strip() + self.announce("Building binaries", level=3) - self.spawn(["cmake", "--build", self.build_temp, - "--config", "Release", '--', '-j8']) + + if generator.find('Visual Studio') != -1: + self.spawn(["cmake", "--build", self.build_temp, + "--config", "Release", "--", "-m"]) + else: + self.spawn(["cmake", "--build", self.build_temp, + "--config", "Release", "--", "-j8"]) # Build finished, now copy the files into the copy directory # The copy directory is the parent directory of the extension (.pyd) -- GitLab