Skip to content

Commit ed144ec

Browse files
committed
builds on windows
1 parent c3cc62c commit ed144ec

File tree

9 files changed

+361
-179
lines changed

9 files changed

+361
-179
lines changed

bin/boost-lib

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
4+
var log = require("npmlog");
5+
var _ = require("lodash");
6+
var boostLib = require("../");
7+
var BoostDownloader = boostLib.BoostDownloader;
8+
var util = require("util");
9+
var Bluebird = require("bluebird");
10+
11+
var version = require("../package").version;
12+
var logLevels = ["silly", "verbose", "info", "http", "warn", "error"];
13+
var yargs = require("yargs")
14+
.usage("Boost dependency resolver for CMake.js - v" + version + "\n\nUsage: $0 [<command>] [options]")
15+
.version(function () {
16+
return version;
17+
})
18+
.command("download", "Downloads specified Boost version if needed")
19+
.options({
20+
h: {
21+
alias: "help",
22+
demand: false,
23+
describe: "show this screen",
24+
type: "boolean"
25+
},
26+
l: {
27+
alias: "log-level",
28+
demand: false,
29+
describe: "sets log level (" + logLevels.join(", ") + "), default is info",
30+
type: "string"
31+
},
32+
V: {
33+
alias: "boost-version",
34+
demand: false,
35+
describe: "Boost version",
36+
type: "string"
37+
}
38+
});
39+
var argv = yargs.argv;
40+
41+
// If help, then print and exit:
42+
43+
if (argv.h) {
44+
console.info(yargs.help());
45+
return;
46+
}
47+
48+
// Setup log level:
49+
50+
if (argv.l && _.contains(logLevels, argv.l)) {
51+
log.level = argv.l;
52+
log.resume();
53+
}
54+
55+
log.silly("CON", "argv:");
56+
log.silly("CON", util.inspect(argv));
57+
58+
log.verbose("CON", "Parsing arguments");
59+
60+
var options = {
61+
version: argv.V
62+
};
63+
64+
log.verbose("CON", "options:");
65+
log.verbose("CON", util.inspect(options));
66+
67+
var command = _.first(argv._);
68+
69+
log.verbose("CON", "Running command: " + command);
70+
71+
function ifCommand(c, f) {
72+
if (c === command) {
73+
f();
74+
return true;
75+
}
76+
return false;
77+
}
78+
79+
function exitOnError(promise) {
80+
try {
81+
if (_.isFunction(promise)) {
82+
promise = promise();
83+
}
84+
}
85+
catch (e) {
86+
promise = Bluebird.reject(e);
87+
}
88+
promise.catch(function(e) {
89+
if (log.level === "verbose" || log.level === "silly") {
90+
log.error("OMG", e.stack);
91+
}
92+
else {
93+
log.error("OMG", e.message);
94+
}
95+
process.exit(1);
96+
});
97+
}
98+
99+
function download() {
100+
exitOnError(function() {
101+
return new BoostDownloader(options).ensureDownloaded()
102+
.then(function(path) {
103+
console.info(path);
104+
});
105+
});
106+
}
107+
108+
var done = ifCommand("download", download);
109+
if (!done) {
110+
if (command) {
111+
log.error("OMG", "Unknown command: " + command);
112+
}
113+
else {
114+
log.error("OMG", "Command expected.");
115+
}
116+
process.exit(1);
117+
}

cmake/BoostLib.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ function(require_boost_libs req_boost_version req_boost_libs)
88
message(STATUS "Required libs: ${req_boost_libs}")
99

1010
# Finding installed boost version
11-
find_package(Boost ${req_boost_version} COMPONENTS ${req_boost_libs})
11+
find_package(Boost "${req_boost_version}" COMPONENTS "${req_boost_libs}")
1212
if(Boost_FOUND)
1313
message(STATUS "Boost package found.")
1414
else(Boost_FOUND)
15-
boost_lib_installer(${req_boost_version} "${req_boost_libs}")
15+
boost_lib_installer("${req_boost_version}" "${req_boost_libs}")
1616
message(STATUS "Boost installed.")
1717
endif(Boost_FOUND)
1818

@@ -21,6 +21,6 @@ function(require_boost_libs req_boost_version req_boost_libs)
2121

