summaryrefslogtreecommitdiff
path: root/cmake/Jamfile
blob: 3f5bf61a525276aca83daded994cb98499ab5674 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#
# CMake configuration support for stage/install
#
# Copyright 2017 Peter Dimov
#
# Distributed under the Boost Software License, 1.0
#

import print ;
import option ;
import os ;
import path ;
import boostcpp ;
import modules ;
import property-set ;
import "class" : new ;
import feature ;
import toolset ;
import regex ;
import common ;

if "--debug-cmake" in [ modules.peek : ARGV ]
{
    .info-enabled = 1 ;
}

local rule .info ( messages * )
{
    if $(.info-enabled)
    {
        ECHO info: $(messages) ;
    }
}

#

local BOOST_STAGE_LOCATE = [ option.get stagedir : ../stage ] ;
.info BOOST_STAGE_LOCATE is $(BOOST_STAGE_LOCATE) ;

local BOOST_VERSION_TAG = [ modules.peek boostcpp : BOOST_VERSION_TAG ] ;
.info BOOST_VERSION_TAG is $(BOOST_VERSION_TAG) ;

# layout

local layout = [ modules.peek boostcpp : layout ] ;
.info layout is $(layout) ;

# prefix

local default-prefix = "" ;

if [ os.name ] = NT
{
    default-prefix = C:/Boost ;
}
else
{
    default-prefix = /usr/local ;
}

.info default-prefix is $(default-prefix) ;

local prefix = [ option.get prefix : $(default-prefix) ] ;
.info prefix is $(prefix) ;

# header-subdir

header-subdir = "" ;

if $(layout) = versioned
{
    header-subdir = /boost-$(BOOST_VERSION_TAG) ;
}

.info header-subdir is $(header-subdir) ;

# libdir

local libdir = [ option.get libdir : $(prefix)/lib ] ;
.info libdir is $(libdir) ;

# generate-config

local rule generate-config ( target type )
{
    .info generate-config $(target) :: $(type) ;

    local name = [ MATCH boost_(.*)-config.cmake : $(target) ] ;

    .info generate-config: name is $(name) ;

    local cmake-lib = boost_$(name) ;
    local cmake-target = boost::$(name) ;

    print.output $(target) ;

    print.text

        "# Generated by Boost $(BOOST_VERSION)"
        ""
        "cmake_minimum_required(VERSION 3.5)"
        ""
        "if(TARGET $(cmake-target))"
        "  return()"
        "endif()"
        ""
        "# Compute the installation prefix relative to this file."
        "get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)"
        "get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)"
        "get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)"
        "get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)"
        ""
        "# Create imported target $(cmake-target)"
        "add_library($(cmake-target) $(type) IMPORTED)"
        ""
        "set_target_properties($(cmake-target) PROPERTIES"
        "  INTERFACE_INCLUDE_DIRECTORIES \"\${_IMPORT_PREFIX}/include$(header-subdir)\""
        ")"
        ""
        "get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)"
        ""
        "include(${_DIR}/../BoostDetectToolset-$(BOOST_VERSION).cmake)"
        ""
        "file(GLOB CONFIG_FILES "${_DIR}/libboost_$(name)-config-variant*.cmake")"
        "foreach(f ${CONFIG_FILES})"
        "  include(${f})"
        "endforeach()"
        ""
        "set(CONFIG_FILES)"
        "set(_DIR)"
        "set(_IMPORT_PREFIX)"
        ""
        "include(CMakeFindDependencyMacro)"
        "function(boost_declare_dependency package type target)"
        "  find_dependency(${package} $(BOOST_VERSION) EXACT)"
        "  set_property(TARGET boost::$(name) APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${target})"
        "endfunction()"
        "include(\${CMAKE_CURRENT_LIST_DIR}/$(cmake-lib)-dependencies.cmake)"
        ""
        : true ;
}

rule generate-header-config ( target : sources * : properties * )
{
    generate-config $(target) INTERFACE ;
}

rule generate-static-config ( target : sources * : properties * )
{
    generate-config $(target) UNKNOWN ;
}

# generate-config-version

rule generate-config-version ( target : sources * : properties * )
{
    .info generate-config-version $(target) ;

    local name = [ MATCH boost_(.*)-config-version.cmake : $(target) ] ;

    .info generate-config-version: name is $(name) ;

    print.output $(target) ;

    print.text

        "# Generated by Boost $(BOOST_VERSION)"
        ""
        "set(PACKAGE_VERSION $(BOOST_VERSION))"
        ""
        "if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)"
        "  set(PACKAGE_VERSION_COMPATIBLE FALSE)"
        "else()"
        "  set(PACKAGE_VERSION_COMPATIBLE TRUE)"
        "  if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)"
        "    set(PACKAGE_VERSION_EXACT TRUE)"
        "  endif()"
        "endif()"
        ""
        : true ;
}

