Skip to content

Commit c46e42c

Browse files
FirstLoveLifesolodon4
authored andcommitted
add cmake installation support (#82)
Adds cmake installation support
1 parent c77d6f6 commit c46e42c

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Version 3.2 is needed to be able to have support of target_compile_features for AppleClang
2+
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
3+
4+
# 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.
5+
project(Mach7)
6+
7+
# Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.txt and code files are located.
8+
project(Mach7)
9+
10+
add_subdirectory(code/test)
11+
12+
# Define the library target
13+
add_library(Mach7 INTERFACE)
14+
add_library(Mach7::Mach7 ALIAS Mach7)
15+
16+
install(TARGETS Mach7
17+
EXPORT Mach7Targets
18+
LIBRARY DESTINATION lib COMPONENT Runtime
19+
ARCHIVE DESTINATION lib COMPONENT Development
20+
RUNTIME DESTINATION bin COMPONENT Runtime
21+
PUBLIC_HEADER DESTINATION include COMPONENT Development
22+
BUNDLE DESTINATION bin COMPONENT Runtime
23+
)
24+
25+
include(CMakePackageConfigHelpers)
26+
configure_package_config_file(
27+
"${PROJECT_SOURCE_DIR}/cmake/Mach7Config.cmake.in"
28+
"${PROJECT_BINARY_DIR}/Mach7Config.cmake"
29+
INSTALL_DESTINATION lib/cmake/Mach7
30+
)
31+
32+
install(EXPORT Mach7Targets DESTINATION lib/cmake/Mach7)
33+
install(FILES
34+
"${PROJECT_BINARY_DIR}/Mach7Config.cmake"
35+
DESTINATION lib/cmake/Mach7)
36+
37+
38+
# for linux: copy header files to /usr/local/ by default
39+
# for windows: copy header fiels to c:/Program Files by default
40+
install(
41+
DIRECTORY ${CMAKE_SOURCE_DIR}/code/mach7/
42+
DESTINATION include/mach7)
43+
install(
44+
DIRECTORY ${CMAKE_SOURCE_DIR}/code/xtl/
45+
DESTINATION include/xtl)
46+
install(
47+
DIRECTORY ${CMAKE_SOURCE_DIR}/code/cppft/
48+
DESTINATION include/cppft)

README.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,20 @@ on the library were built with.
161161
[CMake](https://cmake.org/) support is the most recent and is still very experimental at this point. To
162162
build with cmake, perform the following commands from within Mach7 folder:
163163
164-
cd code/test
165-
mkdir build
166-
cd build
167-
cmake ..
168-
cmake --build .
169-
170-
Version 3.2 is needed in order to be able to have support of target_compile_features for AppleClang
164+
cmake -H. -Bbuild
165+
cmake --build build --target install
166+
167+
Note: this requires administrative privileges under all systems, if you don't like this, try commands below:
168+
169+
cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX=/wherever/doesn't/require/administrative/priviege
170+
cmake --build build --target install
171+
172+
But please make sure msvc/clang/gcc is able to find the path your provide above when
173+
including Mach7's headers in your own project:
174+
175+
- MSVC: https://stackoverflow.com/questions/335408/where-does-visual-studio-look-for-c-header-files
176+
- Gcc/Clang: -I
177+
- CMake: https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake
171178
172179
#### Using Makefiles for GCC (4.4 or later) or Clang (3.3 or later)
173180

cmake/Mach7Config.cmake.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://stackoverflow.com/questions/47718485/install-and-export-interface-only-library-cmake
2+
@PACKAGE_INIT@
3+
4+
include("${CMAKE_CURRENT_LIST_DIR}/Mach7Targets.cmake")
5+
check_required_components("@PROJECT_NAME@")

code/test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
77
# Add preprocessor definition to disable internal XTL messages
88
add_definitions(-DXTL_MESSAGE_ENABLED=0)
99

10+
# 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.
1011
project(Tests)
1112

13+
# Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.txt and code files are located.
1214
add_subdirectory(unit)
1315
add_subdirectory(time)

0 commit comments

Comments
 (0)