From c46e42c3415dbfbe100665f428e0e78504916742 Mon Sep 17 00:00:00 2001 From: chenli Date: Thu, 7 Mar 2019 11:02:01 +0800 Subject: [PATCH] add cmake installation support (#82) Adds cmake installation support --- CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++++++ README.md | 21 +++++++++++------ cmake/Mach7Config.cmake.in | 5 ++++ code/test/CMakeLists.txt | 2 ++ 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/Mach7Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f2e6bea --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,48 @@ +# Version 3.2 is needed to be able to have support of target_compile_features for AppleClang +cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR) + +# Sets the name of the project, and stores it in the variable PROJECT_NAME. When called from the top-level CMakeLists.txt also stores the project name in the variable CMAKE_PROJECT_NAME. +project(Mach7) + +# Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.txt and code files are located. +project(Mach7) + +add_subdirectory(code/test) + +# Define the library target +add_library(Mach7 INTERFACE) +add_library(Mach7::Mach7 ALIAS Mach7) + +install(TARGETS Mach7 + EXPORT Mach7Targets + LIBRARY DESTINATION lib COMPONENT Runtime + ARCHIVE DESTINATION lib COMPONENT Development + RUNTIME DESTINATION bin COMPONENT Runtime + PUBLIC_HEADER DESTINATION include COMPONENT Development + BUNDLE DESTINATION bin COMPONENT Runtime +) + +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/Mach7Config.cmake.in" + "${PROJECT_BINARY_DIR}/Mach7Config.cmake" + INSTALL_DESTINATION lib/cmake/Mach7 +) + +install(EXPORT Mach7Targets DESTINATION lib/cmake/Mach7) +install(FILES + "${PROJECT_BINARY_DIR}/Mach7Config.cmake" + DESTINATION lib/cmake/Mach7) + + +# for linux: copy header files to /usr/local/ by default +# for windows: copy header fiels to c:/Program Files by default +install( + DIRECTORY ${CMAKE_SOURCE_DIR}/code/mach7/ + DESTINATION include/mach7) +install( + DIRECTORY ${CMAKE_SOURCE_DIR}/code/xtl/ + DESTINATION include/xtl) +install( + DIRECTORY ${CMAKE_SOURCE_DIR}/code/cppft/ + DESTINATION include/cppft) diff --git a/README.md b/README.md index 3f73cd6..a311957 100644 --- a/README.md +++ b/README.md @@ -161,13 +161,20 @@ on the library were built with. [CMake](https://cmake.org/) support is the most recent and is still very experimental at this point. To build with cmake, perform the following commands from within Mach7 folder: - cd code/test - mkdir build - cd build - cmake .. - cmake --build . - - Version 3.2 is needed in order to be able to have support of target_compile_features for AppleClang + cmake -H. -Bbuild + cmake --build build --target install + +Note: this requires administrative privileges under all systems, if you don't like this, try commands below: + + cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX=/wherever/doesn't/require/administrative/priviege + cmake --build build --target install + +But please make sure msvc/clang/gcc is able to find the path your provide above when +including Mach7's headers in your own project: + +- MSVC: https://stackoverflow.com/questions/335408/where-does-visual-studio-look-for-c-header-files +- Gcc/Clang: -I +- CMake: https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake #### Using Makefiles for GCC (4.4 or later) or Clang (3.3 or later) diff --git a/cmake/Mach7Config.cmake.in b/cmake/Mach7Config.cmake.in new file mode 100644 index 0000000..88b43a4 --- /dev/null +++ b/cmake/Mach7Config.cmake.in @@ -0,0 +1,5 @@ +# https://stackoverflow.com/questions/47718485/install-and-export-interface-only-library-cmake +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/Mach7Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/code/test/CMakeLists.txt b/code/test/CMakeLists.txt index 8d0ca5b..6fcb5d1 100644 --- a/code/test/CMakeLists.txt +++ b/code/test/CMakeLists.txt @@ -7,7 +7,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Add preprocessor definition to disable internal XTL messages add_definitions(-DXTL_MESSAGE_ENABLED=0) +# Sets the name of the project, and stores it in the variable PROJECT_NAME. When called from the top-level CMakeLists.txt also stores the project name in the variable CMAKE_PROJECT_NAME. project(Tests) +# Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.txt and code files are located. add_subdirectory(unit) add_subdirectory(time)