summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-02-10 22:41:15 +0100
committerNao Pross <naopross@thearcway.org>2019-02-10 23:40:45 +0100
commitc74446c3e6a88ffbb13743dcc9f3b93d10aa009d (patch)
tree99676f3822af99f272110b3c3afaaf1ecfc0c9dc
parentMerge remote-tracking branch 'github/master' (diff)
downloadlibmm-c74446c3e6a88ffbb13743dcc9f3b93d10aa009d.tar.gz
libmm-c74446c3e6a88ffbb13743dcc9f3b93d10aa009d.zip
Add CMake configuration, delete ninja files
The new CMake configuration builds only static libraries
-rw-r--r--CMakeLists.txt107
-rw-r--r--build.ninja11
-rw-r--r--cmake/MMConfig.cmake.in9
-rw-r--r--ninja/rules.ninja27
4 files changed, 116 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..c31e16b
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,107 @@
+cmake_minimum_required(VERSION 3.10)
+project(
+ MM
+ VERSION 0.1
+ DESCRIPTION "MiniMath, a mathematical library that (ab)uses abstraction"
+ LANGUAGES CXX
+)
+
+list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
+
+############################
+# build libmm
+add_library(mm STATIC
+ mmvec.cpp
+)
+
+add_library(MM:mm ALIAS mm)
+
+# set up headers
+target_include_directories(mm
+ PUBLIC
+ $<INSTALL_INTERFACE:include>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+ PRIVATE
+ ${CMAKE_CURRENT_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/mm
+)
+
+target_compile_options(mm
+ PRIVATE
+ $<$<CXX_COMPILER_ID:GNU>:
+ -pedantic -Wall -Wextra -Wcast-qual -Wcast-align -Wpointer-arith
+ -Winit-self -Wshadow -Wswitch-enum -Wredundant-decls -Wfloat-equal
+ -Wundef -Wvla -Wconversion -Wstrict-aliasing
+ >
+ $<$<CXX_COMPILER_ID:MSVC>:/W4>
+)
+
+target_compile_definitions(mm
+ PRIVATE
+ $<$<CONFIG:Debug>:DEBUG>
+)
+
+# set compiler features
+# For a complete list see:
+# https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
+target_compile_features(mm
+ PRIVATE
+ cxx_std_17
+)
+
+
+############################
+# installation
+include(GNUInstallDirs)
+set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/MM)
+
+install(TARGETS mm
+ EXPORT mm-targets
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+set_target_properties(mm PROPERTIES EXPORT_NAME MM)
+
+# install public headers
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+# export targets
+install(EXPORT mm-targets
+ FILE
+ MMTargets.cmake
+ NAMESPACE
+ MM::
+ DESTINATION
+ ${INSTALL_CONFIGDIR}
+)
+
+# create ConfigVersion.cmake
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+ ${CMAKE_CURRENT_BINARY_DIR}/MMConfigVersion.cmake
+ VERSION ${PROJECT_VERSION}
+ COMPATIBILITY AnyNewerVersion
+)
+
+configure_package_config_file(
+ ${CMAKE_CURRENT_LIST_DIR}/cmake/MMConfig.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/MMConfig.cmake
+ INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
+)
+
+# install config, configversion
+install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/MMConfig.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/MMConfigVersion.cmake
+ DESTINATION ${INSTALL_CONFIGDIR}
+)
+
+############################
+# export from the build tree
+export(EXPORT mm-targets
+ FILE ${CMAKE_CURRENT_BINARY_DIR}/MMTargets.cmake
+ NAMESPACE MM::
+)
+
+export(PACKAGE MM)
diff --git a/build.ninja b/build.ninja
deleted file mode 100644
index 9f51a13..0000000
--- a/build.ninja
+++ /dev/null
@@ -1,11 +0,0 @@
-include ninja/rules.ninja
-
-# libmm
-build build/mmvec.o: cpp mmvec.cpp
-
-build build/libmm.a: link-static build/mmvec.o
-build build/libmm.so: link-shared build/mmvec.o
-
-# examples
-build build/example.o: cpp example.cpp
-build build/example: link build/example.o
diff --git a/cmake/MMConfig.cmake.in b/cmake/MMConfig.cmake.in
new file mode 100644
index 0000000..c338eae
--- /dev/null
+++ b/cmake/MMConfig.cmake.in
@@ -0,0 +1,9 @@
+get_filename_component(MM_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+list(REMOVE_AT CMAKE_MODULE_PATH -1)
+
+if (NOT TARGET MM::MM)
+ include("${MM_CMAKE_DIR}/MMTargets.cmake")
+endif()
+
+set(MM_LIBRARIES MM::MM)
diff --git a/ninja/rules.ninja b/ninja/rules.ninja
deleted file mode 100644
index a17c01a..0000000
--- a/ninja/rules.ninja
+++ /dev/null
@@ -1,27 +0,0 @@
-includes = -I include/mm
-cflags = -Wall -Werror -pedantic -fPIC -std=c++17 $includes
-
-libs =
-lflags = $libs
-
-flags = -fdiagnostics-color
-
-rule mkdir
- command = mkdir -p $out
- description = creating directory $out
-
-rule cpp
- command = g++ $flags $cflags -c $in -o $out $lflags
- description = compiling $in
-
-rule link
- command = g++ $flags $cflags -o $out $in $lflags
- description = linking $out
-
-rule link-shared
- command = g++ $flags $cflags -shared -o $out $in $lflags
- description = linking shared object $out
-
-rule link-static
- command = ar rvs $out $in
- description = creating archive $out