diff --git a/CMakeLists.txt b/CMakeLists.txt
index 534057a..6f7c648 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,5 @@
 cmake_minimum_required(VERSION 3.22.1)
 
-include(ExternalProject)
 
 project(libmem
 	LANGUAGES
@@ -48,23 +47,18 @@ message(STATUS
 
 message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
 message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(CAPSTONE REQUIRED capstone)
+pkg_check_modules(KEYSTONE REQUIRED keystone)
 
 # External dependencies
 set(EXTERNAL_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/external")
-set(CAPSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/capstone")
-set(CAPSTONE_INC "${CAPSTONE_DIR}/include")
-set(CAPSTONE_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/capstone-engine-prefix/src/capstone-engine-build")
-set(KEYSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/keystone")
-set(KEYSTONE_INC "${KEYSTONE_DIR}/include")
-set(KEYSTONE_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/keystone-engine-prefix/src/keystone-engine-build/llvm/lib")
+set(CAPSTONE_INC "${CAPSTONE_INCLUDE_DIR}")
+set(KEYSTONE_INC "${KEYSTONE_INCLUDE_DIR}")
 set(LLVM_DIR "${EXTERNAL_DEPENDENCIES_DIR}/llvm")
 set(LLVM_INC "${LLVM_DIR}/include")
+file(GLOB_RECURSE LLVM_DEM_SRC "${LLVM_DIR}/lib/*.cpp")
 
-add_subdirectory("${EXTERNAL_DEPENDENCIES_DIR}")
-add_library(capstone STATIC IMPORTED)
-set_target_properties(capstone PROPERTIES IMPORTED_LOCATION ${CAPSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX})
-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
 
 set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}")
@@ -90,11 +84,11 @@ 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
-	llvm
+	${CAPSTONE_LINK_LIBRARIES}
+	${KEYSTONE_LINK_LIBRARIES}
 )
 
+set(LIBMEM_SRC ${LIBMEM_SRC} ${LLVM_DEM_SRC})
 if (LIBMEM_BUILD_STATIC)
 	add_library(libmem STATIC ${LIBMEM_SRC})
 else()
@@ -116,10 +110,6 @@ endif()
 
 set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC})
 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
@@ -193,7 +183,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()
@@ -202,14 +192,22 @@ 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()
+endif()
+if(0)
 	set(CMAKE_INSTALL_PREFIX "/usr")
 endif()
 
 install(TARGETS libmem
-	LIBRARY DESTINATION lib)
-
-install(TARGETS libmem
-	RUNTIME DESTINATION lib)
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib
+	RUNTIME DESTINATION bin
+)
+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")
 
 install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include)
