Am 17.07.19 um 15:38 schrieb hex:

hello community,

I am receiving a|fatal error: foobar_version.h: No such file or directory|for|foobar_version.h|. The reason is that the source file is generated in|${CMAKE_CURRENT_BINARY_DIR}/foobar_version.cpp|while the header file is in|${CMAKE_CURRENT_SOURCE_DIR}|as seen here:

1234|configure_file(foobar_version.cpp.in foobar_version.cpp @ONLY) # configure_file(foobar_version.h foobar_version.h @ONLY) add_library(foobar_version STATIC ${CMAKE_CURRENT_BINARY_DIR}/foobar_version.cpp) |//

In the source I simply|#include "foobar_version.h"|but the file is in a different location.

Why is this|CMakeLists.txt|file placing the files in different locations? What should I do about it?

Nothing. You really want to keep source and build directories seperate, which means you do not want to generate files into the source directory. Instead, add the CMAKE_CURRENT_SOURCE_DIR to the include search path of any target that needs to include foobar_version.h using any one of:

1) the include_directories command
2) the target_include_directories command
3) the CMAKE_INCLUDE_CURRENT_DIR variable

------------------------------------------------------------------------

also, what is the purpose of|mylib.cpp|, I had to create it otherwise I receive:|No SOURCES given to target: fooToolkit|. The build is successful but my file is currently empty. Here are all build steps:

123456789|configure_file(foobar_version.cpp.in foobar_version.cpp @ONLY) configure_file(foobar_version.h foobar_version.h @ONLY) add_library(foobar_version STATIC ${CMAKE_CURRENT_BINARY_DIR}/foobar_version.cpp) add_executable(foobar main.cpp) target_link_libraries(foobar PRIVATE foobar_version) add_library(fooToolkit mylib.cpp) target_link_libraries(fooToolkit PRIVATE foobar_version) |//
------------------------------------------------------------------------
I'm not sure what you are trying to accomplish with the fooToolkit target. If you want to create a library without sources for its properties (because you have a header-only library, for example), the correct way is to create an INTERFACE library, like so:

add_library(fooToolkit INTERFACE)

As a final note, I would strongly suggest you read the fine manual when you get errors from CMake - the documentation is actually pretty good when used as a reference and would have answered both of your questions.
--

*Dr. Eric Dönges *
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
doen...@mvtec.com <mailto:doen...@mvtec.com> | Tel: +49 89 457 695-0 | www.mvtec.com <http://www.mvtec.com>

Sign up <http://www.mvtec.com/newsletter> for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

MVTec Software GmbH Logo
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to