Skip to content

Commit d5f0b89

Browse files
authored
Merge pull request #15 from miccol/installation-rules
Installation rules
2 parents 4b5c517 + ad57a3f commit d5f0b89

File tree

6 files changed

+93
-26
lines changed

6 files changed

+93
-26
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ before_script:
1919
script:
2020
# Build BTpp
2121
- (cd build; cmake .. ;cmake --build . )
22+
#Install BTpp
23+
- (cd build; sudo cmake --build . --target install)
2224

23-
24-

CMakeLists.txt

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.0)
22
project(BTpp)
33

44
set(CMAKE_BUILD_TYPE Release)
5-
add_definitions(-lX11 -Wall -lglut -lGL -lgtest -std=c++11 -pthread -lrt )
5+
add_definitions(-lX11 -Wall -lglut -lGL -lgtest -std=c++11 -lrt )
66
# Needed for using threads
77
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
88

9-
10-
119
#########################################################
1210
# FIND X11
1311
#########################################################
@@ -59,6 +57,20 @@ if(APPLE)
5957
endif()
6058

6159

60+
#########################################################
61+
# Make relative paths absolute (needed later on)
62+
#########################################################
63+
64+
foreach(p LIB BIN INCLUDE CMAKE)
65+
set(var INSTALL_${p}_DIR)
66+
if(NOT IS_ABSOLUTE "${${var}}")
67+
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
68+
endif()
69+
endforeach()
70+
71+
72+
73+
6274
file(GLOB_RECURSE BTHeadLibrary include/*.h)
6375

6476
set(BTSrcLibrary
@@ -92,8 +104,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
92104
# COMPILING GTEST
93105
######################################################
94106
if(GTEST_FOUND)
95-
add_executable(btpp_gtest gtest/gtest_tree.cpp ${BTSrcLibrary} ${BTHeadLibrary})
96-
target_link_libraries(btpp_gtest ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} ${X11_LIBRARIES})
107+
#add_executable(btpp_gtest gtest/gtest_tree.cpp ${BTSrcLibrary} ${BTHeadLibrary})
108+
#target_link_libraries(btpp_gtest ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} ${X11_LIBRARIES})
97109
endif(GTEST_FOUND)
98110

99111
######################################################
@@ -105,27 +117,61 @@ target_link_libraries(btpp_example ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${X11_LI
105117
######################################################
106118
# COMPILING LIBRARY
107119
######################################################
108-
add_library(BTpp STATIC ${BTSrcLibrary} ${BTHeadLibrary})
109-
target_link_libraries(BTpp ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${X11_LIBRARIES})
120+
add_library(BTppLib STATIC ${BTSrcLibrary} ${BTHeadLibrary})
121+
target_link_libraries(BTppLib ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${X11_LIBRARIES})
110122

111123
######################################################
112-
# INSTALLATION OF LIBRARY AND EXECUTABLE TO /usr/local
124+
# INSTALLATION OF LIBRARY AND EXECUTABLE
113125
######################################################
114-
install(TARGETS BTpp
115-
EXPORT btpp-targets
116-
DESTINATION lib/BTpp
117-
)
118126

127+
128+
129+
# Add all targets to the build-tree export set
130+
export(TARGETS BTppLib
131+
FILE "${PROJECT_BINARY_DIR}/BTppTargets.cmake")
132+
133+
# Export the package for use from the build-tree
134+
# (this registers the build-tree with a global CMake-registry)
119135
export(PACKAGE BTpp)
120136

121-
install(EXPORT btpp-targets DESTINATION lib/BTpp)
122137

123-
install(FILES btpp-config.cmake DESTINATION lib/BTpp)
124-
#set(btpp_INCLUDE_DIRS /usr/local/include/BTpp)
125-
#set(btpp_LIBRARY /usr/local/lib/BTpp/libbtpp.a)
126-
#message("the value of btpp_INCLUDE_DIRS: " ${btpp_INCLUDE_DIRS})
127-
#message("the value of btpp_LIBRARY: " ${btpp_LIBRARY})
138+
install(FILES ${BTHeadLibrary} DESTINATION ${INSTALL_INCLUDE_DIR}/include/BTpp)
139+
140+
141+
install(TARGETS BTppLib
142+
# IMPORTANT: Add the library to the "export-set"
143+
EXPORT BTppTargets
144+
ARCHIVE DESTINATION "${INSTALL_CMAKE_DIR}/BTpp/lib"
145+
RUNTIME DESTINATION "${PROJECT_BINARY_DIR}/bin" COMPONENT ${PROJECT_BINARY_DIR}/bin
146+
LIBRARY DESTINATION "${PROJECT_BINARY_DIR}/lib" COMPONENT ${PROJECT_BINARY_DIR}/shlib
147+
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/include/BTpp"
148+
COMPONENT ${INSTALL_CMAKE_DIR}"include/BTpp")
149+
150+
151+
# Create the BTppConfig.cmake and BTppConfigVersion files
152+
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
153+
"${INSTALL_INCLUDE_DIR}")
154+
# ... for the build tree
155+
128156

157+
set(CONF_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}include/BTpp")
158+
configure_file(conf/BTppConfig.cmake.in
159+
"${PROJECT_BINARY_DIR}/BTppConfig.cmake" @ONLY)
129160

161+
# ... for the install tree
162+
#set(CONF_INCLUDE_DIRS "\${BTpp_CMAKE_DIR}/${REL_INCLUDE_DIR}")
163+
configure_file(conf/BTppConfig.cmake.in
164+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/BTppConfig.cmake" @ONLY)
165+
# ... for both
166+
configure_file(conf/BTppConfigVersion.cmake.in
167+
"${PROJECT_BINARY_DIR}/BTppConfigVersion.cmake" @ONLY)
130168

169+
# Install the BTppConfig.cmake and BTppConfigVersion.cmake
170+
install(FILES
171+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/BTppConfig.cmake"
172+
"${PROJECT_BINARY_DIR}/BTppConfigVersion.cmake"
173+
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
131174

175+
# Install the export set for use with the install-tree
176+
install(EXPORT BTppTargets DESTINATION
177+
"${INSTALL_CMAKE_DIR}" COMPONENT dev)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ Check the installation by running a sample example.
8989
`$ cd build/sample` <br/>
9090
`$ ./btpp_example` <br/>
9191

92-
Note that the local installation generates the shared library in `/path/to/folder/build/lib`.
93-
94-
INSTALL THE LIBRARY SYSTEM-WIDE (tested on Ubuntu 14.04 only)
92+
INSTALL THE LIBRARY SYSTEM-WIDE (tested on Ubuntu 14.04 and 16.04)
9593
-------------------------------
9694

9795
If you would like to install the library system-wide, then run:
@@ -100,7 +98,9 @@ If you would like to install the library system-wide, then run:
10098
`$ cd build` <br/>
10199
`$ sudo make install` <br/>
102100

103-
On Ubuntu 14.04, this will install the shared library (libbtpp.so) in `/usr/local/lib`. <br/>
101+
On Ubuntu, this will install the library (libbtpp.so) in `/usr/local/lib`. <br/>
102+
In an external project, just call in your CMakeLists 'find_package(BTpp)' to find the library. <br/>
103+
The include directory is defined as `BTpp_INCLUDE_DIRS` and the libraries to link as `BTpp_LIBRARIES`.<br/>
104104
The repository [my-behavior-tree-project](https://github.com/miccol/my-behavior-tree-project) shows an example on how to use the library once system-wide installed.
105105

106106

conf/BTppConfig.cmake.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
get_filename_component(BTpp_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
2+
set(BTpp_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")
3+
4+
# Our library dependencies (contains definitions for IMPORTED targets)
5+
if(NOT TARGET BTpp AND NOT BTpp_BINARY_DIR)
6+
include("${BTpp_CMAKE_DIR}/BTppTargets.cmake")
7+
endif()
8+
9+
# These are IMPORTED targets created by YARPBTCoreargets.cmake
10+
set(BTpp_LIBRARIES BTppLib)

conf/BTppConfigVersion.cmake.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(PACKAGE_VERSION "@BTpp_VERSION@")
2+
3+
# Check whether the requested PACKAGE_FIND_VERSION is compatible
4+
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
5+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
6+
else()
7+
set(PACKAGE_VERSION_COMPATIBLE TRUE)
8+
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
9+
set(PACKAGE_VERSION_EXACT TRUE)
10+
endif()
11+
endif()

include/tree_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141

4242
#include <iostream>
43-
#include <unistd.h>
43+
//#include <unistd.h>
4444

4545
#include <string>
4646

0 commit comments

Comments
 (0)