From 7072b25e433148006dfca1dc100eb45050b2db90 Mon Sep 17 00:00:00 2001 From: Weijia Song Date: Sun, 7 Apr 2019 14:51:28 -0400 Subject: [PATCH] Add find_package support (#2) * add cmake find_package() support, to be tested. * bugfix to in mutilsConfig.cmake * minor optimization; remove Makefile * fix include and lib path --- CMakeLists.txt | 45 +++++++++++++++++++++++++++++++++++++++------ Makefile | 20 -------------------- mutilsConfig.cmake | 2 ++ 3 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 Makefile create mode 100644 mutilsConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 25bf650..7097577 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,49 @@ cmake_minimum_required (VERSION 3.1) project (mutils) +#Versions +set(mutils_VERSION 1.0) + #CXX FLAGS set(CMAKE_CXX_FLAGS_RELEASE "-std=c++14 -fPIC") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_DEBUG "-std=c++14 -fPIC -g") set(CMAKE_SHARED_LINKER_FLAGS "-shared --enable-new-dtags") -include_directories(${mutils_SOURCE_DIR}/include) - add_library(mutils SHARED utils.cpp abiutils.cpp) +target_include_directories(mutils PRIVATE $) + +#Make install +install(TARGETS mutils EXPORT mutils + LIBRARY DESTINATION lib) +install(DIRECTORY include/mutils + DESTINATION include) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/mutils/mutilsConfigVersion.cmake" + VERSION ${mutils_VERSION} + COMPATIBILITY AnyNewerVersion +) + +export (EXPORT mutils + FILE "${CMAKE_CURRENT_BINARY_DIR}/mutils/mutilsTargets.cmake" +) + +configure_file (mutilsConfig.cmake + "${CMAKE_CURRENT_BINARY_DIR}/mutils/mutilsConfig.cmake" + COPYONLY +) + +set(ConfigPackageLocation lib/cmake/mutils) +install(EXPORT mutils + FILE mutilsTargets.cmake + DESTINATION ${ConfigPackageLocation} +) -set_target_properties(mutils PROPERTIES PUBLIC_HEADER "include/mutils/17_type_utils.hpp;include/mutils/17utils.hpp;include/mutils/AtScopeEnd.hpp;include/mutils/CTString.hpp;include/mutils/CTString_decl.hpp;include/mutils/CTString_impl.hpp;include/mutils/CTString_macro.hpp;include/mutils/CTString_split.hpp;include/mutils/CTString_strip_paren_group.hpp;include/mutils/FunctionalMap.hpp;include/mutils/Hertz.hpp;include/mutils/PrintableObject.hpp;include/mutils/abiutils.hpp;include/mutils/args-finder.hpp;include/mutils/argswrapper.hpp;include/mutils/as_value.hpp;include/mutils/backtrace.hpp;include/mutils/cexprutils.hpp;include/mutils/compile-time-lambda.hpp;include/mutils/compile-time-tuple.hpp;include/mutils/cstring.hpp;include/mutils/extras;include/mutils/filter-varargs.hpp;include/mutils/macro_utils.hpp;include/mutils/mutils.hpp;include/mutils/peano.hpp;include/mutils/private_access.hpp;include/mutils/restrict.hpp;include/mutils/tuple_extras.hpp;include/mutils/type_utils.hpp;include/mutils/typelist.hpp;include/mutils/typeset.hpp;include/mutils/variant.hpp") -install(TARGETS mutils - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include/mutils/) +install( + FILES + mutilsConfig.cmake + "${CMAKE_CURRENT_BINARY_DIR}/mutils/mutilsConfigVersion.cmake" + DESTINATION ${ConfigPackageLocation} +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 3e3dc2f..0000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -.PHONY : clean - -TARGET=libmutils.so - -CPPFLAGS=-fPIC -g --std=c++14 -LDFLAGS= -shared -Wl,-rpath=$(shell pwd)/ --enable-new-dtags - -SOURCES = utils.cpp - -HEADERS = AtScopeEnd.hpp backtrace.hpp compile-time-tuple.hpp macro_utils.hpp restrict.hpp type_utils.hpp Hertz.hpp args-finder.hpp compile-time-lambda.hpp filter-varargs.hpp mutils.hpp tuple_extras.hpp FunctionalMap.hpp -OBJECTS=$(SOURCES:.cpp=.o) - -all: $(TARGET) - -clean: - rm -f $(OBJECTS) $(TARGET) - -$(TARGET) : $(OBJECTS) - $(CXX) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS) - diff --git a/mutilsConfig.cmake b/mutilsConfig.cmake new file mode 100644 index 0000000..45be9b9 --- /dev/null +++ b/mutilsConfig.cmake @@ -0,0 +1,2 @@ +set(mutils_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include") +set(mutils_LIBRARIES "-L${CMAKE_INSTALL_PREFIX}/lib -lmutils")