--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,14 +15,22 @@ if (WIN32)
     set (NATPMP_SOURCES ${NATPMP_SOURCES} wingettimeofday.c)
 endif (WIN32)
 
-# Library itself
-add_library(natpmp STATIC ${NATPMP_SOURCES})
-target_include_directories(natpmp PUBLIC ${CMAKE_CURRENT_LIST_DIR})
-target_compile_definitions(natpmp PRIVATE -DENABLE_STRNATPMPERR)
+add_library(natpmp-obj OBJECT ${NATPMP_SOURCES})
+target_compile_definitions(natpmp-obj PUBLIC -DNATPMP_STATICLIB)
+target_compile_definitions(natpmp-obj PRIVATE -DENABLE_STRNATPMPERR)
+target_include_directories(natpmp-obj PUBLIC ${CMAKE_CURRENT_LIST_DIR})
+
+# Static library
+add_library(natpmp-static STATIC $<TARGET_OBJECTS:natpmp-obj>)
+set_target_properties(natpmp-static PROPERTIES OUTPUT_NAME natpmp)
+
+# Shared library
+add_library(natpmp SHARED $<TARGET_OBJECTS:natpmp-obj>)
+set_property(TARGET natpmp PROPERTY POSITION_INDEPENDENT_CODE 1)
 
 if (WIN32)
 	target_link_libraries(natpmp PUBLIC ws2_32 Iphlpapi)
-	target_compile_definitions(natpmp PUBLIC -DNATPMP_STATICLIB)
+	target_link_libraries(natpmp-static PUBLIC ws2_32 Iphlpapi)
 endif (WIN32)
 
 # Executables
@@ -33,3 +41,9 @@ add_executable(testgetgateway
 	testgetgateway.c
 	getgateway.c)
 target_link_libraries(testgetgateway natpmp)
+
+install(TARGETS natpmpc)
+install(TARGETS natpmp)
+install(TARGETS natpmp-static)
+install(FILES natpmp.h DESTINATION include)
+install(FILES natpmp_declspec.h DESTINATION include)
