Skip to content

Commit ee83327

Browse files
authored
ver 3.3 (#5)
ver 3.3 Fixed when multiple invocations of addboost happened a lot of behaviour problems. drawback : using my version of CPM commit log: * fixed if `addboost` is called twice * use my version of CPM. * use Boost_LOCAL from my version of CPM .
1 parent 93d8c47 commit ee83327

File tree

3 files changed

+76
-94
lines changed

3 files changed

+76
-94
lines changed

CMakeLists.txt

+70-84
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ cmake_minimum_required(VERSION 3.14...3.22)
55
# Note: update this to your new project's name and version
66
project(
77
AddBoost.cmake
8-
VERSION 3.2
8+
VERSION 3.3
99
LANGUAGES CXX
1010
)
1111

1212
function(SUBDIRLIST result_var curdir)
1313
file(
1414
GLOB children
1515
RELATIVE ${curdir}
16-
${curdir}/*)
16+
${curdir}/*
17+
)
1718
set(result "")
1819
foreach(child ${children})
1920
if(IS_DIRECTORY ${curdir}/${child})
@@ -22,18 +23,21 @@ function(SUBDIRLIST result_var curdir)
2223
endforeach()
2324
set(${result_var}
2425
${result}
25-
PARENT_SCOPE)
26+
PARENT_SCOPE
27+
)
2628
endfunction()
2729

2830
macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
29-
BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED)
31+
BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
32+
)
3033
message(
3134
DEBUG
3235
"add_boost called with next arguments:
3336
\$\{\$\{TRY_BOOST_VERSION\}\} : ${${TRY_BOOST_VERSION}}
3437
\$\{\$\{BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED\}\} : ${${BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}}
3538
\$\{\$\{BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED\}\} : ${${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}}
36-
")
39+
"
40+
)
3741
set(targets_to_link_to "${ARGN}")
3842
message(DEBUG "targets_to_link_to: \"${targets_to_link_to}\"")
3943
set(BOOST_INCLUDE_LIBRARIES
@@ -56,11 +60,13 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
5660
set(patches_for_boost "")
5761

5862
file(GLOB global_patches_for_boost CONFIGURE_DEPENDS
59-
"${CMAKE_CURRENT_SOURCE_DIR}/patches/boost/*.patch")
63+
"${CMAKE_CURRENT_SOURCE_DIR}/patches/boost/*.patch"
64+
)
6065
list(APPEND patches_for_boost ${global_patches_for_boost})
6166
if(DEFINED BOOST_ADD_MY_PATCHES)
6267
file(GLOB global_patches_for_boost CONFIGURE_DEPENDS
63-
"${BOOST_ADD_MY_PATCHES}/patches/boost/*.patch")
68+
"${BOOST_ADD_MY_PATCHES}/patches/boost/*.patch"
69+
)
6470
list(APPEND patches_for_boost ${global_patches_for_boost})
6571

6672
endif()
@@ -69,11 +75,10 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
6975
if(subdirs_boost_patches)
7076
foreach(subdir ${subdirs_boost_patches})
7177
if(${subdir} STREQUAL ${${TRY_BOOST_VERSION}})
72-
file(GLOB_RECURSE patches_with_max_applicable_version_up_to
73-
CONFIGURE_DEPENDS
74-
"${CMAKE_CURRENT_SOURCE_DIR}/patches/boost/${subdir}/*.patch")
75-
list(APPEND patches_for_boost
76-
${patches_with_max_applicable_version_up_to})
78+
file(GLOB_RECURSE patches_with_max_applicable_version_up_to CONFIGURE_DEPENDS
79+
"${CMAKE_CURRENT_SOURCE_DIR}/patches/boost/${subdir}/*.patch"
80+
)
81+
list(APPEND patches_for_boost ${patches_with_max_applicable_version_up_to})
7782
endif()
7883
endforeach()
7984
endif()
@@ -82,80 +87,56 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
8287
if(subdirs_boost_patches)
8388
foreach(subdir ${subdirs_boost_patches})
8489
if(${subdir} STREQUAL ${${TRY_BOOST_VERSION}})
85-
file(GLOB_RECURSE patches_with_max_applicable_version_up_to
86-
CONFIGURE_DEPENDS
87-
"${CMAKE_CURRENT_SOURCE_DIR}/patches/boost/${subdir}/*.patch")
88-
list(APPEND patches_for_boost
89-
${patches_with_max_applicable_version_up_to})
90+
file(GLOB_RECURSE patches_with_max_applicable_version_up_to CONFIGURE_DEPENDS
91+
"${CMAKE_CURRENT_SOURCE_DIR}/patches/boost/${subdir}/*.patch"
92+
)
93+
list(APPEND patches_for_boost ${patches_with_max_applicable_version_up_to})
9094
endif()
9195
endforeach()
9296
endif()
9397
endif()
9498

95-
string(REPLACE ";" "\;"
96-
ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
97-
"${${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}}")
99+
string(REPLACE ";" "\;" ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
100+
"${${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}}"
101+
)
98102
message(
99103
DEBUG
100104
"\$\{ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED\} : ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
101105
)
102106

103107
if(DEFINED BOOST_USE_MY_BOOST_DIRECTORY)
104-
cpmaddpackage(
105-
NAME
106-
Boost
107-
VERSION
108-
${${TRY_BOOST_VERSION}}
109-
SOURCE_DIR
110-
${BOOST_USE_MY_BOOST_DIRECTORY}
111-
PATCHES
112-
${patches_for_boost}
113-
FIND_PACKAGE_ARGUMENTS
114-
"COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
115-
OPTIONS
116-
"BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}")
108+
CPMAddPackage(
109+
NAME Boost
110+
VERSION ${${TRY_BOOST_VERSION}}
111+
SOURCE_DIR ${BOOST_USE_MY_BOOST_DIRECTORY} PATCHES ${patches_for_boost}
112+
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
113+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
114+
)
117115
elseif(patches_for_boost AND NOT boost_is_old) # is it 1.80.0 < x < 1.84.0
118-
cpmaddpackage(
119-
NAME
120-
Boost
121-
VERSION
122-
${${TRY_BOOST_VERSION}}
123-
URL
124-
${BOOST_URL}
125-
PATCHES
126-
${patches_for_boost}
127-
FIND_PACKAGE_ARGUMENTS
128-
"COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
129-
OPTIONS
130-
"BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}")
116+
CPMAddPackage(
117+
NAME Boost
118+
VERSION ${${TRY_BOOST_VERSION}}
119+
URL ${BOOST_URL} PATCHES ${patches_for_boost}
120+
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
121+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
122+
)
131123
elseif(NOT boost_is_old) # is it 1.85.0+ ?
132-
cpmaddpackage(
133-
NAME
134-
Boost
135-
VERSION
136-
${${TRY_BOOST_VERSION}}
137-
URL
138-
${BOOST_URL}
139-
FIND_PACKAGE_ARGUMENTS
140-
"COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
141-
OPTIONS
142-
"BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}")
124+
CPMAddPackage(
125+
NAME Boost
126+
VERSION ${${TRY_BOOST_VERSION}}
127+
URL ${BOOST_URL}
128+
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
129+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
130+
)
143131
else() # is it <1.80.0 ?
144-
cpmaddpackage(
145-
NAME
146-
Boost
147-
VERSION
148-
${${TRY_BOOST_VERSION}}
149-
GIT_REPOSITORY
150-
"https://github.com/boostorg/boost"
151-
GIT_TAG
152-
"boost-${${TRY_BOOST_VERSION}}"
153-
PATCHES
154-
${patches_for_boost}
155-
FIND_PACKAGE_ARGUMENTS
156-
"COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
157-
OPTIONS
158-
"BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}")
132+
CPMAddPackage(
133+
NAME Boost
134+
VERSION ${${TRY_BOOST_VERSION}}
135+
GIT_REPOSITORY "https://github.com/boostorg/boost"
136+
GIT_TAG "boost-${${TRY_BOOST_VERSION}}" PATCHES ${patches_for_boost}
137+
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${ESCAPED_BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
138+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
139+
)
159140
endif()
160141

161142
# set(IS_BOOST_LOCAL OFF) endif()
@@ -164,7 +145,11 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
164145

165146
# Link dependencies
166147
foreach(target IN LISTS targets_to_link_to)
167-
message(DEBUG "Boost_ADDED is defined : ${Boost_ADDED}")
148+
if(DEFINED Boost_LOCAL)
149+
message(DEBUG "Boost_LOCAL is defined \$\{Boost_LOCAL\}: ${Boost_LOCAL}")
150+
else()
151+
message(DEBUG "Boost_LOCAL is not defined.")
152+
endif()
168153
if(NOT DEFINED ADDBOOSTCMAKE_LINK_TYPE)
169154
get_target_property(type ${target} TYPE)
170155
if("${type}" STREQUAL "INTERFACE_LIBRARY")
@@ -175,21 +160,19 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
175160
else()
176161
set(ADDBOOSTCMAKE_LINK_TYPE_VALUE ${ADDBOOSTCMAKE_LINK_TYPE})
177162
endif()
178-
if(Boost_ADDED STREQUAL "")
163+
if(Boost_LOCAL STREQUAL "YES")
179164
target_link_libraries(${target} ${ADDBOOSTCMAKE_LINK_TYPE_VALUE} Boost::boost)
180165
else()
181166
foreach(a_lib ${${BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}})
182-
target_link_libraries(${target} ${ADDBOOSTCMAKE_LINK_TYPE_VALUE}
183-
Boost::${a_lib})
167+
target_link_libraries(${target} ${ADDBOOSTCMAKE_LINK_TYPE_VALUE} Boost::${a_lib})
184168
endforeach()
185169
endif()
186170

187171
foreach(a_lib ${${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}})
188-
target_link_libraries(${target} ${ADDBOOSTCMAKE_LINK_TYPE_VALUE}
189-
Boost::${a_lib})
172+
target_link_libraries(${target} ${ADDBOOSTCMAKE_LINK_TYPE_VALUE} Boost::${a_lib})
190173
endforeach()
191174
endforeach()
192-
if(Boost_ADDED STREQUAL "")
175+
if(Boost_LOCAL STREQUAL "YES")
193176
set(ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS
194177
"Boost ${${TRY_BOOST_VERSION}} REQUIRED ${${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}}"
195178
)
@@ -200,16 +183,19 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
200183
)
201184
foreach(dep ${BOOST_ALL_DEPENDENCIES})
202185
string(APPEND ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS
203-
"boost_${dep} ${${TRY_BOOST_VERSION}};")
186+
"boost_${dep} ${${TRY_BOOST_VERSION}};"
187+
)
204188
endforeach()
205189
string(LENGTH "${ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS}"
206-
ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS_LENGTH)
190+
ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS_LENGTH
191+
)
207192
math(EXPR ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS_LENGTH
208-
"${ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS_LENGTH}-1"
209-
OUTPUT_FORMAT DECIMAL)
193+
"${ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS_LENGTH}-1" OUTPUT_FORMAT DECIMAL
194+
)
210195
string(SUBSTRING "${ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS}" 0
211196
${ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS_LENGTH}
212-
ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS)
197+
ADDBOOSTCMAKE_PACKAGEPROJECT_INSTALL_TARGETS
198+
)
213199
endif()
214200

215201
message(

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Versions tested: from 1.79.0 upto 1.86.0 .
1616
```cmake
1717
CPMAddPackage(
1818
NAME AddBoost.CMake
19-
GIT_TAG 3.1
19+
GIT_TAG 3.3
2020
GITHUB_REPOSITORY Arniiiii/AddBoost.cmake
2121
)
2222
```

cmake/getCPM.cmake

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# ===============================================================================
22

3-
# This file should be like getCPM.cmake from CPM project. Though, because there's a logical error at
4-
# finding local boost ( if error, not much explanation why ) there's a problem that is going to be
5-
# fixed in PR https://github.com/cpm-cmake/CPM.cmake/pull/589 , here is just CPM.cmake file from the
6-
# project with a patch from this PR.
3+
# This file should be like getCPM.cmake from CPM project. But it's too long to wait until a PR is
4+
# merged. So we use here a my version.
75

86
# =============================================================================
97
# from release
@@ -30,13 +28,12 @@
3028
# include(${CPM_DOWNLOAD_LOCATION})
3129
#
3230

33-
3431
# =============================================================================
3532
# my version:
3633
# =============================================================================
3734

38-
# set(CPM_DOWNLOAD_VERSION 0.40.2)
39-
# set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")
35+
# set(CPM_DOWNLOAD_VERSION 0.40.2) set(CPM_HASH_SUM
36+
# "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")
4037

4138
if(CPM_SOURCE_CACHE)
4239
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
@@ -49,8 +46,7 @@ endif()
4946
# Expand relative path. This is important if the provided path contains a tilde (~)
5047
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
5148

52-
file(DOWNLOAD
53-
https://raw.githubusercontent.com/Arniiiii/CPM.cmake/master/cmake/CPM.cmake
49+
file(DOWNLOAD https://raw.githubusercontent.com/Arniiiii/CPM.cmake/main/cmake/CPM.cmake
5450
${CPM_DOWNLOAD_LOCATION} # EXPECTED_HASH SHA256=${CPM_HASH_SUM}
5551
)
5652

0 commit comments

Comments
 (0)