问题描述
我正在尝试使用CMake创建解决方案。这是我的第一次,我从简单的事情开始。
I'm trying to create my solution with using CMake. This is my first time and I started with something simple.
我制作了文本文件(CMakeLists.txt),并在CMake中使用了它。我可以没有错误地配置,但是尝试生成它时出现错误:
I made text file (CMakeLists.txt) and used it in CMake. I can "Configure" with no error but I have an error when I try to generate it:
CMake Error at CMakeLists.txt:75 (ADD_EXECUTABLE):
Cannot find source file:
./source/server/server.hpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
这是我文件的路径:
\QTCP_Connection\source\server (contain server.cpp and server.hpp)
\QTCP_Connection\source\qtcp (contain main.cpp)
\QTCP_Connection\source\libs (contain singleton_holder.hpp and stdafx.hpp and stdafx.cpp and targetver.hpp)
这是我的CMakeLists.txt:
And this is my CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.6)
PROJECT(QTCP_Connection)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE} )
ADD_DEFINITIONS(${QT_DEFINITIONS})
ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-DQT_PLUGIN)
ADD_DEFINITIONS(-DQT_SHARED)
ADD_DEFINITIONS(-DQT_DLL)
ADD_DEFINITIONS(-DQT_LARGEFILE_SUPPORT)
ADD_DEFINITIONS(-DQT_THREAD_SUPPORT)
SET(QT_DONT_USE_QTGUI TRUE)
SET(QTCP_PROJECT_DIR .)
SET(QTCP_QT_DIR $ENV{SEPANTA_QT_DIR})
SET(QTCP_BOOST_DIR $ENV{SEPANTA_BOOST_DIR})
SET(QTCP_PYTHON_DIR $ENV{SEPANTA_PYTHON_DIR})
SET(QTCP_XFS_DIR $ENV{XFS_DIR})
SET(QTCP_LOGGER_DIR $ENV{SEPANTA_LOGGER_DIR})
SET(DEVICE_MANAGER_IMPL_DIR device-manager)
SET(DEVICES_BASE_DIR ../../devices)
SET(DEVICES_IMPL_DIR devices)
SET(QTCP_DIR ${QTCP_PROJECT_DIR}/source/qtcp)
SET(SERVER_DIR ${QTCP_PROJECT_DIR}/source/server)
SET(LIBS_DIR ${QTCP_PROJECT_DIR}/source/libs)
INCLUDE_DIRECTORIES(
${QTCP_PROJECT_DIR}/source
${QTCP_QT_DIR}/include
${QTCP_QT_DIR}/include/QtCore
${QTCP_BOOST_DIR}/include/boost-1_50
${QTCP_LOGGER_DIR}/include
${QTCP_PYTHON_DIR}/include
)
SET(QT_HEADERS
${SERVER_DIR}/server.hpp
)
QT4_WRAP_CPP(QT_HEADERS_MOC ${QT_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
SET(QTCP_FILES
${QTCP_PROJECT_DIR}/source/qtcp/main.cpp
)
SET(SERVER_FILES
${SERVER_DIR}/server.hpp
${SERVER_DIR}/server.cpp
)
SET(LIBS_FILES
${LIBS_DIR}/singleton_holder.hpp
${LIBS_DIR}/stdafx.cpp
${LIBS_DIR}/stdafx.hpp
${LIBS_DIR}/targetver.hpp
)
LINK_DIRECTORIES(
${QTCP_QT_DIR}/lib
${QTCP_BOOST_DIR}/lib
${QTCP_PYTHON_DIR}/libs
${QTCP_LOGGER_DIR}/lib
${QTCP_XFS_DIR}/XFS_WINCOR_4.1
${QTCP_XFS_DIR}/XFS_WINCOR_4.1/LIB)
SET(XFS_LIBS
MSXFS
xfs_conf
SSIDLL)
ADD_EXECUTABLE(QTCP_Connection
${QT_HEADERS_MOC}
${QTCP_FILES}
${SERVER_FILES}
${LIBS_FILES}
)
source_group("moc_generated" FILES ${QT_HEADERS_MOC})
source_group("source\\qtcp" FILES ${QTCP_FILES})
source_group("source\\server" FILES ${SERVER_FILES})
source_group("source\\libs" FILES ${LIBS_FILES})
TARGET_LINK_LIBRARIES(QTCP_Connection
#${QT_LIBRARIES}
${QT_QTCORE_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${QT_QTSQL_LIBRARY}
${XFS_LIBS}
debug log4cplusUD.lib
optimized log4cplusU.lib
)
set_target_properties(QTCP_Connection PROPERTIES COMPILE_FLAGS "/W2 /Zc:wchar_t-")
set_target_properties(QTCP_Connection PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
你能告诉我我在做什么错吗?
Can you tell me what I'm doing wrong here?
推荐答案
此行似乎有问题:
SET(QTCP_PROJECT_DIR .)
目录。
将poi nt到正在运行的cmake进程的工作目录,而不是CMakeLists文件的目录。
The directory .
will point to the working directory of the running cmake process and not to the directory of the CMakeLists file.
相反,您应该使用类似
SET(QTCP_PROJECT_DIR ${PROJECT_SOURCE_DIR})
请参见上的文档
请注意,您可以使用进行一些简单的printf调试:
Note that you can use message
to do some simple printf-debugging if you are not sure what a certain variable points to:
message("PROJECT_SOURCE_DIR points to " ${PROJECT_SOURCE_DIR})
这篇关于CMake-找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!