2222
# Results:
2323
set(Boost_FOUND ${Boost_FOUND} PARENT_SCOPE)
24-
set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} PARENT_SCOPE)
25-
set(Boost_LIBRARIES ${Boost_LIBRARIES} PARENT_SCOPE)
24+
set(Boost_INCLUDE_DIRS "${Boost_INCLUDE_DIRS}" PARENT_SCOPE)
25+
set(Boost_LIBRARIES "${Boost_LIBRARIES}" PARENT_SCOPE)
2626
endfunction(require_boost_libs)

cmake/BoostLibInstaller.cmake

Lines changed: 29 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,9 @@ cmake_minimum_required(VERSION 2.8)
22

33
include(ExternalProject)
44
include(GetBoostLibB2Args)
5-
6-
#boost_lib_checkout_submo("${install_dir}" libs/core)
7-
#boost_lib_checkout_submo("${install_dir}" libs/detail)
8-
#boost_lib_checkout_submo("${install_dir}" libs/config)
9-
#boost_lib_checkout_submo("${install_dir}" libs/preprocessor)
10-
#boost_lib_checkout_submo("${install_dir}" libs/mpl)
11-
#boost_lib_checkout_submo("${install_dir}" libs/wave)
12-
#boost_lib_checkout_submo("${install_dir}" libs/assert)
13-
#boost_lib_checkout_submo("${install_dir}" libs/move)
14-
#boost_lib_checkout_submo("${install_dir}" libs/static_assert)
15-
#boost_lib_checkout_submo("${install_dir}" libs/range)
16-
#boost_lib_checkout_submo("${install_dir}" libs/type_traits)
17-
#boost_lib_checkout_submo("${install_dir}" libs/iterator)
18-
#boost_lib_checkout_submo("${install_dir}" libs/concept_check)
19-
#boost_lib_checkout_submo("${install_dir}" libs/utility)
20-
#boost_lib_checkout_submo("${install_dir}" libs/throw_exception)
21-
#boost_lib_checkout_submo("${install_dir}" libs/predef)
22-
#boost_lib_checkout_submo("${install_dir}" libs/exception)
23-
#boost_lib_checkout_submo("${install_dir}" libs/smart_ptr)
5+
include(DownloadBoost)
246

257
# Known dependencies
26-
set(core_dep
27-
config
28-
detail
29-
preprocessor
30-
assert
31-
move
32-
static_assert
33-
range
34-
type_traits
35-
iterator
36-
concept_check
37-
utility
38-
throw_exception
39-
predef
40-
exception
41-
smart_ptr
42-
mpl
43-
ratio
44-
integer)
458
set(chrono_dep system)
469
set(coroutine_dep context system)
4710
set(context_dep chrono thread)
@@ -53,59 +16,17 @@ set(thread_dep chrono)
5316
set(timer_dep chrono)
5417
set(wave_dep chrono date_time filesystem thread)
5518

56-
# Must build list
57-
# set(to_build_libs chrono context filesystem graph_parallel iostreams locale mpi
58-
59-
function(boost_lib_checkout_submo install_dir submo_path)
60-
file(GLOB submo_dir "${install_dir}/${submo_path}/*")
61-
list(LENGTH submo_dir submo_dir_len)
62-
if(submo_dir_len EQUAL 0)
63-
message(STATUS "Checking out subodule: ${submo_path}")
64-
execute_process(COMMAND "${GIT_EXECUTABLE}" submodule update --recursive --init "${submo_path}" WORKING_DIRECTORY ${install_dir} RESULT_VARIABLE err ERROR_VARIABLE err_msg)
65-
if(err)
66-
message(FATAL_ERROR "Git error:\n${err_msg}")
67-
endif(err)
68-
else()
69-
message(STATUS "Submodule ${submo_path} is already checked out.")
70-
endif()
71-
endfunction(boost_lib_checkout_submo name)
72-
7319
function(boost_lib_installer req_boost_version req_boost_libs)
7420
message(STATUS "Boost Lib Installer starting.")
7521

