Skip to content

Commit

Permalink
add cmake installation support (#82)
Browse files Browse the repository at this point in the history
Adds cmake installation support
  • Loading branch information
FirstLoveLife authored and solodon4 committed Mar 7, 2019
1 parent c77d6f6 commit c46e42c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
48 changes: 48 additions & 0 deletions 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)
21 changes: 14 additions & 7 deletions README.md
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions 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@")
2 changes: 2 additions & 0 deletions code/test/CMakeLists.txt
Expand Up @@ -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)

0 comments on commit c46e42c

Please sign in to comment.