--- a/c++/src/CMakeLists.txt
+++ b/c++/src/CMakeLists.txt
@@ -86,6 +86,7 @@ set (CPP_HDRS
     ${HDF5_CPP_SRC_SOURCE_DIR}/H5VarLenType.h
 )
 
+if (NOT BUILD_SHARED_LIBS)
 add_library (${HDF5_CPP_LIB_TARGET} STATIC ${CPP_SRCS} ${CPP_HDRS})
 TARGET_C_PROPERTIES (${HDF5_CPP_LIB_TARGET} STATIC " " " ")
 target_link_libraries (${HDF5_CPP_LIB_TARGET} PUBLIC ${HDF5_LIB_TARGET})
@@ -96,6 +97,7 @@ set_target_properties (${HDF5_CPP_LIB_TARGET} PROPERTIES
     INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
 )
 set (install_targets ${HDF5_CPP_LIB_TARGET})
+endif ()
 
 if (BUILD_SHARED_LIBS)
   add_library (${HDF5_CPP_LIBSH_TARGET} SHARED ${CPP_SRCS} ${CPP_HDRS})
@@ -130,8 +132,9 @@ install (
 if (HDF5_EXPORTED_TARGETS)
   if (BUILD_SHARED_LIBS)
     INSTALL_TARGET_PDB (${HDF5_CPP_LIBSH_TARGET} ${HDF5_INSTALL_BIN_DIR} cpplibraries)
-  endif ()
+  else ()
   INSTALL_TARGET_PDB (${HDF5_CPP_LIB_TARGET} ${HDF5_INSTALL_BIN_DIR} cpplibraries)
+  endif ()
 
   install (
       TARGETS
--- a/hl/c++/src/CMakeLists.txt
+++ b/hl/c++/src/CMakeLists.txt
@@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES (${HDF5_HL_CPP_SRC_SOURCE_DIR})
 set (HDF5_HL_CPP_SRCS ${HDF5_HL_CPP_SRC_SOURCE_DIR}/H5PacketTable.cpp)
 set (HDF5_HL_CPP_HDRS ${HDF5_HL_CPP_SRC_SOURCE_DIR}/H5PacketTable.h)
 
+if (NOT BUILD_SHARED_LIBS)
 add_library (${HDF5_HL_CPP_LIB_TARGET} STATIC ${HDF5_HL_CPP_SRCS})
 TARGET_C_PROPERTIES (${HDF5_HL_CPP_LIB_TARGET} STATIC " " " ")
 target_link_libraries (${HDF5_HL_CPP_LIB_TARGET} PUBLIC ${HDF5_HL_LIB_TARGET} ${HDF5_LIB_TARGET})
@@ -20,6 +21,7 @@ set_target_properties (${HDF5_HL_CPP_LIB_TARGET} PROPERTIES
     INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
 )
 set (install_targets ${HDF5_HL_CPP_LIB_TARGET})
+endif ()
 
 if (BUILD_SHARED_LIBS)
   add_library (${HDF5_HL_CPP_LIBSH_TARGET} SHARED ${HDF5_HL_CPP_SRCS})
@@ -54,8 +56,9 @@ install (
 if (HDF5_EXPORTED_TARGETS)
   if (BUILD_SHARED_LIBS)
     INSTALL_TARGET_PDB (${HDF5_HL_CPP_LIBSH_TARGET} ${HDF5_INSTALL_BIN_DIR} hlcpplibraries)
-  endif ()
+  else ()
   INSTALL_TARGET_PDB (${HDF5_HL_CPP_LIB_TARGET} ${HDF5_INSTALL_BIN_DIR} hlcpplibraries)
+  endif ()
 
   install (
       TARGETS
--- a/hl/src/CMakeLists.txt
+++ b/hl/src/CMakeLists.txt
@@ -26,6 +26,7 @@ set (HL_HEADERS
     ${HDF5_HL_SRC_SOURCE_DIR}/hdf5_hl.h
 )
 
+if (NOT BUILD_SHARED_LIBS)
 add_library (${HDF5_HL_LIB_TARGET} STATIC ${HL_SRCS} ${HL_HEADERS})
 TARGET_C_PROPERTIES (${HDF5_HL_LIB_TARGET} STATIC " " " ")
 target_link_libraries (${HDF5_HL_LIB_TARGET} PUBLIC ${HDF5_LIB_TARGET})
@@ -36,6 +37,7 @@ set_target_properties (${HDF5_HL_LIB_TARGET} PROPERTIES
 )
 set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_HL_LIB_TARGET}")
 set (install_targets ${HDF5_HL_LIB_TARGET})
+endif ()
 
 if (BUILD_SHARED_LIBS)
   add_library (${HDF5_HL_LIBSH_TARGET} SHARED ${HL_SRCS} ${HL_HEADERS})
@@ -70,8 +72,9 @@ install (
 if (HDF5_EXPORTED_TARGETS)
   if (BUILD_SHARED_LIBS)
     INSTALL_TARGET_PDB (${HDF5_HL_LIBSH_TARGET} ${HDF5_INSTALL_BIN_DIR} hllibraries)
-  endif ()
+  else ()
   INSTALL_TARGET_PDB (${HDF5_HL_LIB_TARGET} ${HDF5_INSTALL_BIN_DIR} hllibraries)
+  endif ()
 
   install (
       TARGETS
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -696,6 +696,8 @@ set_source_files_properties (${HDF5_BINARY_DIR}/H5version.h GENERATED)
 set (common_SRCS ${common_SRCS} ${HDF5_BINARY_DIR}/H5overflow.h)
 set_source_files_properties (${HDF5_BINARY_DIR}/H5overflow.h GENERATED)
 
+option (HDF5_ENABLE_DEBUG_APIS "Turn on extra debug output in all packages" OFF)
+if (NOT BUILD_SHARED_LIBS)
 add_library (${HDF5_LIB_TARGET} STATIC ${common_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS})
 TARGET_C_PROPERTIES (${HDF5_LIB_TARGET} STATIC " " " ")
 target_link_libraries (${HDF5_LIB_TARGET} PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS})
@@ -709,7 +711,6 @@ set_target_properties (${HDF5_LIB_TARGET} PROPERTIES
     INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
 )
 
-option (HDF5_ENABLE_DEBUG_APIS "Turn on extra debug output in all packages" OFF)
 if (HDF5_ENABLE_DEBUG_APIS)
   set_target_properties (${HDF5_LIB_TARGET} PROPERTIES
       COMPILE_DEFINITIONS
@@ -717,6 +718,7 @@ if (HDF5_ENABLE_DEBUG_APIS)
   )
 endif ()
 set (install_targets ${HDF5_LIB_TARGET})
+endif()
 
 if (BUILD_SHARED_LIBS)
   add_library (${HDF5_LIBSH_TARGET} SHARED ${common_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS})
@@ -770,8 +772,9 @@ endif ()
 if (HDF5_EXPORTED_TARGETS)
   if (BUILD_SHARED_LIBS)
     INSTALL_TARGET_PDB (${HDF5_LIBSH_TARGET} ${HDF5_INSTALL_BIN_DIR} libraries)
-  endif ()
+  else ()
   INSTALL_TARGET_PDB (${HDF5_LIB_TARGET} ${HDF5_INSTALL_BIN_DIR} libraries)
+  endif ()
 
   install (
       TARGETS