# generate-config-variant-

rule generate-config-variant- ( target : sources * : properties * )
{
    .info generate-config-variant- $(target) ;

    local ps = [ property-set.create $(properties) ] ;

    print.output $(target) ;

    print.text

        "# Generated by Boost $(BOOST_VERSION)"
        ""
        : true ;

    local variant = [ $(ps).get <variant> ] ;
    .info generate-config-variant-: variant is $(variant) ;

    print.text "# variant=$(variant)" "" : true ;

    if $(variant) = debug
    {
        print.text

            "if(\"${BOOST_BUILD_VARIANT}\" STREQUAL \"RELEASE\")"
            "  return()"
            "endif()"
            ""
            : true ;
    }
    else
    {
        print.text

            "if(\"${BOOST_BUILD_VARIANT}\" STREQUAL \"DEBUG\")"
            "  return()"
            "endif()"
            ""
            : true ;
    }
    
    local link = [ $(ps).get <link> ] ;
    .info generate-config-variant-: link is $(link) ;

    print.text "# link=$(link)" "" : true ;

    if $(link) = static
    {
        print.text

            "if(\"${BOOST_LINK_TYPE}\" STREQUAL \"SHARED\")"
            "  return()"
            "endif()"
            ""
            : true ;
    }
    else
    {
        print.text

            "if(NOT \"${BOOST_LINK_TYPE}\" STREQUAL \"SHARED\")"
            "  return()"
            "endif()"
            ""
            : true ;
    }
    
    local runtime-link = [ $(ps).get <runtime-link> ] ;
    .info generate-config-variant-: runtime-link is $(runtime-link) ;

    print.text "# runtime-link=$(runtime-link)" "" : true ;

    if $(runtime-link) = static
    {
        print.text

            "if(NOT \"${BOOST_RUNTIME_LINK}\" STREQUAL \"STATIC\")"
            "  return()"
            "endif()"
            ""
            : true ;
    }
    else
    {
        print.text

            "if(\"${BOOST_RUNTIME_LINK}\" STREQUAL \"STATIC\")"
            "  return()"
            "endif()"
            ""
            : true ;
    }

    local runtime-debugging = [ $(ps).get <runtime-debugging> ] ;
    .info generate-config-variant-: runtime-debugging is $(runtime-debugging) ;

    print.text "# runtime-debugging=$(runtime-debugging)" "" : true ;

    local toolset = [ MATCH ^-(.*) : [ common.format-name <toolset> : "" : "" : $(ps) ] ] ;
    .info generate-config-variant-: toolset is $(toolset) ;

    print.text "# toolset=$(toolset)" "" : true ;

    print.text

        "if(NOT \"${BOOST_TOOLSET}\" STREQUAL \"\")"
        "  if(NOT \"${BOOST_TOOLSET}\" STREQUAL \"$(toolset)\")"
        "    return()"
        "  endif()"
        "elseif(NOT \"${BOOST_DETECTED_TOOLSET}\" STREQUAL \"\" AND NOT \"${BOOST_DETECTED_TOOLSET}\" STREQUAL \"$(toolset)\")"
        "  return()"
        "endif()"
        ""
        : true ;

    local name = [ MATCH boost_(.*)-config-variant-.*cmake : $(target) ] ;
    .info generate-config-variant-: name is $(name) ;

    local ftype = STATIC_LIB ;

    if $(link) = shared
    {
        if [ os.name ] = NT
        {
            ftype = IMPORT_LIB ;
        }
        else
        {
            ftype = SHARED_LIB ;
        }
    }

    local fname = [ boostcpp.tag boost_$(name) : $(ftype) : $(ps) ] ;
    .info generate-config-variant-: fname is $(fname) ;

    print.text "# Target file name: $(fname)" "" : true ;

    print.text

        "set_property(TARGET boost::$(name) APPEND PROPERTY IMPORTED_CONFIGURATIONS $(variant:U))"
        "set_target_properties(boost::$(name) PROPERTIES"
        "  IMPORTED_LINK_INTERFACE_LANGUAGES_$(variant:U) CXX"
        "  IMPORTED_LOCATION_$(variant:U) \"${_IMPORT_PREFIX}/lib/$(fname)\""
        "  )"
        ""
        : true ;
}

# tag

rule tag ( name : type ? : property-set )
{
    .info tag $(name) :: $(type) :: $(property-set) ;

    local link = [ $(property-set).get <link> ] ;

    .info tag: link is $(link) ;

    local r = [ boostcpp.tag $(name) : STATIC_LIB : $(property-set) ] ;

    r = $(r:S=$(name:S)) ;
    r = $(r:B=$(r:B)-$(link)) ;

    .info tag: returning $(r) ;

    return $(r) ;
}

