From 1ddf77ac2f5b54f794c955191c61a785a87c3fd2 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Thu, 5 Apr 2018 23:25:03 +0200 Subject: [PATCH] Some updates from AmpGen work --- chapters/features.md | 18 ++++++++++++++++++ chapters/features/modules.md | 7 +++++++ chapters/packages/OpenMP.md | 9 ++++++--- chapters/packages/ROOT.md | 4 ++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/chapters/features.md b/chapters/features.md index 4390f51..bd89c19 100644 --- a/chapters/features.md +++ b/chapters/features.md @@ -1,3 +1,21 @@ # Adding features This section covers adding common features to your CMake project. You'll learn how to add a variety of options commonly needed in C++ projects, like C++11 support, as well as how to support IDEs and more. + + +## Default build type + +CMake normally does a "non-release, non debug" empty build type; if you prefer to set the default build type yourself, you can follow this +recipe for the default build type modified from the [Kitware blog](https://blog.kitware.com/cmake-and-the-default-build-type/): + +```cmake +set(default_build_type "Release") +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE + STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() +``` diff --git a/chapters/features/modules.md b/chapters/features/modules.md index be8cc99..e929994 100644 --- a/chapters/features/modules.md +++ b/chapters/features/modules.md @@ -26,6 +26,12 @@ if(NOT BUILD_TESTS_DEFAULT) mark_as_advanced(BUILD_TESTS) endif() ``` +## [CMakePrintHelpers] + + +This module has a couple of handy output functions. `cmake_print_properties` lets you easily print properties. +And `cmake_print_variables` will print the names and values of any variables you give it. + ## [CheckCXXCompilerFlag] @@ -86,3 +92,4 @@ There are lots of options you can add, like `COMPILE_DEFINITIONS`. In CMake 3.8+ [CMakeDependentOption]: https://cmake.org/cmake/help/latest/module/CMakeDependentOption.html [CheckCXXCompilerFlag]: https://cmake.org/cmake/help/latest/module/CheckCXXCompilerFlag.html [WriteCompilerDetectionHeader]: https://cmake.org/cmake/help/latest/module/WriteCompilerDetectionHeader.html +[CMakePrintHelpers]: https://cmake.org/cmake/help/latest/module/CMakePrintHelpers.html diff --git a/chapters/packages/OpenMP.md b/chapters/packages/OpenMP.md index 99fe49e..f2f9d46 100644 --- a/chapters/packages/OpenMP.md +++ b/chapters/packages/OpenMP.md @@ -16,17 +16,20 @@ This not only is cleaner than the old method, it will also correctly set the lib ```cmake # For CMake < 3.9, we need to make the target ourselves if(NOT TARGET OpenMP::OpenMP_CXX) + find_package(Threads REQUIRED) add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS}) # Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang) set_property(TARGET OpenMP::OpenMP_CXX - PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS}) + PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads) - find_package(Threads REQUIRED) - target_link_libraries(MyTarget INTERFACE Threads::Threads) endif() target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX) ``` +{% hint style='danger' %} +Warning: CMake < 3.4 has a bug in the Threads package that requires you to have the `C` language enabled. +{% endhint %} + [OpenMP]: https://cmake.org/cmake/help/latest/module/FindOpenMP.html diff --git a/chapters/packages/ROOT.md b/chapters/packages/ROOT.md index 16febcf..56fb7b9 100644 --- a/chapters/packages/ROOT.md +++ b/chapters/packages/ROOT.md @@ -32,6 +32,10 @@ To link, just pick the libraries you want to use: [import:'add_and_link', lang:'cmake'](../../examples/root-simple/CMakeLists.txt) +## Components + +Find ROOT allows you to specify components. It will add anything you list to ${ROOT_LIBRARIES}, so you might want to build your own target using that to avoid listing the components twice. + ## Dictionary generation Dictionary generation is ROOT's way of working around the missing reflection feature in C++. It allows ROOT to learn the details of your class so it can save it, show methods in the Cling interpreter, etc. You'll need three things in your source code to make it work for classes: