Creating filters for Lua files in VS using CMake's source_group

I've been able to easily get all my headers and source files organized using filters like so: source_group(Source\ Files\\network FILES network/lobbylist.cpp network/network.cpp network/networkenet.cpp network/networkfactory.cpp network/networklinux.cpp network/networkraw.cpp network/networkwin.cpp ) However, today I started adding Lua scripts to my project and found that, although no errors were displayed during project generation and everything seemed to be spelled correctly, CMake didn't

Does Cmake handle recursive builds correctly

I am currently looking at replacements for the old make system for some projects. One of the alternatives I am currently looking at is cmake. However from what I know so far, CMake prefers to have one configuration file for each directory, similar to what Autotools and others prefer as well. I know that recursive make should be considered harmfull, because not the whole dependency graph is know at all times (see the paper for details). For that reason other tools, which rely on recursive make,

catch return value in CMake add_custom_command?

how do I grab the return value of command invoked by add_custom_command? I thought I could do something like this, macro(mac param1) execute_process(COMMAND process ${param1} RESULT_VARIABLE res_var) if(${res_var} .... endmacro(mac) add_custom_command(COMMAND mac(param1)) but that won't work. I found out that even a plain macro(mac) endmacro() add_custom_command(COMMAND mac()) does not work. Upon building, sh complains: /bin/sh: 1: Syntax error: end of file unexpected or, if

unable to include a ui_form header of QT5 in cmake

My CMakeLists.txt looks something like : cmake_minimum_required(VERSION 2.8) if(CMAKE_BUILD_TYPE STREQUAL Release) SET(CMAKE_BUILD_TYPE Release) SET (PROJECT_NAME location_recognition) message("Release mode") else() SET(CMAKE_BUILD_TYPE Debug) SET (PROJECT_NAME location_recognition) SET(CMAKE_CXX_FILES "-g -Wall") message("Debug mode") endif() #find QT libraries find_package(Qt5Widgets REQUIRED) find_package(Qt5Core REQUIRED) find_package(Qt5Gui REQUIRED) FIND_PACKAGE(OpenCV R

Cmake How to clear/delete a cache variable

Trying to get find_path to do what I want. find_path(temmp include/help.h) message("temmp= ${temmp}") help.h is found. The output is temmp= /usr/local/toolA find_path(temmp include/foo.shoe) message("temmp= ${temmp}") foo.shoe does not exist (not found). The output is temmp= /usr/local/toolA The cache variable exists, so the variable (temmp) is untouched. I try and clear the cache var with this: set (temmp "" CACHE INTERNAL "") find_path(temmp include/help.h) message("temmp= ${temmp}"

Cmake Adding a test project to supplement an existing project

I am currently helping to migrate a group of visual studio projects to use CMake. Currently all the projects have been migrated and are building successfully. However, we have yet to re-incorporate our unit tests. Is there a way to create a separate executable for unit tests without having to recompile all the source files of the dependent project? In other words, is there a simple way to allow the test project to link to object files produced by the dependent project? Here is an example st

Cmake does not configure the files

I'm trying to create a CMakeLists.txt to configure some files but it is not working properly, here is my code, set (MDIR "${CMAKE_INSTALL_PREFIX}/share/models") configure_file ( "include/CLMParameters.h.in" "${PROJECT_BINARY_DIR} /CLMParameters.h" ) here is the code in the header file, # code .... wSizeCurrent = wSizeLarge; defaultModelLoc = @mdir@/main.txt; XLeftOffset = 100; XRightOffset = 100; # more code and so on I was expecting it to change @mdir@ to my defined path, but what I

Best way to check with CMake whether list containts a specific entry

I want to check whether a lists contains a specific entry like in the following code snipplet: macro(foo) if ($(ARGN} contains "bar") ... endif endmacro() CMake does not offer a contains. What is best / easiest way to get the desired result? In CMake's wiki I found a LIST_CONTAINS macro, but the wiki page is outdated. Is this still the best way to go or has CMake gained new capabilities?

CMake: how to create include path to generated include files

I have a project with about 600 directories, containing the source for about a dozen libraries and several dozen programs. Some of the programs depend upon a C++ header file that is generated from a text file. How do I cleanly tell CMake how to include that path to the generated header file into the include path for those source files which require it? Or alternatively, how can I force the generated file to be installed into a known location before CMake attempts to compile those programs?

Assimp with cmake

I want to include assimp to my project using CMake. I have Ubuntu 14.04 LTE and QTCreator. Project contain of main.cpp and linked libraries stored in libs directory. Main CMakeLists.txt cmake_minimum_required(VERSION 2.6) project(test) find_package(OpenGL REQUIRED) # libs contain external libaries add_subdirectory (libs) include_directories( libs/glfw-3.0.4/include libs/assimp-3.1.1/include/ ) set(allLibs ${GLFW_LIBRARIES} ${OPENGL_LIBRARY} GLEW_LIB assimp ) add_

How to control the order that CMAKE builds subdirectories when involving options?

I know that CMake automatically somehow figures out the dependency tree. It will build things in the right order normally. I decided to use options and that has caused it to guess poorly. I have a variant of this SO question following: /CMakeLists.txt /src/CMakeLists.txt /testpackage1/CMakeLists.txt /testpackage2/CMakeLists.txt In my case, mylib has two kinds -- a static and a dynamic. OPTION(MYLIB_BUILD_STATIC "Build static library" TRUE) IF(MYLIB_BUILD_STATIC) ADD_LIBRARY(my

Cmake Using Eigen Library in ROS Indigo

I am working on a project in ROS Indigo that requires using the Eigen libraries. According to indigo/Migration page on the ROS Wiki, the FindEigen.cmake module is now in the cmake_modules package. After following steps to add the cmake_modules package to the project's CMake.txt (via find_package) and adding a build dependency to the package.xml (< build_depend >cmake_modules< /build_depend >), I'm still having issues compiling the project. I've looked at various sources citing the

How to include Assimp with CMakeLists?

I'm unable to include the external library assimp into my project using CMakeLists. I got it working by doing: add_subdirectory(${CMAKE_SOURCE_DIR}/external/assimp-3.1.1-win-binaries) include_directories(${CMAKE_SOURCE_DIR}/external/assimp-3.1.1-win-binaries/include) target_link_libraries(MyProject assimp) but I don't want to use add_subdirectoy since it adds it to my IDE. (Visual Studios 2013) Why am I unable to just include the assimp include directory and link it with my project like thi

CMake slow with large projects

I have over a thousand Fortran and a dozen C source files which compile into a single executable (FHI-aims). The code is full of interdependencies making it difficult to break it up into auxiliary libraries. For some reason dependency scanning is slow - it takes over 10 seconds to report that no files have been modified. With a single Makefile that time is about 2 seconds. I'm using ifort and icc. I could upload my depend.make (2.0 M) if that's of help. Is there anything I could try to speed up

Add quotation mark in CMake string

I am using CMake to create and build my project solution. i am using the following command to add a post build event to copy a .tlb from the local bin to the program bin. ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD COMMAND xcopy /D /Y "${CMAKE_SOURCE_DIR}LocalBin\\example.tlb" "${CMAKE_SOURCE_DIR}ProgramBin\\$<CONFIGURATION>\\") When this adds the command to the project properties , it is added as xcopy /D /Y LocalBin\example.tlb ProgramBin\Debug\ However this gives me an er

cmake make cannot find -lprotocol

I have these files in the directory: CMakeLists.txt datalink.c datalink.h protocol.a protocol.h All these files were got from my teacher except CMakeLists.txt. #CMakeLists.txt cmake_minimum_required(VERSION 3.5) project(DataLinkSimulator) INCLUDE_DIRECTORIES(.) set(SOURCE_FILES datalink.c protocol.a datalink.h protocol.h) add_executable(DataLinkSimulator ${SOURCE_FILES}) target_link_libraries(DataLinkSimulator protocol.a) I run 'cmake .' in this directory, and it works. However, when I r

CMake/CPack: How to avoid top-level directory in zip files

I'm using cpack to create my zip file of my binaries. Everything works fine, but one thing is ugly. CPack always generate a top-level directory (with the name of the project and some other variables). Does anybody know how i can tell cpack to get rid of this auto toplevel directory? CMake: 3.4.x OS: Win7 x64 Thanks in advance Tonka

Cmake Clean copied files from external project

As a part of my build process I'm building the webserver lighttpd. The following CMakeLists.txt is working: include(ExternalProject) ExternalProject_Add( lighttpd URL ${PROJECT_SOURCE_DIR}/ext/lighttpd.tar.gz CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_OUTPUT_PATH}/lighttpd ) ExternalProject_Add_Step( lighttpd copy2bin COMMAND ${CMAKE_COMMAND} -E copy_directory ${EXTERNAL_OUTPUT_PATH}/lighttpd/sbin ${EXECUTABLE_OUTPUT_PATH} COMMAND ${CMAKE_COMMAND} -E copy_directory

cmake's ExternalProject_Add: how to set source, build and install directories

I want to use ExternalProject_Add function to install cmake enabled projects. I need to control the building and installation processes. More specifically, I want that cmake build and install in specific directories. There is an option to select a path where to put the source directory: SOURCE_DIR. Is there something equivalent for BUILD_DIR and INSTALL_DIR? I did not see anything alike. There is a PREFIX option: Root dir for entire project What does it mean exactly? An how does cmake's

force cmake specific sh path

I have incompatible sh.exe and make.exe in my path due to multiple toolchains for embedded development. I want to force use of the one not in my path. cmake used the wrong make (the one in the path) to check GCC functionnality and I could force the correct make with SET(CMAKE_MAKE_PROGRAM .../make.exe) How to do the same for sh.exe ?

Creating a findable shared library with cmake

I am rewriting libraries from hand-written Makefiles to using cmake. I am getting stuck at the point where I need to library library A from library B. I can find the libraries using find_package, but when they are being linked cmake complains about not having a rule for building the .so file because it is looking for it in the build directory instead of the installed directory. This is explained if I look at the /usr/lib/cmake/library/libraryConfigVersion.cmake file, which contains this hardco

Yocto Extensible SDK (eSDK) and CMake

This question is about getting find_package(Boost REQUIRED) in a CMakeLists.txt file to work in a Yocto SDK. I have the same question but for a Yocto Extensible SDK. CMake finds the compiler and linker just fine, but doesn't know where to find packages, such as Boost. I get messages such as Unable to find the requested Boost libraries. Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost'

CMake and configure_file: what if I need $ONLY instead of @ONLY?

As from the documentation of configure_file, it has an useful @ONLY parameter used to: Restrict variable replacement to references of the form @VAR@. This is useful for configuring scripts that use ${VAR} syntax. So far so good. Now I'm in the case where I've a file that contains both @FOO@ and ${BAR} and I want to replace S{BAR} with a variable that comes from my CMakeLists.tx. On the other side I don't want that configure_file tries to replace @FOO@. In other terms, I need something lik

TinyB's CMake script cannot find javah

I tried reinstalling TinyB from scratch: https://github.com/intel-iot-devkit/tinyb. When I run CMake in Ubuntu cmake -DBUILDJAVA=ON I get this error: INFO - libtinyb Version v0.5.0-dirty CMake Error at java/CMakeLists.txt:16 (message): Cannot locate javah executable. -- Configuring incomplete, errors occurred! See also "/home/ubuntu/Downloads/tinyb-master/CMakeFiles/CMakeOutput.log". See also "/home/ubuntu/Downloads/tinyb-master/CMakeFiles/CMakeError.log". My version of Java: java -ver

CMake rule to copy one of multiple identically-named files

Let's say we have a project like this: foo +-bar + +-header.h <-- copy if updated +-baz + +-header.h <-- copy if updated +-wibble + +-ni + +-header.h <-- copy if updated target +-header.h <-- to here We have three possible candidates for header.h, but one final location; we're not using symbolic links for reasons. Note that there are actually around 350 header files with just a few duplicates, so listing each individually is troublesome, especially if these subdirect

Cmake Doxygen - Could NOT find FLEX (missing: FLEX_EXECUTABLE)

I know there are very similar worded questions on here, but I could not find an answer to my question there, so here we go: I'm trying to see which of my C++ methods are called by others so I found Doxygen after googling. On their page the installation seems pretty straightforward: If you have the necessary build tools installed (i.e. g++, python, cmake, flex, bison), you should do the following to get the initial copy of the repository: git clone https://github.com/doxygen/doxyge

cmake windows x64 builds

Is there a way to use the cmake gui to specify a x64 build, since by default cmake on windows creates a 32-bit Visual Studio solution. From the command line, folks say to do this: C:\projectx\build> cmake ..\make -G "Visual Studio 10 Win64" but how do I get to the command line arguments from the cmake windows gui? see: http://www.saoe.net/blog/778/ How to build x86 and/or x64 on Windows from command line with CMAKE? cmake -G Ninja on windows specify x64

llvm cmake add_llvm_loadable_module unknown

I am an llvm beginner. I compiled llvm which checked from svn, and I got the error: unknown cmake command add_llvm_loadable_module when using cmake to create a makefile in llvmroot/lib/Transform/Hello/build. I have no idea why this occur. Is there something wrong when compiling llvm? In this case, I compiled llvm by cmake -G "Unix Makefiles" in macros. Thanks for your help.

How add include path to CMake?

I tried to add paths using: export PATH=<myPath> export CPPFLAGS='-I<myPath>' I tried to run make using the make -I=<myPath>. But make still does not see hpp files. CmakeLists: cmake_minimum_required(VERSION 2.4.6) include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) rosbuild_init() set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) rosbuild_genmsg() rosbuild_gensrv() rosbuild_add_executable(add_two_ints_server src/add_

CMAKE cannot identify .f90 as source code?

I am trying to use CMAKE to build a Fortran program The test source files include: TEST.cpp, A.f90, B.f90 The CMakeLists.txt: cmake_minimum_required(VERSION 3.1) enable_language(Fortran) aux_source_directory( ${CMAKE_SOURCE_DIR} SRC ) file(WRITE out.txt ${SRC} ) But the command aux_source_directory cannot identify the .f90 source files. I have used enable_language(Fortran) But only the TEST.cpp file can be identified ( output in out.txt ) How could the .f90 source files be identified

LightGBM Installation issue on cmake

I would like to download LightGbm and i followed this website for doing it. But suddenly stopped with an error. Please post a solution. Thankshttps://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#macos Error: cmake .. CMake Error at /usr/local/Cellar/cmake/3.13.0/share/cmake/Modules/CMakeDetermineCCompiler.cmake:48 (message): Could not find compiler set in environment variable CC: gcc-7. Call Stack (most recent call first): CMakeLists.txt:7 (PROJECT) CMake Error: CMAKE_C

CMake submodules dependencies

I have a CMake project with two submodules A and B. B depends on A. In submodule B I would like to search for A using find_package(A CONFIG). My minimal (not) working example would be: CMakeLists.txt cmake_minimum_required(VERSION 3.13) project(AB) add_subdirectory(B) add_subdirectory(A) A/CMakeLists.txt: message(STATUS "CMake: A") add_library(A SHARED A.hpp A.cpp) target_include_directories(A PUBLIC "${CURRENT_SOURCE_DIR}") install(TARGETS A EXPORT AA LIBRARY DESTINATIO

CMake: how to make execute_process wait for subdirectory to finish?

Part of my source code is generated by a tool which is also built under our main project with a add_subdirectory. We execute this tool with a execute_process command. Clearly, if the tool is not built before we reach the execute_process statement it will fail. I use a GLOB (file(GLOB...)) to find the source files generated. I do this because it is not possible to know beforehand how many files are generated, neither their names. How do I force cmake to wait for the subproject to be compiled be

Cmake Why -fPIC must be provided as definition, rather than compiler flag

In my CmakeLists.txt file I have had the line set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall") and with that, I run into the error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)." Then I accidentally found topic Error while compiling QT project in cmake where it was suggested to add the line add_definitions(-fPIC) And really, it seems to work. I have two questions: 1./ Is

a project A rely on shared library B, B rely on C, A don't rely on C, why I need to find_package and targe_link C in CMakelist.txt of A?

a project A rely on shared library B, B relies on third-party library C, A doesn't rely on C, why do I need to find_package C in CMakelist.txt of A? The third-party library C is PCL. The CMakelist.txt of shared library B. add_library(TdLib SHARED pcl_tools.cpp pcl_tools.h ) #PCL find_package(PCL 1.8 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) set(HEADER_FILES pcl_tools.h ) set_target_properties(TdLib PROPER

CMake build and install shared library from subdirectory before building main directory

Here is my source code structure: cd my_git_repo/ CMakeLists.txt src/ main.cpp mylibrary/ a.hpp b.hpp a.cpp b.cpp CMakeLists.txt Root CMakeLists.txt: cmake_minimum_required(VERSION 3.9) project(myexe CXX) add_subdirectory(src/mylibrary) find_library(mylib NAMES mylibrary.so PATHS "./src/mylibrary/mylibrary.so") add_executable(myexe src/main.cpp) target_link_libraries(myexe ${mylib}) mylibrary/CMakeLists.tx

Get all include folders from cmake executable

How can I get all include directories of my executable? I want to introduce cppcheck and I need to forward all include directories to cppcheck (also the include directories of the interface imported libraries). So for example I have add_executable(my_exe main.cpp) target_link_libraries(my_exe PRIVATE RapidJSON::RapidJSON) How can I get all corresponding include directories of my_exe, including the RapidJSON ones (e.g. ~/.conan/data/RapidJSON/1.1.0/a/b/package/x/include)? I tried following

Cmake How to get include directories from a target for use in add_custom_target?

I'm modeling dependencies with target_link_libraries, as is done in this blog post. target_link_libraries(Foo LibraryA LibraryB ) This is working great, but for various reasons I need to use add_custom_target to preprocess to a file through a custom command. The problem is, this custom target depends on the includes of LibraryA and LibraryB. I was really hoping to do the following like how target_link_libraries works (see the LibraryA and LibraryB bit): add_custom_target(Bar ALL

Cache existing CMake variable in Find-script?

I'm using CMake macros to extract the value of certain variables that I want to export as part of my Find-script: string(REGEX REPLACE "([0-9]+)\\.[0-9]+" "\\1" MY_PACKAGE_MAJOR_VERSION "${MY_PACKAGE_VERSION}" How do I cache this variable after determing its value with a macro? I've tried this: set(MY_PACKAGE_MAJOR_VERSION ${MY_PACKAGE_MAJOR_VERSION} CACHE STRING "Major version of my package.") But without FORCE, it detects that MY_PACKAGE_MAJOR_VERSION is already set, and wi

cpack (creating RPM) ignores CMAKE_INSTALL_RPATH (sets RPATH to empty string - rather than an explicit value)

I'm trying a fairly simple experiment using cpack. The aim is to create an RPM installer (using cpack) with a trivial executable which uses an external 3rd party shared library (called libSomeSharedLib.so). The structure I'd like the RPM to install is opt |_cmakeFindPackageTest |_bin |_cmakeFindPackageTest (an executable) |_lib |_libSomeSharedLib.so (the shared library) I want the executable's RPATH to be /opt/cmakeFindPackageTest/lib (to ensure it uses the installed shared lib).

Cmake Link libc statically

I am trying to make a static executable with CMake 3.15. I am building on Alpine Linux (hence with musl), and currently, my executable's ldd output is: # ldd my_executable /lib/ld-musl-x86_64.so.1 (0x7fc6f7977000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fc6f65b3000) libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fc6f7977000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fc6f659f000) I can set target_link_options(my_executable PRIVATE -static-libgcc -static-

Cmake Conan install fails: 'compiler not defined for compiler.libcxx'

Conan install fails with the message below. As I could follow, it is an issue since about 2018. I did follow some discussions, about changing configurations, defaults, profiles, promising discussion in the afternoon, etc., but did not see a solution that works. Is there any way I can use in my cmake file to fix it, or to downgrade to a stable version? I have chosen Conan because in this way my users can simply install my app. They do not want to bother (and even: they cannot) with maybe it wor

Is it safe to delete CMakeCache.txt before each incremental build?

My incremental CI builds frequently get: ##[error]CMake Error: Target xxx has dependency information when it shouldn't. ##[error]Your cache is probably stale. Please remove the entry xxx_LIB_DEPENDS from the cache. Is it safe to delete the cache file before each build? Will most build binaries be still up to date, or will this trigger a full rebuild?

Qt-Cretor + CMake insists on using MSVC when I want to use MinGW

I am trying to build a CMake project with MinGW. I have installed MinGW 8.1 through the Qt installer. The CMakeList is unchanged from how Qt Creator created it when creating the project. When running CMake, I can see how Qt Creator passes the compiler and linker's paths to CMake and how CMake completely ignores them. Führe C:\Program Files\CMake\bin\cmake.exe -S [snip] -B [snip] "-DCMAKE_BUILD_TYPE:String=Debug" "-DQT_QMAKE_EXECUTABLE:STRING=C:/Qt/5.15.1/mingw81_64/bin/qmake.exe&q

CMake add_custom_command() POST_BUILD generator expression expansion not working

I want to run a POST_BUILD action after the build (but only in the Debug configuration). After reading add_custom_command docs and a possible solution I understood that I can "wrap" my COMMAND into $<CONFIG:Debug> generator expression (to be sure it's "empty" in Release mode). I tried the following: cmake_minimum_required(VERSION 3.18) project(post-build CXX) file(WRITE main.cxx "int main() {}") add_executable(foo main.cxx) add_custom_command( TARGET foo P

CMake doesn't add /usr/include to include_directories list

I'm trying to build a CMake project with a customed arm-linux-..g++ compiler. This project is using some third-party library (libzmq for the manner of sake). Now the problem is that when I install libzmq, it puts the header file in /usr/include, but my compiler doesn't search for .h files there. I tried the following: find_package(PkgConfig) pkg_check_modules(LIBZMQ REQUIRED libzmq) // Now I have a variable ${LIBZMQ_INCLUDEDIR} populated with /usr/include - checked it include_directories( ${L

how can i define a macro/function in cmake to read parameter list?

I want to write a function in cmake. it looks like: macro(compile arg1) # TODO here: define a endless input param target_link_libraries(${arg1} pthread zmq config++ mmm dl) # TODO here: to add input list endmacro(compile) for example: i want to compile a pragma named demo, it need library libb and libc so i called: compile(demo, b, c) please notice. the arg num is not fixed. so, i need a thing similar with char ** argv in c++ the first input parameter will set the binary file name, the le

  1    2   3   4   5   6  ... 下一页 最后一页 共 21 页