Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcpkg support #69

Open
Hary309 opened this issue Apr 7, 2024 · 7 comments
Open

Vcpkg support #69

Hary309 opened this issue Apr 7, 2024 · 7 comments

Comments

@Hary309
Copy link

Hary309 commented Apr 7, 2024

It would be nice to see this library in the vcpkg registry, I hate having deps as a target inside Visual Studio.

Anyway, this is a great library, thanks for your work!

@angelfor3v3r
Copy link
Collaborator

It would be nice to see this library in the vcpkg registry, I hate having deps as a target inside Visual Studio.

Anyway, this is a great library, thanks for your work!

I'm not sure if any of the current maintainers use Vcpkg but I'm sure someone could create a portfile for the library and we wouldn't be against it. My question is though, what's wrong with using the Amalgamated builds? They won't add a target and just live on your include path/in your primary project.

@Hary309
Copy link
Author

Hary309 commented Apr 8, 2024

what's wrong with using the Amalgamated builds? They won't add a target and just live on your include path/in your primary project.

It is even worse to keep the deps sources as part of your primary project 😛 So I would rather move it to a separate target.

@angelfor3v3r
Copy link
Collaborator

what's wrong with using the Amalgamated builds? They won't add a target and just live on your include path/in your primary project.

It is even worse to keep the deps sources as part of your primary project 😛 So I would rather move it to a separate target.

I don't think it's that bad, they're very small files and it keeps it simple, but I understand your concerns and I don't see anything wrong with getting a portfile made for the library. If you have experience with Vcpkg perhaps you could get a simple portfile working to get the ball rolling? 😄

@Hary309
Copy link
Author

Hary309 commented Apr 8, 2024

If you have experience with Vcpkg perhaps you could get a simple portfile working to get the ball rolling? 😄

I don't have any experience with portfiles but this is a good opportunity to learn it finally, I will see what I can do.

@llm96
Copy link

llm96 commented Feb 10, 2025

I've been using a personal overlay port in my projects for a while. It's far from perfect and I don't remember why I wrote a separate CMakeLists.txt for it - I think the upstream one didn't have the install stuff it was expecting? It's been a while.

sample.zip

I'm still not sure how the install stuff works or if I even used it correctly there, but feel free to use this as a reference if it helps.

@Hary309
Copy link
Author

Hary309 commented Feb 10, 2025

I eventually decided to use CPM (it is just simpler for my project) so I abandoned this idea 😛

@llm96
Copy link

llm96 commented Feb 12, 2025

That's alright, I wouldn't mind trying myself. It'd be cool to have packages in MSYS2 & AUR at some point too.

I played around a bit more with the install stuff, now adding it to cmkr.toml instead.

diff --git a/cmake.toml b/cmake.toml
index df17b9f..a3e6c58 100644
--- a/cmake.toml
+++ b/cmake.toml
@@ -24,12 +24,14 @@ condition = "build-test"
 git = "https://github.com/boost-ext/ut.git"
 tag = "v2.0.1"
 shallow = true
+EXCLUDE_FROM_ALL = true
 
 [fetch-content.xbyak]
 condition = "build-test"
 git = "https://github.com/herumi/xbyak.git"
 tag = "v6.69"
 shallow = true
+EXCLUDE_FROM_ALL = true
 
 [fetch-content.Zydis]
 condition = "fetch-zydis"
@@ -41,6 +43,7 @@ option(ZYDIS_BUILD_EXAMPLES "" OFF)
 option(ZYDIS_BUILD_TOOLS "" OFF)
 option(ZYDIS_BUILD_DOXYGEN "" OFF)
 """
+EXCLUDE_FROM_ALL = true
 
 [find-package.Doxygen]
 condition = "build-docs"
@@ -53,7 +56,10 @@ required = true
 [target.safetyhook]
 type = "static"
 sources = ["src/*.cpp"]
-include-directories = ["include/"]
+include-directories = [
+    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>",
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
+]
 compile-features = ["cxx_std_23"]
 alias = "safetyhook::safetyhook"
 link-libraries = ["Zydis"]
@@ -64,6 +70,29 @@ cmake-after = """
 if(SAFETYHOOK_USE_CXXMODULES)
     target_compile_definitions(safetyhook INTERFACE SAFETYHOOK_USE_CXXMODULES)
 endif()
+
+include(GNUInstallDirs)
+
+install(
+    TARGETS      safetyhook
+    EXPORT       safetyhook-export
+    LIBRARY      DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    ARCHIVE      DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    RUNTIME      DESTINATION ${CMAKE_INSTALL_BINDIR}
+    INCLUDES     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
+
+install(
+    DIRECTORY    ${CMAKE_CURRENT_SOURCE_DIR}/include/
+    DESTINATION  ${CMAKE_INSTALL_INCLUDEDIR}
+)
+
+install(
+    EXPORT       safetyhook-export
+    FILE         safetyhook-config.cmake
+    NAMESPACE    safetyhook::
+    DESTINATION  ${CMAKE_INSTALL_LIBDIR}/cmake/safetyhook
+)
 """
 
 [target.docs]
-- Install configuration: "Debug"
-- Installing: lib/libsafetyhook.a
-- Installing: include
-- Installing: include/safetyhook
-- Installing: include/safetyhook/allocator.hpp
-- Installing: include/safetyhook/common.hpp
-- Installing: include/safetyhook/context.hpp
-- Installing: include/safetyhook/easy.hpp
-- Installing: include/safetyhook/inline_hook.hpp
-- Installing: include/safetyhook/mid_hook.hpp
-- Installing: include/safetyhook/os.hpp
-- Installing: include/safetyhook/utility.hpp
-- Installing: include/safetyhook/vmt_hook.hpp
-- Installing: include/safetyhook.hpp
-- Installing: lib/cmake/safetyhook/safetyhook-config.cmake
-- Installing: lib/cmake/safetyhook/safetyhook-config-debug.cmake

Works as expected, but I'm not certain the install stuff is set up correctly. Still mostly a product of trial and error.

Should I make a pull request for this? It'd make packaging for vcpkg and others a bit easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants