From a990260c749d9ade8646a4e44229b3fe551a0649 Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Mon, 1 Aug 2022 13:24:01 -0400 Subject: [PATCH] contrib(msc): fix Windows natpmp build The natpmp CMake build has no installation specified, so currently we use the root source directory which contains the header files as an include path in the daemon build. This may cause issues as case insensative header includes for the standard library <version> will incorrectly load natpmp's 'VERSION' file. This patch copies the project's headers to an include directory post-build, and adjusts the daemon's include path. Change-Id: I4b318fb0309c72b94f4ea4e757035780ee2a8a63 --- CMakeLists.txt | 4 ++-- compat/msvc/winmake.py | 31 +++++++++++++++++++++---------- contrib/src/natpmp/package.json | 20 +++++++++++++------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f46916a3b..3c4a4040b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,7 +149,7 @@ if(MSVC) "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/restinio/dev;" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/fmt/include;" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/http_parser;" - "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/natpmp" + "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/natpmp/include" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/msgpack-c/include;" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/opendht/include;" "${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/libarchive/libarchive;" @@ -257,7 +257,7 @@ if(MSVC) ${CMAKE_CURRENT_SOURCE_DIR}/contrib/msvc/lib/x64/secp256k1.lib ${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/yaml-cpp/msvc/Release/libyaml-cppmd.lib ${CMAKE_CURRENT_SOURCE_DIR}/contrib/msvc/lib/x64/libupnp.lib - ${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/natpmp/msvc/Release/natpmp.lib + ${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/natpmp/build/Release/natpmp.lib ${CMAKE_CURRENT_SOURCE_DIR}/contrib/msvc/lib/x64/archive_static.lib ${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/pjproject/pjsip/lib/pjsip-core-x86_64-x64-vc15-Release.lib ${CMAKE_CURRENT_SOURCE_DIR}/contrib/build/pjproject/pjsip/lib/pjsip-simple-x86_64-x64-vc15-Release.lib diff --git a/compat/msvc/winmake.py b/compat/msvc/winmake.py index 06b166b21c..48b9839dae 100644 --- a/compat/msvc/winmake.py +++ b/compat/msvc/winmake.py @@ -76,6 +76,7 @@ vs_where_path = os.path.join( host_is_64bit = (False, True)[platform.machine().endswith('64')] python_is_64bit = (False, True)[8 * struct.calcsize("P") == 64] + def getMd5ForDirectory(path): hasher = hashlib.md5() for root, _, files in os.walk(path, topdown=True): @@ -86,6 +87,7 @@ def getMd5ForDirectory(path): hasher.update(buf) return hasher.hexdigest() + def shellquote(s, windows=False): if not windows: return "'" + s.replace("'", "'\''") + "'" @@ -493,20 +495,20 @@ def build(pkg_name, pkg_dir, project_paths, custom_scripts, with_env, sdk, # pre_build custom step (CMake...) pre_build_scripts = custom_scripts.get("pre_build", []) if pre_build_scripts: - log.debug('Pre_build phase') - for script in pre_build_scripts: - result = getSHrunner().exec_batch(script) - success &= not result[0] - build_operations += 1 + log.debug('Pre-build phase') + for script in pre_build_scripts: + result = getSHrunner().exec_batch(script) + success &= not result[0] + build_operations += 1 # build custom step (nmake...) build_scripts = custom_scripts.get("build", []) if build_scripts: log.debug('Custom Build phase') - for script in build_scripts: - result = getSHrunner().exec_batch(script) - success &= not result[0] - build_operations += 1 + for script in build_scripts: + result = getSHrunner().exec_batch(script) + success &= not result[0] + build_operations += 1 # vcxproj files if project_paths: @@ -528,10 +530,19 @@ def build(pkg_name, pkg_dir, project_paths, custom_scripts, with_env, sdk, log.error("Error building with CMake") exit(1) + post_build_scripts = custom_scripts.get("post_build", []) + if post_build_scripts: + log.debug('Post-Build phase') + for script in post_build_scripts: + result = getSHrunner().exec_batch(script) + success &= not result[0] + build_operations += 1 + os.chdir(tmp_dir) # should cover header only, no cmake, etc - ops = len(build_scripts) + len(project_paths) + len(pre_build_scripts) + ops = len(build_scripts) + len(project_paths) + \ + len(pre_build_scripts) + len(post_build_scripts) return success and build_operations == ops diff --git a/contrib/src/natpmp/package.json b/contrib/src/natpmp/package.json index 1d5b8f255e..bae1070854 100644 --- a/contrib/src/natpmp/package.json +++ b/contrib/src/natpmp/package.json @@ -4,14 +4,20 @@ "url": "http://github.com/miniupnp/libnatpmp/archive/__VERSION__.tar.gz", "deps": [], "patches": [], - "win_patches": ["natpmp-win32-ssize_t.patch"], - "project_paths": ["msvc/natpmp.vcxproj"], - "with_env" : "", + "win_patches": [ + "natpmp-win32-ssize_t.patch" + ], + "project_paths": [], + "with_env": "", + "use_cmake": true, + "defines": [ + "CMAKE_INSTALL_PREFIX=./install" + ], "custom_scripts": { - "pre_build": [ - "rmdir /s /q msvc & mkdir msvc & cd msvc & cmake .. -G %CMAKE_GENERATOR%" - ], + "pre_build": [], "build": [], - "post_build": [] + "post_build": [ + "xcopy /f /y natpmp*.h include/" + ] } } \ No newline at end of file -- GitLab