I'm trying to make my cmake project automatically compile but I have some difficulties when my path contains spaces.
Here is my command line (windows command prompt)
C:\Code\codetrainerplugins-build>type %CODETRAINER_PATH%\include\common\exportapi.h
#pragma once
... the file is found ...
Here is my CMakeLists.txt file:
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
PROJECT (CodeTrainerPlugins)
MESSAGE("$ENV{CODETRAINER_PATH}")
FIND_PATH (CODETRAINER_FRAMEWORK_PATH
NAMES include/common/ExportApi.h
PATHS
ENV CODETRAINER_PATH
)
if (CODETRAINER_FRAMEWORK_PATH)
MESSAGE(STATUS "CodeTrainer Framework found at: ${CODETRAINER_FRAMEWORK_PATH}")
else()
MESSAGE(FATAL_ERROR "CodeTrainer Framework not found")
endif()
ADD_SUBDIRECTORY(function)
ADD_SUBDIRECTORY(test)
Here is the output when CODETRAINER_PATH variable contains spaces (see the space in the path):
C:\Code\codetrainerplugins-build>echo %CODETRAINER_PATH%
"C:\Code Trainer"
C:\Code\codetrainerplugins-build>
C:\Code\codetrainerplugins-build>cmake ..\codetrainerplugins
-- Building for: Visual Studio 10
"C:\Code Trainer"
CMake Error at CMakeLists.txt:16 (MESSAGE):
CodeTrainer Framework not found
-- Configuring incomplete, errors occurred!
See also "C:/Code/codetrainerplugins-build/CMakeFiles/CMakeOutput.log".
C:\Code\codetrainerplugins-build>
But when the path used has no spaces everything works ok (see below):
C:\Code\codetrainerplugins-build>echo %CODETRAINER_PATH%
C:\CodeTrainer
C:\Code\codetrainerplugins-build>cmake ..\codetrainerplugins
C:\CodeTrainer
-- CodeTrainer Framework found at: C:/CodeTrainer
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Code/codetrainerplugins-build
C:\Code\codetrainerplugins-build>
Do you have any solution on how to solve this issue?
I am using cmake 2.8.12 for Windows.
Thanks,
Iulian
I must admit, I would have expected this to "just work" too, however it looks like it's actually the quotation marks in CODETRAINER_PATH when it has spaces that are the cause of the problem.
Either don't add quotes when defining the environment variable CODETRAINER_PATH, or modify your CMake code something like this:
STRING(REPLACE "\"" "" CODETRAINER_PATH_WITHOUT_QUOTES $ENV{CODETRAINER_PATH})
FIND_PATH(CODETRAINER_FRAMEWORK_PATH
NAMES include/common/ExportApi.h
PATHS ${CODETRAINER_PATH_WITHOUT_QUOTES}
)
Related
I am using google-test(gtest) with CMake and running the unit tests as GitHub ci jobs for Linux and Mac. The Linux jobs pass successfully. However, I am getting an error for the mac runner.
The error is
CMake Error at /usr/local/Cellar/cmake/3.21.1/share/cmake/Modules/GoogleTestAddTests.cmake:77 (message):
Error running test executable.
Path: '/Users/runner/work/splitwebp/build/test/splitwebp_tests'
Result: Process terminated due to timeout
Output:
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.21.1/share/cmake/Modules/GoogleTestAddTests.cmake:173 (gtest_discover_tests_impl)
This is the CMakelists.txt for the tests directory
# CMake config file for unit tests
# Requiring V 3.10 for gtest_discover_tests
cmake_minimum_required(VERSION 3.10)
find_package(OpenCV REQUIRED)
enable_testing()
# finds all .cpp files under this directory (./test) and add them to executable
file(GLOB_RECURSE tests "*.cpp")
file(GLOB_RECURSE source "../src/*.cpp")
add_executable(splitwebp_tests ${tests} ${source})
include_directories("../3rdparty/libwebp/include")
# Link gtest libraries
target_link_libraries(splitwebp_tests ${OpenCV_LIBS})
target_link_libraries(splitwebp_tests webp webpdemux pthread)
target_link_libraries(splitwebp_tests gtest_main)
set(CTEST_OUTPUT_ON_FAILURE 1)
# Find all tests in all .cpp files and convert to CTests
include(GoogleTest)
gtest_discover_tests(splitwebp_tests)
How do I fix the CI pipeline?
The problem is gtest_discover_tests(...) is taking too long and thus getting timed out. The obvious solution is to increase the timeout limit.
The line
gtest_discover_tests(splitwebp_tests)
can be replaced with
gtest_discover_tests(splitwebp_tests PROPERTIES TIMEOUT 600)
I am trying to create a Windows installer using CPACK and NSIS. I am using Windows 10, CMake GUI, NSIS, and Visual Studio Community Edition.
It works great except that I can't find the options so that the default install location will be:
C:\package-version.patch (e.g. C:\apbs-3.0)
The apbs software is a collaboration effort and is cross platform but it does not like "spaces" in pathnames so the default location for NSIS on Windows 10 x64 is:
C:\Program Files\package version (e.g. C:\Program Files\apbs 3.0\)
The closest I have gotten to is:
C:\\apbs 3.0
using the following configuration:
string(TOLOWER ${PROJECT_NAME} PACKAGE_NAME)
set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
set(CPACK_PACKAGE_DESCRIPTION "${PACKAGE_DESC}")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../LICENSE.md")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGING_INSTALL_PREFIX "${PACKAGE_NAME}")
set(CPACK_PACKAGE_VERSION "${APBS_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VENDOR "${VENDOR}")
set(CPACK_PACKAGE_CONTACT "${CONTACT}")
set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${APBS_VERSION}")
set(CPACK_STRIP_FILES ON)
if(WIN32)
# From: https://martinrotter.github.io/it-programming/2014/05/09/integrating-nsis-cmake/
list(APPEND CPACK_GENERATOR "NSIS")
set(CPACK_PACKAGING_INSTALL_PREFIX "\\\\${PACKAGE_NAME}-${APBS_VERSION}")
set(CPACK_NSIS_INSTALL_ROOT "C:\\\\")
endif()
include (CPack)
Is there a magic/undocumented set of CPACK variables to eliminate the extra '\' and replace the "space" with a '-' so that I can get the default install to be?
C:\apbs-3.0\
The following got me the install directory, C:\APBS-3.0.0
set(CMAKE_MAJOR_VERSION "3")
set(CMAKE_MINOR_VERSION "0")
set(CMAKE_MICRO_VERSION "0")
set(PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
set(CPACK_PACKAGE_DESCRIPTION "APBS - Adaptive Poisson Boltzmann Solver")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../LICENSE.md")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_SOURCE_IGNORE_FILES "${PROJECT_BINARY_DIR};/.git/;.gitignore")
set(CPACK_PACKAGE_VERSION_MAJOR "${CMAKE_MAJOR_VERSION}")
set(CPACK_PACKAGE_VERSION_MINOR "${CMAKE_MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_MICRO_VERSION}")
set(CPACK_PACKAGE_VENDOR "PNNL")
set(CPACK_PACKAGE_CONTACT "APBS - https://github.com/Electrostatics/apbs-pdb2pqr")
set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${APBS_VERSION}")
set(CPACK_STRIP_FILES ON)
if(WIN32)
# From: https://martinrotter.github.io/it-programming/2014/05/09/integrating-nsis-cmake/
SET(CPACK_NSIS_PACKAGE_NAME "${PACKAGE_NAME}-${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_MICRO_VERSION}")
SET(CPACK_NSIS_DISPLAY_NAME "${PACKAGE_NAME}-${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_MICRO_VERSION}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${PACKAGE_NAME}-${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_MICRO_VERSION}")
SET(CPACK_NSIS_INSTALL_ROOT "C:")
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${PACKAGE_NAME}-${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
list(APPEND CPACK_GENERATOR "NSIS")
endif()
Hopefully this can help others looking for similar solutions.
I have a gRPC 1.23.0 compiled by conan(and all dependencies also resolved by conan).
And I have a CMake project, that use grpc library:
set (LIB_DEPS
protobuf::libprotobuf
gRPC::grpc++
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_DEPS})
When I generate a VS project from this CMakeLists.txt in Linker - Input - Addition Dependencies property, I have there next value:
C:\.conan\data\protobuf\3.9.1\kpa_conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\lib\libprotobufd.lib <-- (1)
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\grpc++.lib
libprotocd.lib <-- (2)
libprotobufd.lib <-- (3)
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\grpc.lib
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\gpr.lib
C:\.conan\data\c-ares\1.15.0\kpa_conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\lib\cares.lib
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\address_sorting.lib
wsock32.lib
kernel32.lib
(1) - expected valid path, that I add in CMakeLists.txt
(2),(3) - unexpected and invalid path, that added by gRPC::grpc++ in CMakeLists.txt.
If I change gRPC::grpc++ to gRPC::grpc, lines (2) and (3) will disappear, but path to grpc++.lib will disappear too, but I need it.
How to avoid this strange invalid path to libprotocd.lib and libprotobufd.lib?
To properly link against grpc targets you can use:
target_link_libraries(${PROJECT_NAME} PUBLIC CONAN_PKG::grpc)
This should contain everything required.
More details on this approach here: https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#targets-approach
I have found workaround solution:
find_library(GRPC_GRPC++_LIBRARY NAMES grpc++)
set (LIB_DEPS
protobuf::libprotobuf
gRPC::grpc
${GRPC_GRPC++_LIBRARY NAMES}
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_DEPS})
And opened the issue about it in gRPC repository: https://github.com/grpc/grpc/issues/20578
I am trying to compile my code with nana gui library using Biicode.
https://www.biicode.com/qiangwu/qiangwu/nana/master/0/biicode.conf
# Biicode configuration file migrated from old config files
[requirements]
qiangwu/nana: 0
[parent]
[paths]
[dependencies]
include/nana/config.hpp + build/cmake/config.hpp
[mains]
[hooks]
[includes]
[data]
After command bii build
Output is:
H:\na4\nana>bii build
INFO: Processing changes...
WARN: user/nana/biicode.conf, [dependencies] include/nana/config.hpp + build/cmake/config.hpp
There are no files matching pattern include/nana/config.hpp
Building: "cmake" --build .
BLOCK: qiangwu/nana
-----------------------------------------------------------
CMake Error at H:/na4/nana/bii/deps/qiangwu/nana/CMakeLists.txt:19 (list):
list sub-command REMOVE_ITEM requires two or more arguments.
Error copying file (if different) from "H:/na4/nana/bii/deps/qiangwu/nana/build/cmake/config.hpp" to "H:/na4/nana/bii/deps/qiangwu/nana/include/nana/".
+ LIB: qiangwu_nana
BLOCK: user/nana
-----------------------------------------------------------
+ LIB: user_nana
+ EXE: user_nana_main
-- Configuring incomplete, errors occurred!
See also "H:/na4/nana/bii/build/CMakeFiles/CMakeOutput.log".
See also "H:/na4/nana/bii/build/CMakeFiles/CMakeError.log".
mingw32-make.exe: *** [cmake_check_build_system] Error 1
ERROR: Build failed
CmakeLists.txt:
if(NOT BIICODE)
project(nana)
cmake_minimum_required(VERSION 2.8)
else()
set(LIB_SRC ${BII_LIB_SRC})
foreach(cpp ${BII_LIB_SRC})
if(${cpp} MATCHES "(include/nana|source)/detail/[A-Za-z0-9_]+/.+$")
list(APPEND trash_files ${cpp})
endif()
endforeach()
list(REMOVE_ITEM BII_LIB_SRC ${trash_files})
endif()
Line 19 is : " list(REMOVE_ITEM BII_LIB_SRC ${trash_files})"
It seems it is not biicode related, but CMake related. Your ${trash_files} variable is actually empty, and then the REMOVE_ITEM list function fails. Check this code in a regular CMakeLists.txt:
SET(MY_VAR a b c)
SET(TRASH_FILES )
SET(MY_LIST a b c d)
foreach(cpp ${MY_VAR})
if(${cpp} MATCHES d)
list(APPEND trash_files ${cpp})
endif()
endforeach()
list(REMOVE_ITEM MY_LIST ${trash_files})
If you think that a variable might be empty in such operations, protect that code with a conditional:
if(trash_files)
list(REMOVE_ITEM MY_LIST ${trash_files})
endif()
Resently it was an update addresing this.
In GitHub you will need to use the branch develop
Hi everyone I would like to try the openCV library but I have some problems setting up the environment.
From the property Manager I created a new sheet and set:
VC++ Directories :
- Include Directories: $(OPENCV_DIR)\build\x86\vc10\bin and $(OPENCV2_DIR)\build\include
- Library Directories: $(OPENCV2_DIR)\build\x86\vc10\lib;
C/C++ :
- Additional Includes Directories: $(OPENCV2_DIR)\include;
Linker:
opencv_calib3d244d.lib opencv_contrib244d.lib opencv_core244d.lib
opencv_features2d244d.lib opencv_flann244d.lib opencv_gpu244d.lib
opencv_haartraining_engined.lib opencv_highgui244d.lib
opencv_imgproc244d.lib opencv_legacy244d.lib opencv_ml244d.lib
opencv_nonfree244d.lib opencv_objdetect244d.lib opencv_photo244d.lib
opencv_stitching244d.lib opencv_ts244d.lib opencv_video244d.lib
opencv_videostab244d.lib
-Additional Library Directories: $(OPENCV2_DIR)\libs
I can compile but i can't execute the program because I get an error opencv_core242.dll is missing.
Where's my error? Thanks
"I get an error opencv_core242.dll is missing"
if you linked against the libs in opencv\build\x86\vc10\lib (your compiler/linker settings look ok),
you'll have to append
opencv\build\x86\vc10\bin
to your PATH environment variable, so your exe can find the dlls at runtime.