# generate-config-variant

rule generate-config-variant ( project name : property-set : sources * )
{
    .info generate-config-variant $(project) $(name) :: $(property-set) :: $(sources) ;

    local tag = [ tag $(name) : : $(property-set) ] ;

    .info generate-config-variant: tag is $(tag) ;

    local result ;

    local a = [ new non-scanning-action : $(__name__).generate-config-variant- : $(property-set) ] ;

    result += [ new file-target $(tag) : : $(project) : $(a) ] ;

    return $(result) ;
}

# exists

local rule exists ( path )
{
    return [ glob $(path) ] ;
}

# boostdep-cmake

alias boostdep : ../tools/boostdep/build//boostdep : <variant>release <link>static <runtime-link>shared <runtime-debugging>off <define>NDEBUG <threading>multi ;

feature.feature boostdep-module : : free ;
toolset.flags boostdep-cmake MODULE : <boostdep-module> ;

actions boostdep-cmake
{
    $(2) --cmake $(MODULE) > $(1)
}

# create stage and install targets

local library-dirs = [ MATCH (.*)/include : [ glob ../libs/*/include ../libs/numeric/*/include ] ] ;

for dir in $(library-dirs)
{
    .info Processing directory $(dir) ;

    local rname = [ MATCH .*/libs/(.*) : $(dir) ] ;
    .info rname is $(rname) ;

    local name = [ regex.replace $(rname) "/" "_" ] ;
    .info name is $(name) ;

    local reqs = <variant>release <link>static <runtime-link>shared <runtime-debugging>off <define>NDEBUG <threading>multi ;

    # generate -config.cmake

    local config-targets ;

    # boost_math, a dependency of lexical_cast, has six optional libraries, none of which named boost_math
    # boost_exception has an optional MSVC-only library, which creates problems under Linux

    if [ exists $(dir)/build ] && [ exists $(dir)/src ] && $(name) != "math" && $(name) != "exception"
    {
        .info Library $(name) is not header-only ;

        make boost_$(name)-config.cmake : : @generate-static-config : $(reqs) ;
        explicit boost_$(name)-config.cmake ;
        config-targets = boost_$(name)-config.cmake ;

        generate boost_$(name)-config-variant.cmake : : <generating-rule>@generate-config-variant <threading>multi ;
        explicit boost_$(name)-config-variant.cmake ;
        config-targets += boost_$(name)-config-variant.cmake ;
    }
    else
    {
        .info Library $(name) is header-only ;

        make boost_$(name)-config.cmake : : @generate-header-config : $(reqs) ;
        explicit boost_$(name)-config.cmake ;
        config-targets = boost_$(name)-config.cmake ;
    }

    # generate -config-version.cmake

    make boost_$(name)-config-version.cmake : : @generate-config-version : $(reqs) ;
    explicit boost_$(name)-config-version.cmake ;
    config-targets += boost_$(name)-config-version.cmake ;

    # generate -dependencies.cmake

    make boost_$(name)-dependencies.cmake : boostdep : @boostdep-cmake : <boostdep-module>$(rname) $(reqs) ;
    config-targets += boost_$(name)-dependencies.cmake ;

    .info The config-targets of $(name) are $(config-targets) ;

    # stage

    local stage-location = $(BOOST_STAGE_LOCATE)/lib/cmake/boost_$(name)-$(BOOST_VERSION) ;
    .info The staging location of $(name) is $(stage-location) ;

    install $(dir)-stage : $(config-targets) : <location>$(stage-location) ;
    explicit $(dir)-stage ;

    # install

    local install-location = $(libdir)/cmake/boost_$(name)-$(BOOST_VERSION) ;
    .info The install location of $(name) is $(install-location) ;

    install $(dir)-install : $(config-targets) : <location>$(install-location) ;
    explicit $(dir)-install ;
}

# BoostDetectToolset.cmake

install BoostDetectToolset-stage : BoostDetectToolset.cmake : <name>BoostDetectToolset-$(BOOST_VERSION).cmake <location>$(BOOST_STAGE_LOCATE)/lib/cmake ;
explicit BoostDetectToolset-stage ;

install BoostDetectToolset-install : BoostDetectToolset.cmake : <name>BoostDetectToolset-$(BOOST_VERSION).cmake <location>$(libdir)/cmake ;
explicit BoostDetectToolset-install ;

# stage

alias stage : BoostDetectToolset-stage $(library-dirs)-stage ;
explicit stage ;

# install

alias install : BoostDetectToolset-install $(library-dirs)-install ;
explicit install ;