diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb52c1992b5f9fd1f9c937def942e592cc663de7..938d4983a176cd07574a8e8535d993025fef74e1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,7 @@ set(KEYSTONE_VERSION_MAJOR 0)
 set(KEYSTONE_VERSION_MINOR 9)
 
 option(KEYSTONE_BUILD_STATIC_RUNTIME "Embed static runtime" ON)
+option(BUILD_LIBS_ONLY "Only build keystone library" 0)
 
 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
   message(STATUS "No build type selected, default to Debug")
@@ -73,7 +74,7 @@ add_subdirectory(llvm)
 # for Windows, do not build kstool if buiding DLL
 # TODO: fix this
 if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
-if (NOT BUILD_SHARED_LIBS)
+if (NOT BUILD_LIBS_ONLY AND NOT BUILD_SHARED_LIBS)
     add_subdirectory(kstool)
 endif()
 else()
@@ -112,7 +113,11 @@ configure_file(
     "${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake"
     IMMEDIATE @ONLY)
 
-add_custom_target(uninstall
-    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake)
+if(NOT BUILD_LIBS_ONLY)
+    add_custom_target(uninstall
+        COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake)
+endif()
 
-add_subdirectory(suite/fuzz)
\ No newline at end of file
+if(NOT BUILD_LIBS_ONLY)
+    add_subdirectory(suite/fuzz)
+endif()
diff --git a/include/keystone/keystone.h b/include/keystone/keystone.h
index 2fbf77f93fff22b180e348d6052d6525f1d7363b..e29235eab41186ef197e457d9c9904dc9343405a 100644
--- a/include/keystone/keystone.h
+++ b/include/keystone/keystone.h
@@ -16,14 +16,22 @@ extern "C" {
 #ifdef _MSC_VER     // MSVC compiler
 #pragma warning(disable:4201)
 #pragma warning(disable:4100)
+#ifndef KEYSTONE_STATIC
 #define KEYSTONE_EXPORT __declspec(dllexport)
 #else
+#define KEYSTONE_EXPORT
+#endif
+#else
 #ifdef __GNUC__
 #include <stdbool.h>
+#ifndef KEYSTONE_STATIC
 #define KEYSTONE_EXPORT __attribute__((visibility("default")))
 #else
 #define KEYSTONE_EXPORT
 #endif
+#else
+#define KEYSTONE_EXPORT
+#endif
 #endif
 
 
diff --git a/llvm/keystone/CMakeLists.txt b/llvm/keystone/CMakeLists.txt
index 572d0f4ea59950740a74cec80a68c04ccf1ed59f..719485a32c79afecefb0d77a53ff0029313d2614 100644
--- a/llvm/keystone/CMakeLists.txt
+++ b/llvm/keystone/CMakeLists.txt
@@ -53,6 +53,14 @@ set_target_properties(
   SOVERSION ${KEYSTONE_VERSION_MAJOR}
 )
 
+if(NOT BUILD_SHARED_LIBS)
+  target_compile_definitions(
+    keystone
+    PUBLIC
+    KEYSTONE_STATIC
+  )
+endif()
+
 if (APPLE)
   set_target_properties(keystone
                         PROPERTIES