Build xlnt library on Windows x64 - c++

I try build xlnt library from rep
https://github.com/tfussell/xlnt on Windows x64 using cmake:
cmake -G "MinGW Makefiles"
and get errors:
CMake Error at cmake/xlnt.cmake:70 (add_library):
Cannot find source file:
../third-party/miniz/miniz.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:74 (include)
CMake Error: CMake can not determine linker language for target: xlnt.shared
CMake Error: Cannot determine link language for target "xlnt.shared".
I am beginner in cmanke, but in directory nessessry file containts:
xlnt\third-party\miniz.c
What can I do for desition this building problem?
Thanks for answer
Issue on github: https://github.com/tfussell/xlnt/issues/57

I sucessfly compile the library:
TODO:
Edit "cmake/xlnt.cmake": change path form../ to./
SET(MINIZ ./third-party/miniz/miniz.c ./third-party/miniz/miniz.h)
SET(PUGIXML ./third-party/pugixml/src/pugixml.hpp ./third-party/pugixml/src/pugixml.cpp ./third-party/pugixml/src/pugiconfig.hpp)
I think that is path-bug. I issued in project about it.
cmake -G "NMake Makefiles" - .configure for VS compiler
nmake - compile by VS compiler

Related

CMake Error at CMakeLists.txt:4 (add_executable)

I am trying to build a simple CNN model using Pytorch C++ API ( libtorch ), but when I try to run CMake it gives me this error:
CMake Error at CMakeLists.txt:4 (add_executable):
Cannot find source file:
training_VGG.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: example
CMake Error: Cannot determine link language for target "example".
----------------------------------------------------------------------------
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(Digit-Recognition-MNIST)
find_package(Torch REQUIRED)
add_executable(example training_VGG.cpp)
target_link_libraries(example "${TORCH_LIBRARIES}")
set_property(TARGET example PROPERTY CXX_STANDARD 11)
I hope anyone can help me.

How to add library to C++ Project using homebrew, cMake and, cLion

I am really new to C++ and I am a bit confused.
I am trying to add this lib to my project (https://github.com/mrtazz/restclient-cpp).
I have installed it using Homebrew
brew tap mrtazz/oss
brew install restclient-cpp
then I tried adding the library to my CMakeLists by including and linking the Homebrew install directories.
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(POS)
set(CMAKE_CXX_STANDARD 14)
include_directories(/usr/local/include)
link_directories(/usr/local/lib)
add_library(
restclient-cpp STATIC
connection.h
helpers.h
restclient.h
version.h
)
add_executable(POS main.cpp program.cpp program.h programs/find.cpp programs/find.h tools/db.cpp tools/db.h)
target_link_libraries(POS PUBLIC restclient-cpp)
then I get this error...
CMake Error at CMakeLists.txt:16 (add_library):
Cannot find source file:
connection.h
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error at CMakeLists.txt:16 (add_library):
No SOURCES given to target: restclient-cpp
I know something is wrong with the directories but I just cannot figure it out, I would greatly appreciate as much information as possible. I'm just trying to have some fun with this and I cannot figure out why I cannot add this simple library to my build.
Thank you.
You are trying to add header files to the add_library command. Those files need to be in a directory that you include via include_directory. You also should not put header files into the add_executable command.
To link an existing library you can call target_link_libraries.
example:
include_directories(${MY_INCLUDE_DIRS})
add_executable(main source.cpp)
target_link_libraries(main extlib)
It's probably best to find a simple CMake setup and try to use it as template.

cmake: "add_custom_target" + PRE_BUILD didn't take effect while building

I've using cmake to build my google rpc sample code. I've got
examples.proto
client.cpp
server.cpp
I use protoc command to build out .cc/.h files for both protobuf and grpc, CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++11)
include_directories(.)
add_custom_target(protoFile
PRE_BUILD
COMMAND protoc --cpp_out=./ examples.proto
)
add_custom_target(protoSource
PRE_BUILD
COMMAND protoc --grpc_out=./ --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin examples.proto
)
add_dependencies(protoSource protoFile)
add_library(protoCpp SHARED examples.grpc.pb.cc examples.pb.cc)
add_dependencies(protoCpp protoSource)
link_libraries(protoCpp protobuf grpc grpc++)
add_executable(client client.cpp)
add_executable(server server.cpp)
And then:
cmake .
-- Configuring done
CMake Error at CMakeLists.txt:15 (add_library):
Cannot find source file:
examples.grpc.pb.cc
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: protoCpp
CMake Error: Cannot determine link language for target "protoCpp".
-- Generating done
Seems my "add_custom_target()" was not executed, and "ls" didn't show any files I expected. So how to make them executed? I already added "protoSource as dependency for "protoCpp" library, but didn't work.
How to solve this?
Use add_custom_target after add_executable, and the first parameter should be a target created by add_executable, in your example "client" or "server". You can't use PRE_BUILD in add_custom_target, but I'm not sure;
See also: add_custom_target documentation.

