Skip to content

Commit 7db1916

Browse files
committed
minor tweaks
1 parent 8910da1 commit 7db1916

File tree

2 files changed

+74
-49
lines changed

2 files changed

+74
-49
lines changed

cmake/BoostLib.cmake

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ 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}")
12-
if(Boost_FOUND)
13-
message(STATUS "Boost package found.")
14-
else(Boost_FOUND)
15-
boost_lib_installer("${req_boost_version}" "${req_boost_libs}")
16-
message(STATUS "Boost installed.")
17-
endif(Boost_FOUND)
11+
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+$" m "${req_boost_version}")
12+
if(NOT m STREQUAL "")
13+
find_package(Boost "${req_boost_version}" COMPONENTS "${req_boost_libs}")
14+
if(Boost_FOUND)
15+
message(STATUS "Boost package found.")
16+
else(Boost_FOUND)
17+
boost_lib_installer("${req_boost_version}" "${req_boost_libs}")
18+
message(STATUS "Boost installed.")
19+
endif(Boost_FOUND)
20+
endif()
1821

1922
message(STATUS "Boost Include dirs: ${Boost_INCLUDE_DIRS}")
2023
message(STATUS "Boost Libraries: ${Boost_LIBRARIES}")

cmake/BoostLibInstaller.cmake

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function(boost_lib_installer req_boost_version req_boost_libs)
6868
message(STATUS "b2 args: ${b2Args}")
6969

7070
# Resolve dependency tree
71-
foreach(i RANGE 5)
71+
foreach(i RANGE 3)
7272
foreach(lib ${req_boost_libs})
7373
list(APPEND req_boost_libs2 ${lib})
7474
list(APPEND req_boost_libs2 ${${lib}_dep})
@@ -83,58 +83,77 @@ function(boost_lib_installer req_boost_version req_boost_libs)
8383
if (EXISTS "${install_dir}/libs/${lib}/build/")
8484
# Has source
8585

86-
# TODO: Command has to be a dummy if the library file is already exists!
87-
86+
# Setup variables
8887
set(jam_lib boost_${lib}_jam)
8988
set(boost_lib boost_${lib})
90-
91-
# Create lib
92-
ExternalProject_Add(
93-
"${jam_lib}"
94-
STAMP_DIR "${CMAKE_BINARY_DIR}/boost-${req_boost_version}"
95-
SOURCE_DIR "${install_dir}"
96-
BINARY_DIR "${install_dir}"
97-
CONFIGURE_COMMAND ""
98-
BUILD_COMMAND "${b2_command}" "${b2Args}" --with-${lib}
99-
INSTALL_COMMAND ""
100-
LOG_BUILD ON)
101-
102-
add_library(${boost_lib} STATIC IMPORTED GLOBAL)
103-
10489
if(lib STREQUAL "test")
105-
set(ComponentLibName unit_test_framework)
90+
set(lib_name unit_test_framework)
10691
else()
107-
set(ComponentLibName ${lib})
92+
set(lib_name ${lib})
10893
endif()
109-
94+
11095
if(MSVC)
11196
if(MSVC11)
112-
set(CompilerName vc110)
97+
set(compiler_name vc110)
11398
elseif(MSVC12)
114-
set(CompilerName vc120)
99+
set(compiler_name vc120)
115100
elseif(MSVC14)
116-
set(CompilerName vc140)
101+
set(compiler_name vc140)
117102
endif()
118-
119-
set_target_properties(${boost_lib} PROPERTIES
120-
IMPORTED_LOCATION_DEBUG "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-${CompilerName}-mt-gd-${lib_postfix}.lib"
121-
IMPORTED_LOCATION "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-${CompilerName}-mt-${lib_postfix}.lib"
122-
LINKER_LANGUAGE CXX)
103+
104+
set(debug_lib_path "${install_dir}/${stage_dir}/lib/libboost_${lib_name}-${compiler_name}-mt-gd-${lib_postfix}.lib")
105+
set(lib_path "${install_dir}/${stage_dir}/lib/libboost_${lib_name}-${compiler_name}-mt-${lib_postfix}.lib")
123106
else()
124107
if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "") OR (NOT DEFINED CMAKE_BUILD_TYPE))
125-
set_target_properties(${boost_lib} PROPERTIES
126-
IMPORTED_LOCATION "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-mt-d.a"
127-
LINKER_LANGUAGE CXX)
108+
set(lib_path "${install_dir}/${stage_dir}/lib/libboost_${lib_name}-mt-d.a")
128109
else()
129-
set_target_properties(${boost_lib} PROPERTIES
130-
IMPORTED_LOCATION "${install_dir}/${stage_dir}/lib/libboost_${ComponentLibName}-mt.a"
131-
LINKER_LANGUAGE CXX)
110+
set(lib_path "${install_dir}/${stage_dir}/lib/libboost_${lib_name}-mt.a")
132111
endif()
133112
endif()
134113