76-
# Resolving Git dependency
77-
find_package(Git)
78-
if(GIT_FOUND)
79-
message(STATUS "Git found: ${GIT_EXECUTABLE}")
80-
else(GIT_FOUND)
81-
message(FATAL_ERROR "Git is required for Boost library installer.")
82-
endif(GIT_FOUND)
83-
84-
# Install dir
85-
if(WIN32)
86-
set(install_dir $ENV{USERPROFILE})
87-
else(WIN32)
88-
set(install_dir $ENV{HOME})
89-
endif(WIN32)
90-
file(TO_NATIVE_PATH "${install_dir}/.cmake-js/boost/${req_boost_version}" install_dir)
91-
92-
message(STATUS "Boost Lib install dir: ${install_dir}")
93-
94-
# Clone
95-
if(NOT EXISTS "${install_dir}/.git/")
96-
message(STATUS "Cloning Boost, please stand by ...")
97-
execute_process(COMMAND "${GIT_EXECUTABLE}" clone --branch boost-${req_boost_version} --single-branch --depth 1 https://github.com/boostorg/boost.git "${install_dir}" RESULT_VARIABLE err ERROR_VARIABLE err_msg)
98-
if(err)
99-
message(FATAL_ERROR "Git error:\n${err_msg}")
100-
endif(err)
101-
else()
102-
message(STATUS "Boost repository exists.")
103-
endif()
104-
105-
# Checkout Tools and Musthaves
106-
boost_lib_checkout_submo("${install_dir}" tools/build)
107-
boost_lib_checkout_submo("${install_dir}" tools/inspect)
108-
boost_lib_checkout_submo("${install_dir}" libs/wave) # this is required for some unknown reason for jam
22+
# Download
23+
download_boost("${req_boost_version}")
24+
get_filename_component(req_boost_version "${install_dir}" NAME)
25+
message(STATUS "Boost path: ${install_dir}")
26+
message(STATUS "Boost version: ${req_boost_version}")
27+
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\." m "${req_boost_version}")
28+
set(lib_postfix "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
29+
message(STATUS "Boost library postfix: ${lib_postfix}")
10930

11031
# Bootstrap
11132
if(WIN32)
@@ -118,8 +39,13 @@ function(boost_lib_installer req_boost_version req_boost_libs)
11839
file(TO_CMAKE_PATH "${install_dir}/b2" b2_path)
11940
endif(WIN32)
12041
if (NOT EXISTS "${b2_path}")
121-
message(STATUS "Bootstrapping ...")
122-
execute_process(COMMAND ${bootstrap} WORKING_DIRECTORY ${install_dir} RESULT_VARIABLE err OUTPUT_VARIABLE err_msg OUTPUT_QUIET)
42+
message(STATUS "Invoking ${install_dir}/tools/build/${bootstrap}")
43+
execute_process(COMMAND "${bootstrap}" WORKING_DIRECTORY "${install_dir}/tools/build" RESULT_VARIABLE err OUTPUT_VARIABLE err_msg OUTPUT_QUIET)
44+
if(err)
45+
message(FATAL_ERROR "Bootstrap error:\n${err_msg}")
46+
endif(err)
47+
message(STATUS "Invoking ${install_dir}/${bootstrap}")
48+
execute_process(COMMAND "${bootstrap}" WORKING_DIRECTORY "${install_dir}" RESULT_VARIABLE err OUTPUT_VARIABLE err_msg OUTPUT_QUIET)
12349
if(err)
12450
message(FATAL_ERROR "Bootstrap error:\n${err_msg}")
12551
endif(err)
@@ -128,11 +54,16 @@ function(boost_lib_installer req_boost_version req_boost_libs)
12854
endif()
12955

13056
# Process libs
57+
if(CMAKE_CL_64 EQUAL 1)
58+
set(stage_dir stage64)
59+
else()
60+
set(stage_dir stage32)
61+
endif()
62+
13163
get_boots_lib_b2_args()
13264
message(STATUS "b2 args: ${b2Args}")
13365

13466
# Resolve dependency tree
135-
list(APPEND req_boost_libs core) # core dependencies
13667
foreach(i RANGE 5)
13768
foreach(lib ${req_boost_libs})
13869
list(APPEND req_boost_libs2 ${lib})
@@ -145,20 +76,17 @@ function(boost_lib_installer req_boost_version req_boost_libs)
14576
foreach(lib ${req_boost_libs})
14677
message(STATUS "Resolving Boost library: ${lib}")
14778

148-
# Init submodule
149-
boost_lib_checkout_submo("${install_dir}" libs/${lib})
150-
15179
if (EXISTS "${install_dir}/libs/${lib}/build/")
15280
# Has source
15381
set(jam_lib boost_${lib}_jam)
15482
set(boost_lib boost_${lib})
15583

15684
# Create lib
15785
ExternalProject_Add(
158-
${jam_lib}
159-
STAMP_DIR ${CMAKE_BINARY_DIR}/boost-${req_boost_version}
160-
SOURCE_DIR ${install_dir}
161-
BINARY_DIR ${install_dir}
86+
"${jam_lib}"
87+
STAMP_DIR "${CMAKE_BINARY_DIR}/boost-${req_boost_version}"
88+
SOURCE_DIR "${install_dir}"
89+
BINARY_DIR "${install_dir}"
16290
CONFIGURE_COMMAND ""
16391
BUILD_COMMAND "${b2_command}" "${b2Args}" --with-${lib}
16492
INSTALL_COMMAND ""
@@ -182,13 +110,12 @@ function(boost_lib_installer req_boost_version req_boost_libs)
182110
endif()
183111

184112
set_target_properties(${boost_lib} PROPERTIES
185-
IMPORTED_LOCATION_DEBUG ${install_dir}/stage/lib/libboost_${ComponentLibName}-${CompilerName}-mt-gd-${req_boost_version}.lib
186-
IMPORTED_LOCATION ${install_dir}/stage/lib/libboost_${ComponentLibName}-${CompilerName}-mt-${req_boost_version}.lib
113+
IMPORTED_LOCATION_DEBUG "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-${CompilerName}-mt-gd-${lib_postfix}.lib"
114+
IMPORTED_LOCATION "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-${CompilerName}-mt-${lib_postfix}.lib"
187115
LINKER_LANGUAGE CXX)
188116
else()
189117
set_target_properties(${boost_lib} PROPERTIES
190-
IMPORTED_LOCATION_DEBUG ${install_dir}/stage/lib/libboost_${ComponentLibName}-mt-gd.a
191-
IMPORTED_LOCATION ${install_dir}/stage/lib/libboost_${ComponentLibName}-mt.a
118+
IMPORTED_LOCATION "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-mt.a"
192119
LINKER_LANGUAGE CXX)
193120
endif()
194121

cmake/DownloadBoost.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function(download_boost version)
2+
find_file(cwd DownloadBoost.cmake PATHS ${CMAKE_MODULE_PATH})
3+
get_filename_component(cwd "${cwd}" DIRECTORY)
4+
file(TO_CMAKE_PATH "${cwd}/../bin/boost-lib" boost-lib)
5+
message(STATUS "Invoking boost-lib to download Boost ${version}.")
6+
execute_process(COMMAND node "${boost-lib}" download "-V=${version}" RESULT_VARIABLE err OUTPUT_VARIABLE path)
7+
if(err)
8+
message(FATAL_ERROR "Download error.")
9+
endif(err)
10+
string(STRIP "${path}" path)
11+
file(TO_CMAKE_PATH "${path}" path)
12+
set(install_dir ${path} PARENT_SCOPE)
13+
endfunction(download_boost)

cmake/GetBoostLibB2Args.cmake

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
function(get_boots_lib_b2_args)
2+
if(CMAKE_CL_64 EQUAL 1)
3+
set(stage_dir stage64)
4+
else()
5+
set(stage_dir stage32)
6+
endif()
7+
28
set(b2Args link=static
39
threading=multi
410
runtime-link=shared
511
--build-dir=Build
612
stage
13+
--stagedir=${stage_dir}
714
-d+2
815
--hash)
16+
17+
message(STATUS "Generating b2 args.")
918

10-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
11-
list(APPEND b2Args "variant=debug")
12-
else()
13-
list(APPEND b2Args "variant=release")
14-
endif()
19+
if(NOT MSVC)
20+
if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (NOT DEFINED CMAKE_BUILD_TYPE))
21+
message(STATUS "\tvariant=debug")
22+
list(APPEND b2Args "variant=debug")
23+
else()
24+
message(STATUS "\tvariant=release")
25+
list(APPEND b2Args "variant=release")
26+
endif()
27+
endif(NOT MSVC)
1528

1629
if(CMAKE_BUILD_TYPE STREQUAL "ReleaseNoInline")
1730
list(APPEND b2Args "cxxflags=${RELEASENOINLINE_FLAGS}")
@@ -35,8 +48,10 @@ function(get_boots_lib_b2_args)
3548
define=_BIND_TO_CURRENT_CRT_VERSION=1
3649
--layout=versioned)
3750

38-
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
51+
if(CMAKE_CL_64 EQUAL 1)
3952
list(APPEND b2Args address-model=64)
53+
else()
54+
list(APPEND b2Args address-model=32)
4055
endif()
4156
elseif(APPLE)
4257
list(APPEND b2Args toolset=clang cxxflags=-fPIC cxxflags=-std=c++11 cxxflags=-stdlib=libc++

0 commit comments

Comments
 (0)