diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ece68f4710917e4486daaad81649df9d7d96ac2..275b58d395f9843a7b220d98b6641f387a639829 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,8 +1,7 @@
 cmake_minimum_required(VERSION 3.13...3.19)
-project(libaec LANGUAGES C VERSION 1.0.4)
-option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
+project(libaec LANGUAGES C VERSION 1.0.5)
 
-# Automatically export symbls for Windows DLLs
+# Automatically export symbols for Windows DLLs
 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
 
 set(CMAKE_C_STANDARD 99)
@@ -61,6 +60,18 @@ if(AEC_FUZZING)
   target_link_options(aec PUBLIC ${FUZZ_TARGET_SAN_FLAGS})
 endif()
 
+# Install the cmake files.
+set(libaec_CONFIG_IN  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libaec-config.cmake.in)
+set(libaec_CONFIG_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/libaec-config.cmake)
+configure_file(${libaec_CONFIG_IN} ${libaec_CONFIG_OUT} @ONLY)
+set(libaec_CONFIG_VERSION_IN  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libaec-config-version.cmake.in)
+set(libaec_CONFIG_VERSION_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/libaec-config-version.cmake)
+configure_file(${libaec_CONFIG_VERSION_IN} ${libaec_CONFIG_VERSION_OUT} @ONLY)
+install(FILES ${libaec_CONFIG_OUT}
+        DESTINATION cmake)
+install(FILES ${libaec_CONFIG_VERSION_OUT}
+        DESTINATION cmake)
+
 # Cpack configuration mainly for Windows installer
 set(CPACK_PACKAGE_NAME "libaec")
 set(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
diff --git a/Config.cmake.in b/Config.cmake.in
deleted file mode 100644
index a2ce34f9c5beb89c9f7c29054096640a9f1cac5b..0000000000000000000000000000000000000000
--- a/Config.cmake.in
+++ /dev/null
@@ -1,5 +0,0 @@
-@PACKAGE_INIT@
-
-include("${CMAKE_CURRENT_LIST_DIR}/LibaecTargets.cmake")
-
-check_required_components(libaec)
diff --git a/cmake/libaec-config-version.cmake.in b/cmake/libaec-config-version.cmake.in
new file mode 100644
index 0000000000000000000000000000000000000000..d32ef969a13463b253a03c888f265082c7ebb309
--- /dev/null
+++ b/cmake/libaec-config-version.cmake.in
@@ -0,0 +1,15 @@
+set(PACKAGE_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
+set(PACKAGE_VERSION_MINOR @PROJECT_VERSION_MINOR@)
+set(PACKAGE_VERSION_PATCH @PROJECT_VERSION_PATCH@)
+set(PACKAGE_VERSION @PROJECT_VERSION@)
+
+# Check whether the requested PACKAGE_FIND_VERSION is compatible
+if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION OR
+   PACKAGE_VERSION_MAJOR GREATER PACKAGE_FIND_VERSION_MAJOR)
+  set(PACKAGE_VERSION_COMPATIBLE FALSE)
+else()
+  set(PACKAGE_VERSION_COMPATIBLE TRUE)
+  if(PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION)
+    set(PACKAGE_VERSION_EXACT TRUE)
+  endif()
+endif()
diff --git a/cmake/libaec-config.cmake.in b/cmake/libaec-config.cmake.in
new file mode 100644
index 0000000000000000000000000000000000000000..2eccec9fc713757366d0e7e64a6c0dc14c9710cd
--- /dev/null
+++ b/cmake/libaec-config.cmake.in
@@ -0,0 +1,94 @@
+# libaec-config.cmake
+# ----------------
+#
+# Finds the AEC library, specify the starting search path in libaec_ROOT.
+#
+# Static vs. shared
+# ----------------- 
+# To make use of the static library instead of the shared one, one needs
+# to set the variable libaec_USE_STATIC_LIBS to ON before calling find_package.
+# Example:
+#   set(libaec_USE_STATIC_LIBS ON)
+#   find_package(libaec CONFIG)
+#
+# This will define the following variables:
+#
+#   libaec_FOUND   - True if the system has the AEC library.
+#   libaec_VERSION - The version of the AEC library which was found.
+#   SZIP_FOUND     - True if the system has the SZIP library.
+#   SZIP_VERSION   - The version of the SZIP library which was found.
+#   SZIP_LIBRARIES - All the required libraries to make use of SZIP.
+#
+# and the following imported targets:
+#
+#   libaec::aec    - The AEC library.
+#   libaec::sz     - The SZIP compatible version of the AEC library.
+
+find_path(libaec_INCLUDE_DIR NAMES libaec.h DOC "AEC include directory")
+find_path(SZIP_INCLUDE_DIR NAMES szlib.h DOC "SZIP include directory")
+if (libaec_USE_STATIC_LIBS)
+  if (WIN32)
+    find_library(libaec_LIBRARY NAMES aec_static.lib DOC "AEC library")
+    find_library(SZIP_LIBRARY NAMES szip_static.lib DOC "SZIP compatible version of the AEC library")
+  else ()
+    find_library(libaec_LIBRARY NAMES libaec.a DOC "AEC library")
+    find_library(SZIP_LIBRARY NAMES libsz.a DOC "SZIP compatible version of the AEC library")
+  endif ()
+else ()
+  if (WIN32)
+    find_library(libaec_LIBRARY NAMES aec.lib DOC "AEC library")
+    find_library(SZIP_LIBRARY NAMES szip.lib DOC "SZIP compatible version of the AEC library")
+  else ()
+    find_library(libaec_LIBRARY NAMES libaec.so DOC "AEC library")
+    find_library(SZIP_LIBRARY NAMES libsz.so DOC "SZIP compatible version of the AEC library")
+  endif ()
+endif ()
+
+# Check version here
+if (libaec_INCLUDE_DIR AND libaec_LIBRARY)
+  set(libaec_VERSION "@PROJECT_VERSION@")
+  set(SZIP_VERSION "2.0.1")
+endif ()
+
+include(FindPackageHandleStandardArgs)
+set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
+find_package_handle_standard_args(libaec
+  FOUND_VAR libaec_FOUND
+  REQUIRED_VARS libaec_LIBRARY libaec_INCLUDE_DIR SZIP_LIBRARY SZIP_INCLUDE_DIR
+  VERSION_VAR libaec_VERSION
+  CONFIG_MODE
+)
+
+if (libaec_FOUND)
+  if (libaec_USE_STATIC_LIBS)
+    add_library(libaec::aec STATIC IMPORTED)
+  else ()
+    add_library(libaec::aec SHARED IMPORTED)
+  endif ()
+  set_target_properties(libaec::aec PROPERTIES
+    IMPORTED_LOCATION "${libaec_LIBRARY}"
+    INTERFACE_INCLUDE_DIRECTORIES "${libaec_INCLUDE_DIR}"
+  )
+
+  # SZIP
+  if (libaec_USE_STATIC_LIBS)
+    add_library(libaec::sz STATIC IMPORTED)
+  else ()
+    add_library(libaec::sz SHARED IMPORTED)
+  endif ()
+  set_target_properties(libaec::sz PROPERTIES
+    IMPORTED_LOCATION "${SZIP_LIBRARY}"
+    INTERFACE_INCLUDE_DIRECTORIES "${SZIP_INCLUDE_DIR}"
+  )
+  
+  # Set SZIP variables.
+  set(SZIP_FOUND TRUE)
+  set(SZIP_LIBRARIES "${SZIP_LIBRARY}")
+endif ()
+
+mark_as_advanced(
+  libaec_LIBRARY
+  libaec_INCLUDE_DIR
+  SZIP_LIBRARY
+  SZIP_INCLUDE_DIR
+)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9f43ba868d52f2c703061fd577ba95cca15cb82f..8cd46fba7feaf9fe0d0b963e81aba56c48c5b760 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,9 +1,8 @@
 # Main library aec
-add_library(aec
+add_library(aec OBJECT
   encode.c
   encode_accessors.c
   decode.c)
-add_library(libaec::aec ALIAS aec)
 
 target_include_directories(aec
   PUBLIC
@@ -11,23 +10,41 @@ target_include_directories(aec
   "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..>"
   "$<INSTALL_INTERFACE:include>")
 
-set_target_properties(aec
+# Create both static and shared aec library.
+add_library(aec_static STATIC "$<TARGET_OBJECTS:aec>")
+target_link_libraries(aec_static PUBLIC aec)
+set_target_properties(aec_static
+  PROPERTIES
+  OUTPUT_NAME $<IF:$<BOOL:${WIN32}>,aec_static,aec>)
+
+add_library(aec_shared SHARED "$<TARGET_OBJECTS:aec>")
+target_link_libraries(aec_shared PUBLIC aec)
+set_target_properties(aec_shared
   PROPERTIES
   VERSION 0.0.10
   SOVERSION 0
+  OUTPUT_NAME aec
   PUBLIC_HEADER ../include/libaec.h)
 
 # Wrapper for compatibility with szip
-add_library(sz sz_compat.c)
-add_library(libaec::sz ALIAS sz)
+add_library(sz OBJECT sz_compat.c)
+target_link_libraries(sz PUBLIC aec)
+
+# Create both static and shared szip library.
+add_library(sz_static STATIC "$<TARGET_OBJECTS:sz>" "$<TARGET_OBJECTS:aec>")
+set_target_properties(sz_static
+  PROPERTIES
+  OUTPUT_NAME $<IF:$<BOOL:${WIN32}>,szip_static,sz>)
+target_link_libraries(sz_static PUBLIC sz)
 
-set_target_properties(sz
+add_library(sz_shared SHARED "$<TARGET_OBJECTS:sz>" "$<TARGET_OBJECTS:aec>")
+target_link_libraries(sz_shared PUBLIC sz)
+set_target_properties(sz_shared
   PROPERTIES
   VERSION 2.0.1
   SOVERSION 2
   OUTPUT_NAME $<IF:$<BOOL:${WIN32}>,szip,sz>
   PUBLIC_HEADER ../include/szlib.h)
-target_link_libraries(sz PUBLIC aec)
 
 # Simple client for testing and benchmarking.
 # Can also be used stand-alone
@@ -61,25 +78,4 @@ if(UNIX)
     COMPONENT doc)
 endif()
 
-install(TARGETS aec sz aec_client
-  EXPORT LibaecTargets)
-
-install(EXPORT LibaecTargets
-  FILE LibaecTargets.cmake
-  NAMESPACE libaec::
-  DESTINATION lib/cmake)
-
-include(CMakePackageConfigHelpers)
-configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/../Config.cmake.in
-  "${CMAKE_CURRENT_BINARY_DIR}/LibaecConfig.cmake"
-  INSTALL_DESTINATION lib/cmake)
-
-# generate the version file for the config file
-write_basic_package_version_file(
-  "${CMAKE_CURRENT_BINARY_DIR}/LibaecConfigVersion.cmake"
-  COMPATIBILITY AnyNewerVersion)
-
-install(FILES
-  "${CMAKE_CURRENT_BINARY_DIR}/LibaecConfig.cmake"
-  "${CMAKE_CURRENT_BINARY_DIR}/LibaecConfigVersion.cmake"
-  DESTINATION lib/cmake)
+install(TARGETS aec_static aec_shared sz_static sz_shared aec_client)