135-
set_target_properties(${jam_lib} ${boost_lib} PROPERTIES
136-
LABELS Boost EXCLUDE_FROM_ALL TRUE)
114+
# Create lib
115+
if(EXISTS ${lib_path})
116+
message(STATUS "Library ${lib} already built.")
117+
# Dummy project:
118+
ExternalProject_Add(
119+
"${jam_lib}"
120+
STAMP_DIR "${CMAKE_BINARY_DIR}/boost-${req_boost_version}"
121+
SOURCE_DIR "${install_dir}"
122+
BINARY_DIR "${install_dir}"
123+
CONFIGURE_COMMAND ""
124+
BUILD_COMMAND ""
125+
INSTALL_COMMAND ""
126+
LOG_BUILD OFF)
127+
else()
128+
message(STATUS "Setting up external project to build ${lib}.")
129+
ExternalProject_Add(
130+
"${jam_lib}"
131+
STAMP_DIR "${CMAKE_BINARY_DIR}/boost-${req_boost_version}"
132+
SOURCE_DIR "${install_dir}"
133+
BINARY_DIR "${install_dir}"
134+
CONFIGURE_COMMAND ""
135+
BUILD_COMMAND "${b2_command}" "${b2Args}" --with-${lib}
136+
INSTALL_COMMAND ""
137+
LOG_BUILD ON)
138+
endif()
139+
140+
add_library(${boost_lib} STATIC IMPORTED GLOBAL)
141+
142+
if(MSVC)
143+
set_target_properties(${boost_lib} PROPERTIES
144+
IMPORTED_LOCATION_DEBUG "${debug_lib_path}"
145+
IMPORTED_LOCATION "${lib_path}"
146+
LINKER_LANGUAGE CXX)
147+
else()
148+
set_target_properties(${boost_lib} PROPERTIES
149+
IMPORTED_LOCATION "${lib_path}"
150+
LINKER_LANGUAGE CXX)
151+
endif()
152+
153+
# Exlude it from all
154+
set_target_properties(${jam_lib} ${boost_lib} PROPERTIES LABELS Boost EXCLUDE_FROM_ALL TRUE)
137155

156+
# Setup dependencies
138157
add_dependencies(${boost_lib} ${jam_lib})
139158
foreach(dep_lib ${${lib}_dep})
140159
message(STATUS "Setting ${boost_lib} dependent on boost_${dep_lib}")
@@ -155,12 +174,15 @@ function(boost_lib_installer req_boost_version req_boost_libs)
155174
endif()
156175

157176
# b2 headers
158-
# TODO: Generate only if doesn't exists
159-
message(STATUS "Generating headers ...")
160-
execute_process(COMMAND ${b2_command} headers WORKING_DIRECTORY ${install_dir} RESULT_VARIABLE err OUTPUT_VARIABLE err_msg)
161-
if(err)
162-
message(FATAL_ERROR "b2 error:\n${err_msg}")
163-
endif(err)
177+
if(NOT EXISTS ${install_dir}/boost/)
178+
message(STATUS "Generating headers ...")
179+
execute_process(COMMAND ${b2_command} headers WORKING_DIRECTORY ${install_dir} RESULT_VARIABLE err OUTPUT_VARIABLE err_msg)
180+
if(err)
181+
message(FATAL_ERROR "b2 error:\n${err_msg}")
182+
endif(err)
183+
else()
184+
message(STATUS "Headers found.")
185+
endif()
164186

165187
set(Boost_INCLUDE_DIRS "${install_dir}" PARENT_SCOPE)
166188
set(Boost_FOUND TRUE PARENT_SCOPE)

0 commit comments

Comments
 (0)