cmake: add cmake lists file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..d923599
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,97 @@
+#
+# LibTomMath, a free open source portable number theoretic multiple-precision
+# integer (MPI) library written entirely in C.
+#
+
+cmake_minimum_required(VERSION 3.7)
+project(tommath VERSION 1.2.0)
+
+#-----------------------------------------------------------------------------
+# Include cmake modules
+#-----------------------------------------------------------------------------
+include(GNUInstallDirs)
+include(CMakePackageConfigHelpers)
+include(sources.cmake)
+
+#-----------------------------------------------------------------------------
+# library target
+#-----------------------------------------------------------------------------
+add_library(${PROJECT_NAME}
+ ${SOURCES}
+)
+
+target_include_directories(${PROJECT_NAME} PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
+)
+
+set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
+set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
+
+#-----------------------------------------------------------------------------
+# demo target
+#-----------------------------------------------------------------------------
+add_executable(test EXCLUDE_FROM_ALL
+ ${CMAKE_CURRENT_SOURCE_DIR}/demo/shared.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/demo/test.c
+)
+
+target_include_directories(test PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+target_link_libraries(test PRIVATE
+ ${PROJECT_NAME}
+)
+
+#-----------------------------------------------------------------------------
+# demo target
+#-----------------------------------------------------------------------------
+add_custom_target(check
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test
+)
+
+add_dependencies(check test)
+
+#-----------------------------------------------------------------------------
+# Install/export targets and files
+#-----------------------------------------------------------------------------
+set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
+set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
+set(PROJECT_CONFIG_FILE "${PROJECT_NAME}-config.cmake")
+set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
+
+install(TARGETS ${PROJECT_NAME}
+ EXPORT ${TARGETS_EXPORT_NAME}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+install(FILES ${HEADERS}
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
+)
+
+# generate package version file
+write_basic_package_version_file(
+ ${PROJECT_VERSION_FILE}
+ VERSION ${PROJECT_VERSION}
+ COMPATIBILITY SameMajorVersion
+)
+
+# install version file
+install(FILES ${PROJECT_VERSION_FILE}
+ DESTINATION ${CONFIG_INSTALL_DIR}
+)
+
+# build directory package config
+export(EXPORT ${TARGETS_EXPORT_NAME}
+ FILE ${PROJECT_CONFIG_FILE}
+)
+
+# installed package config
+install(EXPORT ${TARGETS_EXPORT_NAME}
+ DESTINATION ${CONFIG_INSTALL_DIR}
+ FILE ${PROJECT_CONFIG_FILE}
+)
+
+# add to CMake registry
+export(PACKAGE ${PROJECT_NAME})