libppd: update to 2.1.0
[oi-userland.git] / make-rules / cmake.mk
blob7fbb0346ed7fc5396098d7361526c992c4c0d537
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
21 # Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
22 # Copyright 2011 EveryCity Ltd. All rights reserved.
23 # Copyright 2013 Aurelien Larcher. All rights reserved.
27 # Rules and Macros for building open source software that uses the CMake utility
28 # from Kitware (http://www.cmake.org) to configure the build.
29 # This file implements the same rules as configure.mk and thus uses GNU Make
30 # to build the components with support of multiple version (32/64 bit).
32 # To use these rules, include ../make-rules/cmake.mk in your Makefile
33 # and define "build", "install", and "test" targets appropriate to building
34 # your component.
35 # Ex:
37 # build: $(SOURCE_DIR)/build/$(MACH32)/.built \
38 # $(SOURCE_DIR)/build/$(MACH64)/.built
40 # install: $(SOURCE_DIR)/build/$(MACH32)/.installed \
41 # $(SOURCE_DIR)/build/$(MACH64)/.installed
43 # test: $(SOURCE_DIR)/build/$(MACH32)/.tested \
44 # $(SOURCE_DIR)/build/$(MACH64)/.tested
46 # Any additional pre/post configure, build, or install actions can be specified
47 # in your make file by setting them in on of the following macros:
48 # COMPONENT_PRE_CMAKE_ACTION, COMPONENT_POST_CMAKE_ACTION
49 # COMPONENT_PRE_BUILD_ACTION, COMPONENT_POST_BUILD_ACTION
50 # COMPONENT_PRE_INSTALL_ACTION, COMPONENT_POST_INSTALL_ACTION
51 # COMPONENT_PRE_TEST_ACTION, COMPONENT_POST_TEST_ACTION
53 # If component specific make targets need to be used for build or install, they
54 # can be specified in
55 # COMPONENT_BUILD_TARGETS, COMPONENT_INSTALL_TARGETS
56 # COMPONENT_TEST_TARGETS
59 CMAKE_PREFIX = /usr
62 # Define path the same way as configure.mk
63 # Ref: http://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:GNUInstallDirs
66 ifeq ($(strip $(PREFERRED_BITS)),64)
67 CMAKE_BINDIR.32 = bin/$(MACH32)
68 CMAKE_BINDIR.64 = bin
69 CMAKE_SBINDIR.32 = sbin/$(MACH32)
70 CMAKE_SBINDIR.64 = sbin
71 else
72 CMAKE_BINDIR.32 = bin
73 CMAKE_BINDIR.64 = bin/$(MACH64)
74 CMAKE_SBINDIR.32 = sbin
75 CMAKE_SBINDIR.64 = sbin/$(MACH64)
76 endif
77 CMAKE_LIBDIR.32 = lib
78 CMAKE_LIBDIR.64 = lib/$(MACH64)
79 # If the component prefers 64-bit binaries, then ensure builds deliver 64-bit
80 # binaries to the standard directories and 32-bit binaries to the non-standard
81 # location. This allows simplification of package manifests and makes it
82 # easier to deliver the 64-bit binaries as the default.
83 ifeq ($(strip $(PREFERRED_BITS)),64)
84 CMAKE_LIBEXECDIR.32 = libexec/$(MACH32)
85 CMAKE_LIBEXECDIR.64 = libexec
86 else
87 CMAKE_LIBEXECDIR.32 = libexec
88 CMAKE_LIBEXECDIR.64 = libexec/$(MACH64)
89 endif
90 CMAKE_INCLUDEDIR = include
91 CMAKE_DATAROOTDIR = share
92 CMAKE_DATADIR = $(CMAKE_DATAROOTDIR)
93 CMAKE_INFODIR = $(CMAKE_DATAROOTDIR)/info
94 CMAKE_LOCALEDIR = $(CMAKE_DATAROOTDIR)/locale
95 CMAKE_MANDIR = $(CMAKE_DATAROOTDIR)/man
96 CMAKE_DOCDIR = $(CMAKE_DATAROOTDIR)/doc
98 CMAKE_ENV = CONFIG_SHELL="$(CONFIG_SHELL)"
99 CMAKE_ENV += CC="$(CC)"
100 CMAKE_ENV += CXX="$(CXX)"
101 CMAKE_ENV += F77="$(F77)"
102 CMAKE_ENV += FC="$(FC)"
103 CMAKE_ENV += CFLAGS="$(CFLAGS)"
104 CMAKE_ENV += CXXFLAGS="$(CXXFLAGS)"
105 CMAKE_ENV += FFLAGS="$(F77FLAGS)"
106 CMAKE_ENV += FCFLAGS="$(FCFLAGS)"
107 CMAKE_ENV += LDFLAGS="$(LDFLAGS)"
108 CMAKE_ENV += PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"
109 CMAKE_ENV += PATH="$(PATH)"
111 # Rewrite absolute source-code paths into relative for ccache, so that any
112 # workspace with a shared CCACHE_DIR can benefit when compiling a component
113 ifneq ($(strip $(CCACHE)),)
114 CMAKE_ENV += CCACHE="$(CCACHE)"
115 CMAKE_ENV += CC_gcc_32="$(CC_gcc_32)"
116 CMAKE_ENV += CC_gcc_64="$(CC_gcc_32)"
117 CMAKE_ENV += CXX_gcc_32="$(CXX_gcc_64)"
118 CMAKE_ENV += CXX_gcc_64="$(CXX_gcc_64)"
119 CMAKE_ENV.$(BITS) += CCACHE_BASEDIR="$(BUILD_DIR_$(BITS))"
121 ifneq ($(strip $(CCACHE_DIR)),)
122 CMAKE_ENV += CCACHE_DIR="$(CCACHE_DIR)"
123 endif
125 ifneq ($(strip $(CCACHE_LOGFILE)),)
126 CMAKE_ENV += CCACHE_LOGFILE="$(CCACHE_LOGFILE)"
127 endif
129 endif
131 CMAKE_DEFAULT_DIRS?=yes
133 CMAKE_OPTIONS += -DCMAKE_C_COMPILER:STRING="$(CC)"
134 CMAKE_OPTIONS += -DCMAKE_CXX_COMPILER:STRING="$(CXX)"
135 CMAKE_OPTIONS += -DCMAKE_Fortran_COMPILER:STRING="$(FC)"
136 CMAKE_OPTIONS += -DCMAKE_C_FLAGS:STRING="$(CFLAGS)"
137 CMAKE_OPTIONS += -DCMAKE_CXX_FLAGS:STRING="$(CXXFLAGS)"
138 CMAKE_OPTIONS += -DCMAKE_Fortran_FLAGS:STRING="$(FCFLAGS)"
140 CMAKE_OPTIONS += -DCMAKE_INSTALL_PREFIX:PATH=$(CMAKE_PREFIX)
141 ifeq ($(CMAKE_DEFAULT_DIRS),yes)
142 CMAKE_OPTIONS += -DCMAKE_INSTALL_BINDIR:PATH=$(CMAKE_BINDIR.$(BITS))
143 CMAKE_OPTIONS += -DCMAKE_INSTALL_LIBDIR:PATH=$(CMAKE_LIBDIR.$(BITS))
144 CMAKE_OPTIONS += -DCMAKE_INSTALL_SBINDIR:PATH=$(CMAKE_SBINDIR.$(BITS))
145 CMAKE_OPTIONS += -DCMAKE_INSTALL_DATAROOTDIR:PATH=$(CMAKE_DATAROOTDIR)
146 CMAKE_OPTIONS += -DCMAKE_INSTALL_DATADIR:PATH=$(CMAKE_DATAROOTDIR)
147 CMAKE_OPTIONS += -DCMAKE_INSTALL_INFODIR:PATH=$(CMAKE_INFODIR)
148 CMAKE_OPTIONS += -DCMAKE_INSTALL_LOCALEDIR:PATH=$(CMAKE_LOCALEDIR)
149 CMAKE_OPTIONS += -DCMAKE_INSTALL_MANDIR:PATH=$(CMAKE_MANDIR)
151 CMAKE_OPTIONS += -DLIBEXEC_INSTALL_DIR="$(CMAKE_PREFIX)/$(CMAKE_LIBEXECDIR.$(BITS))"
153 # Some components use LIB_INSTALL_DIR or CMAKE_INSTALL_LIBDIR, as-is,
154 # others forcibly ignore it and set
155 # based on CMAKE_INSTALL_PREFIX. Those usually instead offer a LIB_SUFFIX
156 # variable that we can generally use to accomplish the same result. Setting
157 # them both shouldn't harm anything.
158 CMAKE_OPTIONS += -DLIB_INSTALL_DIR="$(CMAKE_PREFIX)/$(CMAKE_LIBDIR.$(BITS))"
159 CMAKE_OPTIONS.64 += -DCMAKE_LIBRARY_ARCHITECTURE=$(MACH64)
160 CMAKE_OPTIONS.64 += -DLIB_SUFFIX="/$(MACH64)"
161 endif
162 CMAKE_OPTIONS += $(CMAKE_OPTIONS.$(BITS))
164 COMPONENT_INSTALL_ENV += DESTDIR=$(PROTO_DIR)
166 $(BUILD_DIR_32)/.configured: BITS=32
167 $(BUILD_DIR_64)/.configured: BITS=64
169 CMAKE_ENV += $(CMAKE_ENV.$(BITS))
171 COMPONENT_TEST_CMD=ctest
172 COMPONENT_TEST_TARGETS=
174 # configure the unpacked source for building 32 and 64 bit version
175 CMAKE = cmake
177 # provide test transforms for ctest
178 CMAKE_TEST_TRANSFORMS = \
179 ' -e "s/[0-9]*\.[0-9]* sec//" ' \
180 ' -n ' \
181 ' -e "/Not Run/p" ' \
182 ' -e "/Start/p" ' \
183 ' -e "/Skipped/p" ' \
184 ' -e "/Failed/p" ' \
185 ' -e "/Passed/p" ' \
186 ' -e "/failed/p" '
188 USE_DEFAULT_TEST_TRANSFORMS?=no
189 ifeq ($(strip $(USE_DEFAULT_TEST_TRANSFORMS)),yes)
190 COMPONENT_TEST_TRANSFORMS += $(CMAKE_TEST_TRANSFORMS)
191 endif
193 $(BUILD_DIR)/%/.configured: $(SOURCE_DIR)/.prep
194 ($(RM) -rf $(@D) ; $(MKDIR) $(@D))
195 $(COMPONENT_PRE_CMAKE_ACTION)
196 (cd $(@D) ; $(ENV) $(CMAKE_ENV) \
197 $(CMAKE) $(CMAKE_OPTIONS) $(SOURCE_DIR))
198 $(COMPONENT_POST_CMAKE_ACTION)
199 $(TOUCH) $@
201 # build the configured source
202 $(BUILD_DIR)/%/.built: $(BUILD_DIR)/%/.configured
203 $(COMPONENT_PRE_BUILD_ACTION)
204 (cd $(@D) ; $(ENV) $(COMPONENT_BUILD_ENV) \
205 $(CMAKE) --build . \
206 $(COMPONENT_BUILD_CMAKE_ARGS) $(COMPONENT_BUILD_ARGS)) \
207 $(COMPONENT_POST_BUILD_ACTION)
208 $(TOUCH) $@
210 # install the built source into a prototype area
211 $(BUILD_DIR)/%/.installed: $(BUILD_DIR)/%/.built
212 $(COMPONENT_PRE_INSTALL_ACTION)
213 (cd $(@D) ; $(if $(strip $(CMAKE_COMPONENTS)), \
214 $(CMAKE_COMPONENTS:%=$(ENV) $(COMPONENT_INSTALL_ENV) \
215 $(CMAKE) --install . --component % $(COMPONENT_INSTALL_ARGS) ;) \
217 $(ENV) $(COMPONENT_INSTALL_ENV) \
218 $(CMAKE) --install . $(COMPONENT_INSTALL_ARGS) \
220 $(COMPONENT_POST_INSTALL_ACTION)
221 $(TOUCH) $@
223 # test the built source
224 $(BUILD_DIR)/%/.tested-and-compared: $(COMPONENT_TEST_DEP)
225 $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
226 $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
227 $(COMPONENT_PRE_TEST_ACTION)
228 -(cd $(COMPONENT_TEST_DIR) ; \
229 $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
230 $(COMPONENT_TEST_CMD) \
231 $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
232 &> $(COMPONENT_TEST_OUTPUT)
233 $(COMPONENT_POST_TEST_ACTION)
234 $(COMPONENT_TEST_CREATE_TRANSFORMS)
235 $(COMPONENT_TEST_PERFORM_TRANSFORM)
236 $(COMPONENT_TEST_COMPARE)
237 $(COMPONENT_TEST_CLEANUP)
238 $(TOUCH) $@
240 $(BUILD_DIR)/%/.tested: SHELLOPTS=pipefail
241 $(BUILD_DIR)/%/.tested: $(COMPONENT_TEST_DEP)
242 $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
243 $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
244 $(COMPONENT_PRE_TEST_ACTION)
245 (cd $(COMPONENT_TEST_DIR) ; \
246 $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
247 $(COMPONENT_TEST_CMD) \
248 $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
249 |& $(TEE) $(COMPONENT_TEST_OUTPUT)
250 $(COMPONENT_POST_TEST_ACTION)
251 $(COMPONENT_TEST_CREATE_TRANSFORMS)
252 $(COMPONENT_TEST_PERFORM_TRANSFORM)
253 $(COMPONENT_TEST_CLEANUP)
254 $(TOUCH) $@
256 clean::
257 $(RM) -r $(BUILD_DIR) $(PROTO_DIR)