diff --git a/CMakeLists.txt b/CMakeLists.txt
index fc45f80..e3b0dbf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -152,15 +152,24 @@ foreach(lib brotlicommon brotlidec brotlienc)
   target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" )
   string(TOUPPER "${lib}" LIB)
   set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" )
+  if (NOT BUILD_SHARED_LIBS)
+    set_target_properties(${lib} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)
+  endif()
 endforeach()
 
+if (BUILD_SHARED_LIBS)
+  foreach(lib brotlienc-static brotlidec-static brotlicommon-static)
+    set_target_properties(${lib} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)
+  endforeach()
+endif()
+
 foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-static brotlienc-static)
   target_link_libraries(${lib} ${LIBM_LIBRARY})
   set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
   set_target_properties(${lib} PROPERTIES
     VERSION "${BROTLI_ABI_COMPATIBILITY}.${BROTLI_ABI_AGE}.${BROTLI_ABI_REVISION}"
     SOVERSION "${BROTLI_ABI_COMPATIBILITY}"
-    POSITION_INDEPENDENT_CODE TRUE)
+  )
   set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}")
 endforeach()
 
@@ -184,27 +193,33 @@ endif()
 # Build the brotli executable
 add_executable(brotli ${BROTLI_CLI_C})
 target_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC})
+set_target_properties(brotli PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)
+
 
 # Installation
 if(NOT BROTLI_BUNDLED_MODE)
+  if (NOT)
   install(
     TARGETS brotli
     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   )
+  endif()
 
+  if (BUILD_SHARED_LIBS)
   install(
     TARGETS ${BROTLI_LIBRARIES_CORE}
     ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   )
-
+  else()
   install(
     TARGETS ${BROTLI_LIBRARIES_CORE_STATIC}
     ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   )
+  endif()
 
   install(
     DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli
