pabloariasal / modern-cmake-sample Goto Github PK
View Code? Open in Web Editor NEWExample library that shows best practices and proper usage of CMake by using targets
License: MIT License
Example library that shows best practices and proper usage of CMake by using targets
License: MIT License
When I run this with the CMAKE_PREFIX_PATH=~/tmp/rapidjson (for the git repo), it finds ~/tmp/rapidjson/include/rapidjson as the include directory. However, in json_utils.h it #include <rapidjson/document.h>
. Because the rapidjson
is in both the include path and the header file, it fails to find the file.
Is there a way that FindRapidJSON.cmake can include the directory one level up from where rapidjson.h is located?
I get the following error while using Ubuntu 18 and cmake 3.19. Is "boost_headers" a package name or am I missing something here?
############################################
CMake Error at CMakeLists.txt:10 (find_package):
Could not find a package configuration file provided by "boost_headers"
(requested version 1.71) with any of the following names:
boost_headersConfig.cmake
boost_headers-config.cmake
Add the installation prefix of "boost_headers" to CMAKE_PREFIX_PATH or set
"boost_headers_DIR" to a directory containing one of the above files. If
"boost_headers" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
######################################################
What if the lib itself would be structured into several subprojects by means of the add_subdirectory() command in the top-level CMakeLists.txt. Can you maybe show, how to proceed then? Where do the exporting and installation commands go? into every individual subproject or do you define them all together in the root cmake file? Daniel Pfeiffer is not clear on this as well and I would appreciate it, if you could shed some light on this issue
It would be nice if the readme included the necessary commands for beginners to execute the sample.
i.e. - how to get boost, how to build boost (./bootstrap.sh ; ./b2 --with-regex stage
), how to let cmake find them (export BOOST_ROOT=/path/to/boost_1_55_0
, export CMAKE_PREFIX_PATH=/path/to/rapidjson_repo
), where to run cmake from (cd libjsonutils ; mkdir build; cd build; cmake ..
), etc
As a beginner in cmake I'd like to see how to implement tests for private sources of the target (here it would be file_utils.h)
Now I do something like
target_include_directories(tests
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../src
)
in test directory.
Is it correct?
You should specify a license so people know whether they're allowed to reuse parts of your examples. Even though it's open-source, it's not currently free software.
Does the version of boost you used have some patch applied to optional? I see this error.
tomkent@frink:~/tmp/modern-cmake-sample/libjsonutils/build$ make
[ 12%] Building CXX object CMakeFiles/jsonutils.dir/src/json_utils.cpp.o
In file included from /home/tomkent/tmp/modern-cmake-sample/libjsonutils/include/jsonutils/json_utils.h:6:0,
from /home/tomkent/tmp/modern-cmake-sample/libjsonutils/src/json_utils.cpp:1:
/home/tomkent/tmp/boost_1_55_0/boost/optional/optional.hpp: In instantiation of ‘void boost::optional_detail::optional_base<T>::construct(boost::optional_detail::optional_base<T>::argument_type) [with T = rapidjson::GenericDocument<rapidjson::UTF8<> >; boost::optional_detail::optional_base<T>::argument_type = const rapidjson::GenericDocument<rapidjson::UTF8<> >&]’:
/home/tomkent/tmp/boost_1_55_0/boost/optional/optional.hpp:230:16: required from ‘boost::optional_detail::optional_base<T>::optional_base(boost::optional_detail::optional_base<T>::argument_type) [with T = rapidjson::GenericDocument<rapidjson::UTF8<> >; boost::optional_detail::optional_base<T>::argument_type = const rapidjson::GenericDocument<rapidjson::UTF8<> >&]’
/home/tomkent/tmp/boost_1_55_0/boost/optional/optional.hpp:526:46: required from ‘boost::optional<T>::optional(boost::optional<T>::argument_type) [with T = rapidjson::GenericDocument<rapidjson::UTF8<> >; boost::optional<T>::argument_type = const rapidjson::GenericDocument<rapidjson::UTF8<> >&]’
/home/tomkent/tmp/modern-cmake-sample/libjsonutils/src/json_utils.cpp:20:16: required from here
/home/tomkent/tmp/rapidjson/include/rapidjson/document.h:1902:5: error: ‘rapidjson::GenericDocument<Encoding, Allocator, StackAllocator>::GenericDocument(const rapidjson::GenericDocument<Encoding, Allocator, StackAllocator>&) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>; StackAllocator = rapidjson::CrtAllocator]’ is private
GenericDocument(const GenericDocument&);
^
In file included from /home/tomkent/tmp/boost_1_55_0/boost/optional.hpp:15:0,
from /home/tomkent/tmp/modern-cmake-sample/libjsonutils/include/jsonutils/json_utils.h:5,
from /home/tomkent/tmp/modern-cmake-sample/libjsonutils/src/json_utils.cpp:1:
/home/tomkent/tmp/boost_1_55_0/boost/optional/optional.hpp:346:8: error: within this context
new (m_storage.address()) internal_type(val) ;
^
CMakeFiles/jsonutils.dir/build.make:62: recipe for target 'CMakeFiles/jsonutils.dir/src/json_utils.cpp.o' failed
make[2]: *** [CMakeFiles/jsonutils.dir/src/json_utils.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/jsonutils.dir/all' failed
make[1]: *** [CMakeFiles/jsonutils.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
tomkent@frink:~/tmp/modern-cmake-sample/libjsonutils/build$
tomkent@frink:~/tmp/modern-cmake-sample/libjsonutils/build$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.6) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I am not sure how to solve CMP0048 CMake warning, does anyone know how to solve this?
See below:
/snap/clion/61/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE= -G "CodeBlocks - Unix Makefiles" /home/jonb/Projects/cmake-test/modern-cmake-sample/libjsonutils
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- regex
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jonb/Projects/cmake-test/modern-cmake-sample/libjsonutils/googletest-download
[ 11%] Performing update step for 'googletest'
Current branch master is up to date.
[ 22%] No configure step for 'googletest'
[ 33%] No build step for 'googletest'
[ 44%] No install step for 'googletest'
[ 55%] No test step for 'googletest'
[ 66%] Completed 'googletest'
[100%] Built target googletest
CMake Warning (dev) at googletest-src/CMakeLists.txt:3 (project):
Policy CMP0048 is not set: project() command manages VERSION variables.
Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
The following variable(s) would be set to empty:
PROJECT_VERSION
PROJECT_VERSION_MAJOR
PROJECT_VERSION_MINOR
PROJECT_VERSION_PATCH
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jonb/Projects/cmake-test/modern-cmake-sample/libjsonutils
[Finished]
after building the lib, I wanted to compile the example, but upon putting cmake .. in a build directory, I got
`CMake Error at /usr/share/cmake-3.5/Modules/CMakeFindDependencyMacro.cmake:45 (message):
Invalid arguments to find_dependency
Call Stack (most recent call first):
/usr/local/lib/cmake/JSONUtils/JSONUtilsConfig.cmake:5 (find_dependency)
CMakeLists.txt:6 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/me/tempRepos/modern-cmake-sample/example_exec/build/CMakeFiles/CMakeOutput.log".
`
what seems to be the problem here?
If I have understood this correctly, this line
should use ${CMAKE_INSTALL_INCLUDEDIR}
instead of hard-coded include
. There are systems which don't use include
for that, for example Haiku which uses develop/headers
instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.