cmake: add_dependencies does not work with external projects

Consider the following CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(xyz)
include(ExternalProject)
set(EXTSRC ${CMAKE_SOURCE_DIR}/external)
ExternalProject_Add(q
GIT_REPOSITORY
"https://github.com/sftrabbit/CppSamples-Samples.git"
SOURCE_DIR ${EXTSRC}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "")
add_executable(xyzbin
${EXTSRC}/1-common-tasks/ranges/range-iteration.cpp)
add_dependencies(xyzbin q)
I would expect that the external project files was downloaded first and then my executable target starts to be configured. However, this is not the case.
When I run "cmake .." in a build directory inside the source directory, it yields:
(usual configure stuff above ....)
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:16 (add_executable):
Cannot find source file:
/home/janberq/Desktop/cmake_problem/external/1-common-tasks/ranges/range-iteration.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: xyzbin
CMake Error: Cannot determine link language for target "xyzbin".
-- Generating done
-- Build files have been written to: /home/janberq/Desktop/cmake_problem/build
It seems like, cmake first tries to acquire linker language, which isn't possible in that case as I don't have source files.
I tried adding,
set_target_properties(xyzbin PROPERTIES LINKER_LANGUAGE CXX)
But it didn't work at all, unfortunately. What can I do to fix that error?
P.S. my cmake version is 3.5.2, os: ubuntu 16.10.
ExternalProject_Add adds a target. It won't do anything until you do a make.
To download the repository before configuring, you have to explicitly tell CMake to do so. Or you could create a setup.sh script downloading dependencies and (possibly) running cmake right after.

CMake problems with CLion - Error:Cannot determine link language for target "XYZ"

Starting up CLion outputs me the following:
Error:Cannot find source file:
sinclude/MathCompiler.h
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
Error:CMake can not determine linker language for target: MathCompiler
Error:Cannot determine link language for target "MathCompiler".
Warning:Configuration Debug
Unable to determine product file path for target MathCompiler (Debug). Running and debugging will be unavailable.
Warning:Configuration Release
Unable to determine product file path for target MathCompiler (Release). Running and debugging will be unavailable.
Warning:Configuration RelWithDebInfo
Unable to determine product file path for target MathCompiler (RelWithDebInfo). Running and debugging will be unavailable.
Warning:Configuration MinSizeRel
Unable to determine product file path for target MathCompiler (MinSizeRel). Running and debugging will be unavailable.
I didn't change anything since the last build.
Here is CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(MathCompiler)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp cpp/MathCompiler.cpp include/MathCompiler.h cpp/MathException.cpp include/MathException.h cpp/MathematicString.cpp include/MathematicString.h include/str_cmp.h include/typedefs.h)
add_executable(MathCompiler ${SOURCE_FILES})
.h-files usually aren't included into the list of source files