Assume we have a CMakeLists.txt who has code like ( following is little part of whole file ):
cmake_minimum_required(VERSION 2.6.3)
#...
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/include/mit-krb5/")
message("CMAKE_REQUIRED_INCLUDES=${CMAKE_REQUIRED_INCLUDES};CMAKE_REQUIRED_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS};CMAKE_REQUIRED_FLAGS=${CMAKE_REQUIRED_FLAGS}")
message("before find path, fuckGssApiIncludes=${fuckGssApiIncludes}")
find_path(fuckGssApiIncludes "gssapi.h" "/usr/include")
if(NOT fuckGssApiIncludes)
message(FATAL_ERROR "Can't find folder containing gssapi.h")
endif()
message("after, fuckGssApiIncludes=${fuckGssApiIncludes}")
include_directories(${fuckGssApiIncludes})
check_include_files("gssapi.h" HAVE_GSSAPI_H)
#....
if (NOT HAVE_GSSAPI_H)
message(FATAL_ERROR "Cannot find GSS libraries")
And we have some files:
# ls /usr/include/gssapi.h
/usr/include/gssapi.h
But when I run this command with cmake version 3.12.1, I got error like this:
CMAKE_REQUIRED_INCLUDES=/usr/include/;/usr/include/x86_64-linux-gnu/;CMAKE_REQUIRED_DEFINITIONS=;CMAKE_REQUIRED_FLAGS=
before find path, fuckGssApiIncludes=
after, fuckGssApiIncludes=/usr/include
CMake Error at CMakeLists.txt:548 (message):
Cannot find GSS libraries
I thought in someway, Cmake.check_include_files did not works as Cmake's definition.
So, Q1: Is my thought correct, and why? Q2: How to work around, and make this cmakelists.txt run well?
Answer find, just remove all cmake temporary files.
Related
Im trying to compile the posest C++ library
posest : A C/C++ Library for Robust 6DoF Pose Estimation from 3D-2D Correspondences
with make. But when run the make I got the following error
make
-- LEVMAR_INCLUDE_DIR = /usr/local/levmar-2.6
-- LEVMAR_BINARY_DIR = /usr/local/levmar-2.6/w32
-- LAPACKBLAS_DIR = /usr/lib
-- demos will be linked against posest;levmar;lapack;blas;f2c
-- Configuring done
CMake Error at CMakeLists.txt:24 (ADD_LIBRARY):
Cannot find source file:
mlsl/mlsl.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Warning (dev) at CMakeLists.txt:65 (ADD_DEPENDENCIES):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "levmar" of target "binocposest_demo" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:64 (ADD_DEPENDENCIES):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "levmar" of target "posest_demo" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error: Cannot determine link language for target "posest".
CMake Error: CMake can not determine linker language for target: posest
-- Generating done
-- Build files have been written to: /home/admini/posest-1.2
Makefile:714: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
But the source file mlsl.c is already there
Here is the contents of the CMakeList.txt file
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(POSEST)
# levmar library
SET(LEVMAR_INCLUDE_DIR "/usr/local/levmar-2.6" CACHE PATH "Path to LEVMAR library header")
#ADD_SUBDIRECTORY(${LEVMAR_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LEVMAR_INCLUDE_DIR})
MESSAGE(STATUS "LEVMAR_INCLUDE_DIR = ${LEVMAR_INCLUDE_DIR}")
IF(MSVC)
ADD_DEFINITIONS(/arch:SSE2)
# get rid of CRT warnings
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(MSVC)
INCLUDE_DIRECTORIES(mlsl)
ADD_LIBRARY(posest buckets.c lqs.c ransac.c rngs.c prosac.c deal.c p3p.c p4pf.c planep4p.c svd3.c polysolve.c
poseproj.c posest.c align.c lhm.c sam.c compiler.h lqs.h ransac.h prosac.h p3p.h p4pf.h planep4p.h svd3.h
polysolve.h poseproj.h posest.h util.h rngs.h sam.h
mlsl/mlsl.c mlsl/mt19937ar.c mlsl/redblack.c mlsl/sobolseq.c
)
OPTION(BUILD_DEMOS "Build demo programs?" TRUE)
# demo program
IF(BUILD_DEMOS)
# paths to levmar & lapack/blas libraries
SET(LEVMAR_BINARY_DIR "${LEVMAR_INCLUDE_DIR}/w32" CACHE PATH "Path to levmar library")
MESSAGE(STATUS "LEVMAR_BINARY_DIR = ${LEVMAR_BINARY_DIR}")
SET(LAPACKBLAS_DIR "/usr/lib" CACHE PATH "Path to lapack/blas libraries")
MESSAGE(STATUS "LAPACKBLAS_DIR = ${LAPACKBLAS_DIR}")
# actual names for the lapack/blas/f2c libraries
SET(LAPACKBLAS_LIB_NAMES "lapack;blas" CACHE STRING "The name of the lapack & blas libraries")
SET(F2C_LIB_NAME f2c CACHE STRING "The name of the f2c or F77/I77 library")
# f2c is sometimes equivalent to libF77 & libI77
#SET(F2C_LIB_NAME "libF77;libI77" CACHE STRING "The name of the f2c or F77/I77 library")
SET(LIBS posest levmar)
SET(LIBS ${LIBS} ${LAPACKBLAS_LIB_NAMES} ${F2C_LIB_NAME})
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) # location of the posest library
LINK_DIRECTORIES(${LEVMAR_BINARY_DIR}) # location of the levmar library
LINK_DIRECTORIES(${LAPACKBLAS_DIR})
ADD_EXECUTABLE(posest_demo posest_demo.c)
TARGET_LINK_LIBRARIES(posest_demo ${LIBS})
ADD_EXECUTABLE(binocposest_demo binocposest_demo.c)
TARGET_LINK_LIBRARIES(binocposest_demo ${LIBS})
MESSAGE(STATUS "demos will be linked against ${LIBS}")
# make sure that the libraries are built before the demos
ADD_DEPENDENCIES(posest_demo posest levmar)
ADD_DEPENDENCIES(binocposest_demo posest levmar)
ENDIF(BUILD_DEMOS)
Here the Project Directory screenshot.
And the content of the mlsl directory
/home/posest-1.2/mlsl/mlsl.c
/home/posest-1.2/mlsl/mlsl.h
/home/posest-1.2/mlsl/mt19937ar.c
/home/posest-1.2/mlsl/mt19937ar.h
/home/posest-1.2/mlsl/redblack.c
/home/posest-1.2/mlsl/redblack.h
/home/posest-1.2/mlsl/sobol.h
/home/posest-1.2/mlsl/soboldata.h
/home/posest-1.2/mlsl/sobolseq.c
Im not sure what is the problem. Any help?
I had to download the tar file from the website. It is malformed and won't work.
~/swdev/posest-1.2$ ls -ld mlsl/
drw-r--r-- 2 XXX XXXX 4096 Oct 6 2014 mlsl/
~/swdev/posest-1.2$ chmod u+x mlsl/
~/swdev/posest-1.2$ cmake .
The sources and directories are required to be readable. In this case mlsl has incorrect permissions and CMake cannot read the file. Use the chmod command to fix the permissions on the directory.
I am trying to make a resource file available to the executable during the runtime. I am using the following CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
project(open-gl-test)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
add_executable(${PROJECT_NAME} "main.c")
message(Executable is set!)
target_link_libraries(${PROJECT_NAME} ${GLEW_LIBRARIES} ${OPENGL_gl_LIBRARY} glfw)
# List of files for which we add a copy rule.
set(data_SHADOW "basic.shader")
# We don't want to copy if we're building in the sourse dir.
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(WARNING "Directories are not equal")
foreach(item IN LISTS data_SHADOW)
message(STATUS ${item})
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/res/shaders/${item}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${item}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${item}"
)
endforeach()
else()
message(WARNING "Directories are equal")
endif()
# Files are only copied if a target depends on them.
add_custom_target(data-target ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${data_SHADOW}")
And this is how I access the file.
struct ShaderProgramSource source = parseShader("res/shaders/basic.shader");
But nothing gets copied to the project build directory and the even the messages don't show up in the *compile output window. And the error message I am getting is:
Error while opening the file: No such file or directory
What might be the issue?
I'm currently using recursive make and autotools and am looking to migrate to CMake for a project that looks something like this:
lx/ (project root)
src/
lx.c (contains main method)
conf.c
util/
str.c
str.h
etc.c
etc.h
server/
server.c
server.h
request.c
request.h
js/
js.c
js.h
interp.c
interp.h
bin/
lx (executable)
How should I go about this?
If there's never any source higher than the lx/src directory, then there's no need for the lx/CMakeLists.txt file. If there is, it should look something like this:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx)
add_subdirectory(src)
add_subdirectory(dir1)
add_subdirectory(dir2)
# And possibly other commands dealing with things
# directly in the "lx" directory
...where the subdirectories are added in library dependency order. Libraries that depend on nothing else should be added first, and then libraries that depend on those, and so on.
lx/src/CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx_exe)
add_subdirectory(util)
add_subdirectory(js)
add_subdirectory(server)
set(lx_source_files conf.c lx.c)
add_executable(lx ${lx_source_files})
target_link_libraries(lx server)
# also transitively gets the "js" and "util" dependencies
lx/src/util/CMakeLists.txt
set(util_source_files
etc.c
etc.h
str.c
str.h
)
add_library(util ${util_source_files})
lx/src/js/CMakeLists.txt
set(js_source_files
interp.c
interp.h
js.c
js.h
)
add_library(js ${js_source_files})
target_link_libraries(js util)
lx/src/server/CMakeLists.txt
set(server_source_files
request.c
request.h
server.c
server.h
)
add_library(server ${server_source_files})
target_link_libraries(server js)
# also transitively gets the "util" dependency
Then, in a command prompt:
mkdir lx/bin
cd lx/bin
cmake ..
# or "cmake ../src" if the top level
# CMakeLists.txt is in lx/src
make
By default, the lx executable will end up in the "lx/bin/src" directory using this exact layout. You can control what directory it ends up in by using the RUNTIME_OUTPUT_DIRECTORY target property and the set_property command.
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_property
Refer to target_link_libraries libs either by CMake target name, if the lib is built as a CMake target via add_library, or by full path to the library file otherwise.
See also, the output of "cmake --help-command target_link_libraries", or any other cmake command, and the full online documentation for cmake commands found here:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_Commands
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries
Steinberg VST3 library has a reusable method which recursively loops through subdirectories and adds them if they include a CMakeLists.txt file:
# add every sub directory of the current source dir if it contains a CMakeLists.txt
function(smtg_add_subdirectories)
file(GLOB subDirectories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(dir ${subDirectories})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${dir}")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
add_subdirectory(${dir})
endif()
endif()
endforeach(dir)
endfunction()
https://github.com/steinbergmedia/vst3_cmake/blob/master/modules/SMTG_AddSubDirectories.cmake
I quite new with CMake, but I have a problem with porting an existing library to it.
In order to simplify, I will only work on 2 files : angle.cpp and angle.h.
The files are this ones :
/cmaketest/CMakeLists
/cmaketest/src/angle.cpp
/cmaketest/src/angle.h
and I will run CMake and produce the Makefile in /cmaketest/.
My CMakeLists is currently this one :
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(cmaketest)
SET(cmaketest_SRCDIR src)
AUX_SOURCE_DIRECTORY(${cmaketest_SRCDIR} cmaketest_SOURCES)
FILE(GLOB cmaketest_HEADERS ${cmaketest_SRCDIR}/*.h )
ADD_EXECUTABLE(cmaketest ${cmaketest_SOURCES} ${cmaketest_HEADERS})
But the problem is that in angle.cpp, the header is included not by "angle.h" but by <src/angle.h>
So with the current cmake file I got the following error when I execute make :
/cmaketest/src/angle.cpp:1:23: fatal error: src/angle.h: file not found
How to solve the problem ? (for backward compatibility I can't modify <src/angle.h> in the .cpp file)
Thank you very much.
Try adding the project directory as an include directory by using the include_directories command:
...
file (GLOB cmaketest_HEADERS ${cmaketest_SRCDIR}/*.h )
include_directories(${CMAKE_SOURCE_DIR})
add_executable(cmaketest ${cmaketest_SOURCES} ${cmaketest_HEADERS})
I'm currently using recursive make and autotools and am looking to migrate to CMake for a project that looks something like this:
lx/ (project root)
src/
lx.c (contains main method)
conf.c
util/
str.c
str.h
etc.c
etc.h
server/
server.c
server.h
request.c
request.h
js/
js.c
js.h
interp.c
interp.h
bin/
lx (executable)
How should I go about this?
If there's never any source higher than the lx/src directory, then there's no need for the lx/CMakeLists.txt file. If there is, it should look something like this:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx)
add_subdirectory(src)
add_subdirectory(dir1)
add_subdirectory(dir2)
# And possibly other commands dealing with things
# directly in the "lx" directory
...where the subdirectories are added in library dependency order. Libraries that depend on nothing else should be added first, and then libraries that depend on those, and so on.
lx/src/CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx_exe)
add_subdirectory(util)
add_subdirectory(js)
add_subdirectory(server)
set(lx_source_files conf.c lx.c)
add_executable(lx ${lx_source_files})
target_link_libraries(lx server)
# also transitively gets the "js" and "util" dependencies
lx/src/util/CMakeLists.txt
set(util_source_files
etc.c
etc.h
str.c
str.h
)
add_library(util ${util_source_files})
lx/src/js/CMakeLists.txt
set(js_source_files
interp.c
interp.h
js.c
js.h
)
add_library(js ${js_source_files})
target_link_libraries(js util)
lx/src/server/CMakeLists.txt
set(server_source_files
request.c
request.h
server.c
server.h
)
add_library(server ${server_source_files})
target_link_libraries(server js)
# also transitively gets the "util" dependency
Then, in a command prompt:
mkdir lx/bin
cd lx/bin
cmake ..
# or "cmake ../src" if the top level
# CMakeLists.txt is in lx/src
make
By default, the lx executable will end up in the "lx/bin/src" directory using this exact layout. You can control what directory it ends up in by using the RUNTIME_OUTPUT_DIRECTORY target property and the set_property command.
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_property
Refer to target_link_libraries libs either by CMake target name, if the lib is built as a CMake target via add_library, or by full path to the library file otherwise.
See also, the output of "cmake --help-command target_link_libraries", or any other cmake command, and the full online documentation for cmake commands found here:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_Commands
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries
Steinberg VST3 library has a reusable method which recursively loops through subdirectories and adds them if they include a CMakeLists.txt file:
# add every sub directory of the current source dir if it contains a CMakeLists.txt
function(smtg_add_subdirectories)
file(GLOB subDirectories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(dir ${subDirectories})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${dir}")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
add_subdirectory(${dir})
endif()
endif()
endforeach(dir)
endfunction()
https://github.com/steinbergmedia/vst3_cmake/blob/master/modules/SMTG_AddSubDirectories.cmake