Skip to content

Commit 93c19f9

Browse files
authored
ver 2.1 add ability to add your option and source dir
ver 2.1 add ability to add your option and source dir
2 parents 0f42b0f + 6cdd5fd commit 93c19f9

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

CMakeLists.txt

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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 2.0
8+
VERSION 2.1
99
LANGUAGES CXX
1010
)
1111

@@ -86,30 +86,40 @@ macro(add_boost TRY_BOOST_VERSION BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED
8686
endif()
8787
endif()
8888

89-
if(patches_for_boost AND NOT boost_is_old)
89+
if(DEFINED BOOST_USE_MY_BOOST_DIRECTORY)
90+
CPMAddPackage(
91+
NAME Boost
92+
VERSION ${TRY_BOOST_VERSION}
93+
SOURCE_DIR ${BOOST_USE_MY_BOOST_DIRECTORY}
94+
PATCHES ${patches_for_boost}
95+
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
96+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
97+
)
98+
endif()
99+
if(patches_for_boost AND NOT boost_is_old) # is it 1.80.0 < x < 1.84.0
90100
CPMAddPackage(
91101
NAME Boost
92102
VERSION ${TRY_BOOST_VERSION}
93103
URL ${BOOST_URL} PATCHES ${patches_for_boost}
94104
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
95-
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_SKIP_INSTALL_RULES OFF"
105+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
96106
)
97-
elseif(NOT boost_is_old)
107+
elseif(NOT boost_is_old) # is it 1.85.0+ ?
98108
CPMAddPackage(
99109
NAME Boost
100110
VERSION ${TRY_BOOST_VERSION}
101111
URL ${BOOST_URL}
102112
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
103-
OPTIONS "BOOST_SKIP_INSTALL_RULES OFF"
113+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
104114
)
105-
else()
115+
else() # is it <1.80.0 ?
106116
CPMAddPackage(
107117
NAME Boost
108118
VERSION ${TRY_BOOST_VERSION}
109119
GIT_REPOSITORY "https://github.com/boostorg/boost"
110120
GIT_TAG "boost-${TRY_BOOST_VERSION}" PATCHES ${patches_for_boost}
111121
FIND_PACKAGE_ARGUMENTS "COMPONENTS ${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
112-
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_SKIP_INSTALL_RULES OFF"
122+
OPTIONS "BOOST_ENABLE_CMAKE ON;BOOST_SKIP_INSTALL_RULES OFF;${BOOST_MY_OPTIONS}"
113123
)
114124
endif()
115125

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,18 @@ packageProject(
6161
6262
```
6363

64-
6564
## Features:
6665

6766
- [x] Find local Boost
68-
- [x] Download boost if there's with lower version than needed or if `-DCPM_DOWNLOAD_ALL=1`
67+
- [x] Download boost if there's local Boost with lower version than needed or if `-DCPM_DOWNLOAD_ALL=1`
6968
- [x] Links Boost to what target you need by itself
7069
- [x] If you don't want to download Boost multiple times, set `-DCPM_SOURCE_CACHE=./.cache/cpm`
7170
- [x] Gives appropriate string for you to add to [`PackageProject.cmake`](https://github.com/TheLartians/PackageProject.cmake)
7271
- [x] Makes Boost generate appropriate install targets
7372
- [x] If you download Boost, you can add additional configuring options just by setting them before calling function.
7473
- [x] Well tested at [Arniiiii/ModernCppStarterExampleBoostCmake](https://github.com/Arniiiii/ModernCppStarterExampleBoostCmake)
74+
- [x] You can apply your options or by setting it by your self, or by setting `BOOST_MY_OPTIONS` to something like `"OPTION value;OPTION2 value;"` for example `BOOST_ENABLE_PYTHON ON;` .
75+
- [x] If you have your own Boost directory, set `BOOST_USE_MY_BOOST_DIRECTORY` to be the path with your Boost.
7576
- [x] You can apply your patches to Boost. Define variable `BOOST_ADD_MY_PATCHES` to be a path to folder in which there's `*.patch` in such layout:
7677
```
7778
patches/

0 commit comments

Comments
 (0)