-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add how to add boost #575
add how to add boost #575
Changes from 2 commits
34065ba
0d8c0b5
bf48af8
b161835
f6665a6
981b419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,24 +414,9 @@ CPMAddPackage( | |
|
||
### [Boost](https://github.com/boostorg/boost) | ||
|
||
Boost is a large project and will take a while to download. Using | ||
`CPM_SOURCE_CACHE` is strongly recommended. Cloning moves much more | ||
data than a source archive, so this sample will use a compressed | ||
source archive (tar.xz) release from Boost's github page. | ||
Boost has incompatible targets: for boost installed via b2 (or via CMake upto version boost_1.84.0 or via CMake scripts from `boost/tools/boost_install`) there's no targets for header-only Boost's libraries. Starting from boost_1.85.0 there's b2 version **and CMake version** of *install* targets, and Boost CMake version install CMake target even for header-only libraries, which allows installing and using only necessary boost libraries. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this related to CPM? And why worry about installation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because assume there's no boost on system. What should cmake install when you asked to install your project that uses a boost library, when there's no boost on the specific system? Right, it installs the specific boost libraries too. That's why thinking about installation targets in this context is important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm... In my use cases, I compile boost as a static library so there's no boost installation. In the case of a library, this gets more complicated. But I think the fix to patch Boost instead of add another dependency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I support your idea. I'll try realize it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the script allows more than patching, but also easy linking, easy installing and so on, no matter is boost installed on the system or not, which is great. |
||
|
||
```CMake | ||
# boost is a huge project and directly downloading the 'alternate release' | ||
# from github is much faster than recursively cloning the repo. | ||
CPMAddPackage( | ||
NAME Boost | ||
VERSION 1.84.0 | ||
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz | ||
URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e | ||
OPTIONS "BOOST_ENABLE_CMAKE ON" | ||
) | ||
``` | ||
|
||
For a working example of using CPM to download and configure the Boost C++ Libraries see [here](examples/boost). | ||
Also, to get install target if you use `add_subdirectory(dir_with_boost_source)`, you need to apply a patch for 1.80.0, and another patch if you want a version of Boost from 1.81.0 upto 1.84.0. To solve such problems, there's a script [AddBoost.CMake](https://github.com/Arniiiii/AddBoost.cmake) example usage of which you can see here: [here](examples/boost) or [here](https://github.com/Arniiiii/ModernCppStarterExampleBoostCmake). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this comment mean and how is it realted to nominal CPM usage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a problem with cmake for boost from versions from 1.80.0 upto 1.84.0 that doesn't allow using it via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are using CPM, why would we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm using CPM. Though the logic behind CPM is actually a kinda smart add_subdirectory. I don't use add_subdirectory manually in my projects too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand. |
||
|
||
### [cxxopts](https://github.com/jarro2783/cxxopts) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,34 @@ project(CPMExampleBoost) | |
|
||
# ---- Create binary ---- | ||
|
||
add_executable(CPMExampleBoost main.cpp) | ||
add_executable(${PROJECT_NAME} main.cpp) | ||
target_compile_features(CPMExampleBoost PRIVATE cxx_std_17) | ||
|
||
# ---- Dependencies ---- | ||
|
||
include(../../cmake/CPM.cmake) | ||
|
||
CPMAddPackage( | ||
NAME Boost | ||
VERSION 1.84.0 | ||
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz | ||
URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e | ||
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_INCLUDE_LIBRARIES container\\\;asio" # Note the escapes! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a simple, secure, working example that demonstrates including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this is important. |
||
NAME AddBoost.CMake | ||
GIT_TAG main | ||
GITHUB_REPOSITORY Arniiiii/AddBoost.cmake | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example lacks security and a specific version of boost. When developing a commercial application, there's often a need to call out a specific revision of boost. These lines are neither equivalent nor better than the removed lines for my purposes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security? Not sure. I admit the problem with specific version. I'll try to solve it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought a little bit about version handling. If to think about AddBoost.cmake not as wrapper for Boost but just another cmake script, In the end it's still If to think about specific revision of boost there's two options:
|
||
) | ||
|
||
target_link_libraries(CPMExampleBoost PRIVATE Boost::asio Boost::container) | ||
set(TRY_BOOST_VERSION "1.85.0") | ||
set(BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED "thread") | ||
set(BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED "asio") | ||
|
||
add_boost(${TRY_BOOST_VERSION} ${BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED} | ||
${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED} ${PROJECT_NAME} boost_install_targets | ||
) | ||
|
||
# notice ${boost_install_targets} in the next lines: | ||
|
||
# CPMAddPackage( NAME PackageProject.cmake VERSION 1.11.2 GIT_REPOSITORY | ||
# "https://github.com/TheLartians/PackageProject.cmake.git" ) | ||
# | ||
# packageProject( NAME ${PROJECT_NAME} VERSION ${PROJECT_VERSION} NAMESPACE ${PROJECT_NAME} | ||
# BINARY_DIR ${PROJECT_BINARY_DIR} INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include INCLUDE_DESTINATION | ||
# include/${PROJECT_NAME} VERSION_HEADER "${VERSION_HEADER_LOCATION}" EXPORT_HEADER | ||
# "${EXPORT_HEADER_LOCATION}" COMPATIBILITY "AnyNewerVersion" DISABLE_VERSION_SUFFIX ON DEPENDENCIES | ||
# "${boost_install_targets}" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removed bit is a very important part of this example. It coaches the user in best practices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I'll try to save these lines of notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if add them to
## Tips
that would be ok