diff --git a/CMakeLists.txt b/CMakeLists.txt
index 60b4da8..81af135 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,12 @@
-cmake_minimum_required(VERSION 3.22.1)
+cmake_minimum_required(VERSION 3.27)
 
-include(ExternalProject)
 
 project(libmem
 	LANGUAGES
 	C
 	CXX
 	ASM
+	VERSION 5.1.0
 )
 
 message(STATUS
@@ -49,6 +49,7 @@ message(STATUS
 message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
 message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
 
+if(0)
 # External dependencies
 set(EXTERNAL_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/external")
 set(CAPSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/capstone")
@@ -66,6 +67,19 @@ set_target_properties(capstone PROPERTIES IMPORTED_LOCATION ${CAPSTONE_IMPORT_DI
 add_library(keystone STATIC IMPORTED)
 set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX})
 # End of external dependencies
+endif()
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(CAPSTONE REQUIRED capstone)
+pkg_check_modules(KEYSTONE REQUIRED keystone)
+find_package(LLVM REQUIRED CONFIG)
+set(CAPSTONE_INC "${CAPSTONE_INCLUDE_DIR}")
+set(KEYSTONE_INC "${KEYSTONE_INCLUDE_DIR}")
+add_library(llvm INTERFACE)
+target_include_directories(llvm INTERFACE ${LLVM_INCLUDE_DIRS})
+separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+target_compile_definitions(llvm INTERFACE ${LLVM_DEFINITIONS_LIST})
+llvm_map_components_to_libnames(LLVM_LIBS demangle)
+target_link_libraries(llvm INTERFACE ${LLVM_LIBS})
 
 set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}")
 set(LIBMEM_INC "${LIBMEM_DIR}/include")
@@ -109,8 +123,8 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
 	file(GLOB LIBMEM_SRC ${LIBMEM_ARCH_SRC} "${LIBMEM_DIR}/src/freebsd/*.c" "${LIBMEM_DIR}/src/freebsd/ptrace/*.c" "${LIBMEM_DIR}/src/common/*.c" "${LIBMEM_DIR}/src/common/*.cpp" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp")
 endif()
 set(LIBMEM_DEPS
-	capstone
-	keystone
+	${CAPSTONE_LINK_LIBRARIES}
+	${KEYSTONE_LINK_LIBRARIES}
 	llvm
 )
 
@@ -133,12 +147,10 @@ if (LIBMEM_BUILD_TESTS)
 	add_subdirectory(${TESTS_DIR})
 endif()
 
-set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC})
+set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC}
+    VERSION ${PROJECT_VERSION}
+    SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
 target_compile_definitions(libmem PUBLIC LM_EXPORT)
-add_dependencies(libmem
-	capstone-engine
-	keystone-engine
-)
 
 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
 	set(LIBMEM_DEPS
@@ -147,7 +159,14 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN
 		psapi
 		ntdll
   		shell32
+		ole32
 	)
+	if(MINGW)
+		set(LIBMEM_DEPS
+			${LIBMEM_DEPS}
+			uuid
+		)
+	endif()
 	target_compile_definitions(libmem PUBLIC alloca=_alloca)
 elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL Android)
 	set(LIBMEM_DEPS 
@@ -171,7 +190,7 @@ else()
 endif()
 
 target_link_libraries(libmem ${LIBMEM_DEPS})
-if(LIBMEM_BUILD_STATIC)
+if(0)
 	# Create a bundled static library containing all dependencies (to mimic the shared library behavior)
 	set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial")
 	set(libmem_bundle_files "$<TARGET_FILE:libmem>")
@@ -212,7 +231,7 @@ if(LIBMEM_BUILD_STATIC)
 	endif()
 endif()
 
-if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
+if(0)
 	if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
 		cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}")
 	else()
@@ -221,14 +240,46 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN
 	endif()
 	set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/libmem")
 	execute_process(COMMAND mkdir "${CMAKE_INSTALL_PREFIX}")
-else()
 	set(CMAKE_INSTALL_PREFIX "/usr")
 endif()
 
 install(TARGETS libmem
-	LIBRARY DESTINATION lib)
-
-install(TARGETS libmem
-	RUNTIME DESTINATION lib)
+    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+set(LIBMEM_PC_PRIVATE_LIBS "")
+if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
+	set(LIBMEM_PC_PRIVATE_LIBS "-luser32 -lpsapi -lntdll -lshell32 -lole32")
+	if(MINGW)
+		set(LIBMEM_PC_PRIVATE_LIBS "${LIBMEM_PC_PRIVATE_LIBS} -luuid")
+	endif()
+elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL Android)
+	set(LIBMEM_PC_PRIVATE_LIBS "-ldl -lstdc++ -lm")
+elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
+	set(LIBMEM_PC_PRIVATE_LIBS "-ldl -lkvm -lprocstat -lelf -lstdc++ -lm")
+endif()
+set(PROJECT_REQUIRES_PRIVATE "capstone keystone")
+if(MINGW)
+	if(LIBMEM_BUILD_STATIC)
+		set(LIBRARY_NAME "-l:liblibmem.a ${LIBMEM_PC_PRIVATE_LIBS}")
+		configure_file(libmem-static.pc.in libmem-static.pc.cf @ONLY)
+		file(
+			GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libmem-static.pc"
+			INPUT "${CMAKE_CURRENT_BINARY_DIR}/libmem-static.pc.cf")
+		install(
+			FILES "${CMAKE_CURRENT_BINARY_DIR}/libmem-static.pc"
+			DESTINATION "lib/pkgconfig")
+	else()
+		set(LIBRARY_NAME "-l:liblibmem.dll.a")
+		configure_file(libmem.pc.in libmem.pc.cf @ONLY)
+		file(
+			GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libmem.pc"
+			INPUT "${CMAKE_CURRENT_BINARY_DIR}/libmem.pc.cf")
+		install(
+			FILES "${CMAKE_CURRENT_BINARY_DIR}/libmem.pc"
+			DESTINATION "lib/pkgconfig")
+	endif()
+endif()
 
 install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include)
