-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageBuilder.cmake
More file actions
156 lines (130 loc) · 7.11 KB
/
Copy pathPackageBuilder.cmake
File metadata and controls
156 lines (130 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# PackageBuilder.cmake
# Author: Noah Oblath
# Parts of this script are based on work done by Sebastian Voecking and Marco Haag in the Kasper package
# Convenient macros and default variable settings for the Katydid build.
#
# Requires: CMake v3.0 or better (rpath treatment and version variables)
# CMake policies
cmake_policy( SET CMP0011 NEW )
cmake_policy( SET CMP0012 NEW ) # how if-statements work
cmake_policy( SET CMP0042 NEW ) # rpath on mac os x
cmake_policy( SET CMP0048 NEW ) # version in project()
# check if this is a stand-alone build
set( PBUILDER_STANDALONE FALSE CACHE INTERNAL "Flag for whether or not this is a stand-alone build" )
if( ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
set( PBUILDER_STANDALONE TRUE )
endif( ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
# preprocessor defintion for debug build
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
add_definitions(-D${PROJECT_NAME}_DEBUG)
else ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
remove_definitions(-D${PROJECT_NAME}_DEBUG)
endif ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
# Setup the default install prefix
# This gets set to the binary directory upon first configuring.
# If the user changes the prefix, but leaves the flag OFF, then it will remain as the user specified.
# If the user wants to reset the prefix to the default (i.e. the binary directory), then the flag should be set ON.
if (NOT DEFINED SET_INSTALL_PREFIX_TO_DEFAULT)
set (SET_INSTALL_PREFIX_TO_DEFAULT ON)
endif (NOT DEFINED SET_INSTALL_PREFIX_TO_DEFAULT)
if (SET_INSTALL_PREFIX_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR} CACHE PATH "Install prefix" FORCE)
set (SET_INSTALL_PREFIX_TO_DEFAULT OFF CACHE BOOL "Reset default install path when when configuring" FORCE)
endif (SET_INSTALL_PREFIX_TO_DEFAULT)
# install subdirectories
set (INCLUDE_INSTALL_SUBDIR "include" CACHE PATH "Install subdirectory for headers")
if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
set (LIB_INSTALL_SUBDIR "bin" CACHE PATH "Install subdirectory for libraries")
else( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
set (LIB_INSTALL_SUBDIR "lib" CACHE PATH "Install subdirectory for libraries")
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
set (BIN_INSTALL_SUBDIR "bin" CACHE PATH "Install subdirectory for binaries")
set (CONFIG_INSTALL_SUBDIR "config" CACHE PATH "Install subdirectory for config files")
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_SUBDIR}")
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_SUBDIR}")
set (BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_SUBDIR}")
set (CONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_SUBDIR}")
# build shared libraries
set (BUILD_SHARED_LIBS ON)
# global property to hold the names of katydid library targets
set_property (GLOBAL PROPERTY ${PROJECT_NAME}_LIBRARIES)
# turn on RPATH for Mac OSX
set (CMAKE_MACOSX_RPATH ON)
# add the library install directory to the rpath
SET(CMAKE_INSTALL_RPATH "${LIB_INSTALL_DIR}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
##########
# MACROS #
##########
# This should be called immediately after setting the project name
macro (pbuilder_prepare_project)
# define the variables to describe the package (will go in the KatydidConfig.hh file)
set (${PROJECT_NAME}_PACKAGE_NAME "${PROJECT_NAME}")
set (${PROJECT_NAME}_PACKAGE_STRING "${PROJECT_NAME} ${${PROJECT_NAME}_VERSION}")
# Configuration header file
if (EXISTS ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.hh.in)
configure_file (
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.hh.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.hh
)
# Add the binary tree to the search path for include files so that the config file is found during the build
include_directories (${PROJECT_BINARY_DIR})
endif (EXISTS ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.hh.in)
endmacro ()
macro (pbuilder_add_ext_libraries)
list (APPEND EXTERNAL_LIBRARIES ${ARGN})
endmacro ()
macro (pbuilder_add_submodule_libraries)
list (APPEND EXTERNAL_LIBRARIES ${ARGN})
list (APPEND SUBMODULE_LIBRARIES ${ARGN})
endmacro ()
macro (pbuilder_install_libraries)
install (TARGETS ${ARGN} EXPORT ${PROJECT_NAME}Targets DESTINATION ${LIB_INSTALL_DIR})
#list (APPEND ${PROJECT_NAME}_LIBRARIES ${ARGN})
set_property (GLOBAL APPEND PROPERTY ${PROJECT_NAME}_LIBRARIES ${ARGN})
set_target_properties (${ARGN} PROPERTIES INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
endmacro ()
macro (pbuilder_install_executables)
install(TARGETS ${ARGN} EXPORT ${PROJECT_NAME}Targets DESTINATION ${BIN_INSTALL_DIR})
endmacro ()
macro (pbuilder_install_headers)
install(FILES ${ARGN} DESTINATION ${INCLUDE_INSTALL_DIR})
endmacro ()
macro (pbuilder_install_header_dirs FILE_PATTERN)
install(DIRECTORY ${ARGN} DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "${FILE_PATTERN}")
endmacro ()
macro (pbuilder_install_config)
install(FILES ${ARGN} DESTINATION ${CONFIG_INSTALL_DIR})
endmacro ()
macro (pbuilder_install_files DEST_DIR)
install(FILES ${ARGN} DESTINATION ${DEST_DIR})
endmacro ()
# This should be called AFTER all subdirectories with libraries have been called, and all include directories added.
macro (pbuilder_install_config_files)
# Configuration header file
if (EXISTS ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.hh)
# Install location for the configuration header
pbuilder_install_headers (${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.hh)
endif (EXISTS ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.hh)
# CMake configuration file
get_property(${PROJECT_NAME}_LIBRARIES GLOBAL PROPERTY ${PROJECT_NAME}_LIBRARIES)
if (EXISTS ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in)
# the awkwardness of the following four lines is because for some reason cmake wouldn't just go from .cmake.tmp to .cmake when I tested it.
configure_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}Config.cmake.tmp @ONLY)
configure_file(${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}Config.cmake.tmp ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}Config.cmake.ppp @ONLY)
file (REMOVE ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}Config.cmake.tmp)
file (RENAME ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}Config.cmake.ppp ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}Config.cmake)
endif (EXISTS ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in)
endmacro ()
macro (pbuilder_variables_for_parent)
if (NOT ${PBUILDER_STANDALONE})
get_property (LIBRARIES GLOBAL PROPERTY ${PROJECT_NAME}_LIBRARIES)
set (${PROJECT_NAME}_LIBRARIES ${LIBRARIES} ${SUBMODULE_LIBRARIES} PARENT_SCOPE)
set (${PROJECT_NAME}_LIBRARY_DIR ${LIB_INSTALL_DIR} PARENT_SCOPE)
set (${PROJECT_NAME}_INCLUDE_DIR ${INCLUDE_INSTALL_DIR} PARENT_SCOPE)
get_property (DEP_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
set (${PROJECT_NAME}_DEP_INCLUDE_DIRS ${DEP_INCLUDE_DIRS} PARENT_SCOPE)
endif (NOT ${PBUILDER_STANDALONE})
endmacro ()