--- CMakeLists.txt.orig	2024-03-27 13:30:15 UTC
+++ CMakeLists.txt
@@ -29,25 +29,6 @@ include(sources.cmake)
 include(sources.cmake)
 
 #-----------------------------------------------------------------------------
-# Options
-#-----------------------------------------------------------------------------
-option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
-
-#-----------------------------------------------------------------------------
-# Add support for ccache if desired
-#-----------------------------------------------------------------------------
-find_program(CCACHE ccache)
-
-if(CCACHE)
-    option(ENABLE_CCACHE "Enable ccache." ON)
-endif()
-
-# use ccache if installed
-if(CCACHE AND ENABLE_CCACHE)
-    set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
-endif()
-
-#-----------------------------------------------------------------------------
 # Compose CFLAGS
 #-----------------------------------------------------------------------------
 
@@ -68,10 +49,10 @@ else()
     set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow
                     -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
                     -Wstrict-prototypes -Wpointer-arith -Wsystem-headers)
-    set(CMAKE_C_FLAGS_DEBUG "-g3")
-    set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
-    set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
-    set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
+#    set(CMAKE_C_FLAGS_DEBUG "-g3")
+#    set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
+#    set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
+#    set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
 endif()
 
 # What compiler do we have and what are their...uhm... peculiarities
@@ -103,6 +84,7 @@ add_library(${PROJECT_NAME}
 # library target
 #-----------------------------------------------------------------------------
 add_library(${PROJECT_NAME}
+    OBJECT
     ${SOURCES}
     ${HEADERS}
 )
@@ -125,12 +107,23 @@ endif()
     list(APPEND PUBLIC_HEADERS tommath_c89.h)
 endif()
 
+add_library(${PROJECT_NAME}_shared SHARED $<TARGET_OBJECTS:${PROJECT_NAME}>)
+add_library(${PROJECT_NAME}_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}>)
 set_target_properties(${PROJECT_NAME} PROPERTIES
+    POSITION_INDEPENDENT_CODE TRUE
+)
+set_target_properties(${PROJECT_NAME}_shared PROPERTIES
     OUTPUT_NAME tommath
     VERSION ${PROJECT_VERSION}
     SOVERSION ${PROJECT_VERSION_MAJOR}
     PUBLIC_HEADER "${PUBLIC_HEADERS}"
 )
+set_target_properties(${PROJECT_NAME}_static PROPERTIES
+    OUTPUT_NAME tommath
+    VERSION ${PROJECT_VERSION}
+    SOVERSION ${PROJECT_VERSION_MAJOR}
+    PUBLIC_HEADER "${PUBLIC_HEADERS}"
+)
 
 option(COMPILE_LTO "Build with LTO enabled")
 if(COMPILE_LTO)
@@ -159,7 +152,7 @@ set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
 set(PROJECT_CONFIG_FILE "${PROJECT_NAME}-config.cmake")
 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
 
-install(TARGETS ${PROJECT_NAME}
+install(TARGETS ${PROJECT_NAME}_shared ${PROJECT_NAME}_static
     EXPORT ${TARGETS_EXPORT_NAME}
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
@@ -168,20 +161,18 @@ install(TARGETS ${PROJECT_NAME}
 )
 
 # Install libtommath.pc for pkg-config if we build a shared library
-if(BUILD_SHARED_LIBS)
-    # Let the user override the default directory of the pkg-config file (usually this shouldn't be required to be changed)
-    set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Folder where to install .pc files")
+# Let the user override the default directory of the pkg-config file (usually this shouldn't be required to be changed)
+set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Folder where to install .pc files")
 
-    configure_file(
-        ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
-        ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
-        @ONLY
-    )
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
+    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
+    @ONLY
+)
 
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
-        DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}
-    )
-endif()
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
+    DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}
+)
 
 # generate package version file
 write_basic_package_version_file(
@@ -262,18 +253,11 @@ endif()
     list(APPEND CPACK_GENERATOR FREEBSD)
 endif()
 
-set(LTM_DEBIAN_SHARED_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}")
-
 # general CPack config
 set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/${DISTRO_PACK_PATH})
 message(STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}")
-if(BUILD_SHARED_LIBS)
-    set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}")
-    set(CPACK_DEBIAN_PACKAGE_NAME "${LTM_DEBIAN_SHARED_PACKAGE_NAME}")
-else()
-    set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel")
-    set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}-dev")
-endif()
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}")
+set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}")
 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LibTomMath")
 set(CPACK_PACKAGE_VENDOR "libtom projects")
@@ -287,15 +271,7 @@ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
 set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
 set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
 set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
-if(BUILD_SHARED_LIBS)
-    set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
-else()
-    set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
-    set(CPACK_DEBIAN_PACKAGE_DEPENDS ${LTM_DEBIAN_SHARED_PACKAGE_NAME})
-    set(CPACK_DEB_COMPONENT_INSTALL ON)
-    set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
-    set(CPACK_COMPONENTS_ALL Libraries)
-endif()
+set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
 
 # rpm specific CPack config
 set(CPACK_RPM_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
