Comments (7)
Using DOCOPT_INCLUDE_DIRS
and DOCOPT_LIBRARIES
would be the old-school way of using CMake.
The modern way is to just pass docopt
(or docopt_s
) to target_link_libraries()
:
find_package(docopt REQUIRED)
target_link_libraries(myprogram PUBLIC docopt)
The include directories will be added automatically because they're set as properties on the docopt
library target.
from docopt.cpp.
I have just found of that this fails when I make using:
cmake /path/to/docopt.cpp -DCMAKE_INSTALL_PREFIX:PATH=$HOME/opt
make install
as ${DOCOPT_INCLUDE_DIRS}
is then empty.
from docopt.cpp.
I have found the solution (see also below). But it would be great if this would be better documented (I edited the title accordingly).
cmake_minimum_required(VERSION 3.1)
# define a project name
project(test)
# define empty list of libraries to link
set(PROJECT_LIBS "")
# set optimization level
set(CMAKE_BUILD_TYPE Release)
# set C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# load DOCOPT
find_package(docopt REQUIRED)
include_directories(${DOCOPT_INCLUDE_DIRS})
# create executable
add_executable(${PROJECT_NAME} main.cpp)
# link libraries
target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS} docopt)
from docopt.cpp.
I have the following install structure:
$ tree
.
├── include
│ └── docopt
│ ├── docopt.h
│ ├── docopt_private.h
│ ├── docopt_util.h
│ └── docopt_value.h
├── lib
│ ├── cmake
│ │ └── docopt
│ │ ├── docopt-config-version.cmake
│ │ ├── docopt-config.cmake
│ │ ├── docopt-targets-debug.cmake
│ │ ├── docopt-targets-release.cmake
│ │ └── docopt-targets.cmake
│ ├── libdocopt.0.6.2.dylib
│ ├── libdocopt.0.dylib
│ ├── libdocopt.a
│ ├── libdocopt.dylib
│ ├── libdocoptd.0.6.2.dylib
│ ├── libdocoptd.0.dylib
│ ├── libdocoptd.a
│ ├── libdocoptd.dylib
│ └── pkgconfig
│ └── docopt.pc
└── licenses
└── docopt
├── LICENSE-Boost-1.0
└── LICENSE-MIT
But when I use the package, I get docopt
library target, but DOCOPT_INCLUDE_DIRS
is empty. Moreover, there is no output for grep docopt_include * -nri
from docopt.cpp.
My CMakeLists (tried with both the commented version and the uncommented versions)
# find_package (docopt REQUIRED)
find_package (docopt COMPONENTS CXX REQUIRED)
message (STATUS ${DOCOPT_INCLUDE_DIRS})
add_executable (intro src/main.cpp)
#target_link_libraries (intro doctopt)
target_link_libraries (intro PUBLIC doctopt)
${DOCOPT_ROOT}
is set and docopt
target is available. But I get the error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.14 -std=c++1z -MD -MT CMakeFiles/intro.dir/src/main.cpp.o -MF CMakeFiles/intro.dir/src/main.cpp.o.d -o CMakeFiles/intro.dir/src/main.cpp.o -c ../src/main.cpp
../src/main.cpp:1:10: fatal error: 'docopt.h' file not found
#include <docopt.h>
Same issue if I use docopt/
since the header path isn't in the command invocation.
from docopt.cpp.
I got this error when compiling the example code given in the Readme page. Can I get some help please?
docoptest.cpp:9:10: fatal error: docopt.h: No such file or directory 9 | #include <docopt.h> | ^~~~~~~~~~
I installed docopt following the manual installation steps through CMake. I have to say that I don't know much about CMake I just installed it this way:
sudo apt install cmake # then install docopt git clone cmake . make install
from docopt.cpp.
So on arch find_package
is borked, because arch doesn't ship static libs. I ended up using pkgconfig in the end, and for that modern PkgConfig::docopt, also didn't work for me. I'll paste that here, in case someone gets as confused as I do.
find_package(PkgConfig REQUIRED)
pkg_check_modules(DOCOPT REQUIRED docopt)
include_directories(${DOCOPT_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} ${DOCOPT_LIBRARIES})
from docopt.cpp.
Related Issues (20)
- CMake Windows: install *.dll in the correct location HOT 1
- Feature Request: Please support default that picks up value from environment variable HOT 3
- Better CMake
- New release proposal HOT 5
- Unable to add short version of option HOT 10
- Suggestion: docopt::value to provide a `represent` method rather than overloading operator<< for std::ostream HOT 1
- Crash in 0.6.3 HOT 3
- Visual Studio 2015 link error in example for ostream output operator of value HOT 2
- replacing std::regex with ctre HOT 3
- Packaging for Debian is incorrect. Should be splitted into multiple packages using CPackComponent and renamed for debian into libdocopt-dev and libdocopt HOT 2
- Compile time parse usage
- Argument names with characters other than letters (like underscores or numbers) don't work HOT 1
- Using optional args out of order leads to wrong values all around HOT 2
- MSAN Warning on use-of-initialized-value in docopt::docopt_parse HOT 2
- Update vcpkg port
- Should docopt::Options be an std::unordered_map? HOT 2
- Missing support for comments HOT 2
- Unclear/undocumented value interface. HOT 4
- Unused variable in `Option::parse`
- Version 0.6.3 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docopt.cpp.