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]
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
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
55 # COMPONENT_BUILD_TARGETS, COMPONENT_INSTALL_TARGETS
56 # COMPONENT_TEST_TARGETS
62 # Define path the same way as configure.mk
63 # Ref: http://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:GNUInstallDirs
67 CMAKE_BINDIR
.64 = bin
/$(MACH64
)
68 CMAKE_SBINDIR
.32 = sbin
69 CMAKE_SBINDIR
.64 = sbin
/$(MACH64
)
71 CMAKE_LIBDIR
.64 = lib
/$(MACH64
)
72 CMAKE_INCLUDEDIR
= include
73 CMAKE_DATAROOTDIR
= share
74 CMAKE_INFODIR
= share
/info
75 CMAKE_LOCALEDIR
= share
/locale
76 CMAKE_MANDIR
= share
/man
78 CMAKE_ENV
= CONFIG_SHELL
="$(CONFIG_SHELL)"
79 CMAKE_ENV
+= CC
="$(CC)"
80 CMAKE_ENV
+= CXX
="$(CXX)"
81 CMAKE_ENV
+= F77
="$(F77)"
82 CMAKE_ENV
+= FC
="$(FC)"
83 CMAKE_ENV
+= CFLAGS
="$(CFLAGS)"
84 CMAKE_ENV
+= CXXFLAGS
="$(CXXFLAGS)"
85 CMAKE_ENV
+= FFLAGS
="$(F77FLAGS)"
86 CMAKE_ENV
+= FCFLAGS
="$(FCFLAGS)"
87 CMAKE_ENV
+= LDFLAGS
="$(LDFLAGS)"
88 CMAKE_ENV
+= PKG_CONFIG_PATH
="$(PKG_CONFIG_PATH)"
90 # Rewrite absolute source-code paths into relative for ccache, so that any
91 # workspace with a shared CCACHE_DIR can benefit when compiling a component
92 ifneq ($(strip $(CCACHE
)),)
93 CMAKE_ENV
+= CCACHE
="$(CCACHE)"
94 CMAKE_ENV
+= CC_gcc_32
="$(CC_gcc_32)"
95 CMAKE_ENV
+= CC_gcc_64
="$(CC_gcc_32)"
96 CMAKE_ENV
+= CXX_gcc_32
="$(CXX_gcc_64)"
97 CMAKE_ENV
+= CXX_gcc_64
="$(CXX_gcc_64)"
98 CMAKE_ENV.
$(BITS
) += CCACHE_BASEDIR
="$(BUILD_DIR_$(BITS))"
100 ifneq ($(strip $(CCACHE_DIR
)),)
101 CMAKE_ENV
+= CCACHE_DIR
="$(CCACHE_DIR)"
104 ifneq ($(strip $(CCACHE_LOGFILE
)),)
105 CMAKE_ENV
+= CCACHE_LOGFILE
="$(CCACHE_LOGFILE)"
110 CMAKE_DEFAULT_DIRS?
=yes
112 CMAKE_OPTIONS
+= -DCMAKE_C_COMPILER
:STRING
="$(CC)"
113 CMAKE_OPTIONS
+= -DCMAKE_CXX_COMPILER
:STRING
="$(CXX)"
114 CMAKE_OPTIONS
+= -DCMAKE_Fortran_COMPILER
:STRING
="$(FC)"
115 CMAKE_OPTIONS
+= -DCMAKE_C_FLAGS
:STRING
="$(CFLAGS)"
116 CMAKE_OPTIONS
+= -DCMAKE_CXX_FLAGS
:STRING
="$(CXXFLAGS)"
117 CMAKE_OPTIONS
+= -DCMAKE_Fortran_FLAGS
:STRING
="$(FCFLAGS)"
119 CMAKE_OPTIONS
+= LDFLAGS
="$(LDFLAGS)"
120 CMAKE_OPTIONS
+= PKG_CONFIG_PATH
="$(PKG_CONFIG_PATH)"
122 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_PREFIX
:PATH
=$(CMAKE_PREFIX
)
123 ifeq ($(CMAKE_DEFAULT_DIRS
),yes
)
124 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_BINDIR
:PATH
=$(CMAKE_BINDIR.
$(BITS
))
125 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_SBINDIR
:PATH
=$(CMAKE_SBINDIR.
$(BITS
))
126 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_LIBDIR
:PATH
=$(CMAKE_LIBDIR.
$(BITS
))
127 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_DATAROOTDIR
:PATH
=$(CMAKE_DATAROOTDIR
)
128 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_DATADIR
:PATH
=$(CMAKE_DATAROOTDIR
)
129 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_INFODIR
:PATH
=$(CMAKE_INFODIR
)
130 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_LOCALEDIR
:PATH
=$(CMAKE_LOCALEDIR
)
131 CMAKE_OPTIONS
+= -DCMAKE_INSTALL_MANDIR
:PATH
=$(CMAKE_MANDIR
)
133 CMAKE_OPTIONS
+= $(CMAKE_OPTIONS.
$(BITS
))
135 COMPONENT_INSTALL_ARGS
+= DESTDIR
=$(PROTO_DIR
)
137 $(BUILD_DIR_32
)/.configured
: BITS
=32
138 $(BUILD_DIR_64
)/.configured
: BITS
=64
140 CMAKE_ENV
+= $(CMAKE_ENV.
$(BITS
))
142 # configure the unpacked source for building 32 and 64 bit version
144 $(BUILD_DIR
)/%/.configured
: $(SOURCE_DIR
)/.prep
145 ($(RM
) -rf
$(@D
) ; $(MKDIR
) $(@D
))
146 $(COMPONENT_PRE_CMAKE_ACTION
)
147 (cd
$(@D
) ; $(ENV
) $(CMAKE_ENV
) \
148 $(CMAKE
) $(CMAKE_OPTIONS
) $(SOURCE_DIR
))
149 $(COMPONENT_POST_CMAKE_ACTION
)
152 # build the configured source
153 $(BUILD_DIR
)/%/.built
: $(BUILD_DIR
)/%/.configured
154 $(COMPONENT_PRE_BUILD_ACTION
)
155 (cd
$(@D
) ; $(ENV
) $(COMPONENT_BUILD_ENV
) \
156 $(GMAKE
) $(COMPONENT_BUILD_GMAKE_ARGS
) $(COMPONENT_BUILD_ARGS
) \
157 $(COMPONENT_BUILD_TARGETS
))
158 $(COMPONENT_POST_BUILD_ACTION
)
159 ifeq ($(strip $(PARFAIT_BUILD
)),yes
)
164 # install the built source into a prototype area
165 $(BUILD_DIR
)/%/.installed
: $(BUILD_DIR
)/%/.built
166 $(COMPONENT_PRE_INSTALL_ACTION
)
167 (cd
$(@D
) ; $(ENV
) $(COMPONENT_INSTALL_ENV
) $(GMAKE
) \
168 $(COMPONENT_INSTALL_ARGS
) $(COMPONENT_INSTALL_TARGETS
))
169 $(COMPONENT_POST_INSTALL_ACTION
)
172 # test the built source
173 $(BUILD_DIR
)/%/.tested-and-compared
: $(BUILD_DIR
)/%/.built
174 $(RM
) -rf
$(COMPONENT_TEST_BUILD_DIR
)
175 $(MKDIR
) $(COMPONENT_TEST_BUILD_DIR
)
176 $(COMPONENT_PRE_TEST_ACTION
)
177 -(cd
$(COMPONENT_TEST_DIR
) ; \
178 $(COMPONENT_TEST_ENV_CMD
) $(COMPONENT_TEST_ENV
) \
179 $(COMPONENT_TEST_CMD
) \
180 $(COMPONENT_TEST_ARGS
) $(COMPONENT_TEST_TARGETS
)) \
181 &> $(COMPONENT_TEST_OUTPUT
)
182 $(COMPONENT_POST_TEST_ACTION
)
183 $(COMPONENT_TEST_CREATE_TRANSFORMS
)
184 $(COMPONENT_TEST_PERFORM_TRANSFORM
)
185 $(COMPONENT_TEST_COMPARE
)
186 $(COMPONENT_TEST_CLEANUP
)
189 $(BUILD_DIR
)/%/.tested
: $(BUILD_DIR
)/%/.built
190 $(COMPONENT_PRE_TEST_ACTION
)
191 (cd
$(COMPONENT_TEST_DIR
) ; \
192 $(COMPONENT_TEST_ENV_CMD
) $(COMPONENT_TEST_ENV
) \
193 $(COMPONENT_TEST_CMD
) \
194 $(COMPONENT_TEST_ARGS
) $(COMPONENT_TEST_TARGETS
))
195 $(COMPONENT_POST_TEST_ACTION
)
196 $(COMPONENT_TEST_CLEANUP
)
199 ifeq ($(strip $(PARFAIT_BUILD
)),yes
)
204 $(MAKE
) PARFAIT_BUILD
=yes parfait
208 $(RM
) -r
$(BUILD_DIR
) $(PROTO_DIR
)