4

I'm trying to create my solution with using CMake. This is my first time and I started with something simple.

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

This is the path of my files:

\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)

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?

1 Answer 1

3

This line seems problematic:

SET(QTCP_PROJECT_DIR .)

The directory . will point to the working directory of the running cmake process and not to the directory of the CMakeLists file.

Instead you should use something like

SET(QTCP_PROJECT_DIR ${PROJECT_SOURCE_DIR})

See the documentation on the PROJECT_SOURCE_DIR variable for details.

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})
Sign up to request clarification or add additional context in comments.

4 Comments

I still have same problem even with "SET(QTCP_PROJECT_DIR ${PROJECT_SOURCE_DIR})" also print shows the correct path. PROJECT_SOURCE_DIR points to D:/Source-Code/QTCP_Connection
I used the message command to see files in directory cmake cant find but still is ok. message("SERVER_FILES points to " ${SERVER_FILES}) ------> SERVER_FILES points to D:/Source-Code/QTCP_Connection/source/server/server.hpp D:/Source-Code/QTCP_Connection/source/server/server.cpp
@MeysamHashemi Can you try deleting the CMakeCache.txt in your build folder and run it again. Also, the error given by CMake should look differently now. Can you give the new error message?
I deleted my CMakeLists.txt and made new one with new name and it worked with no problem. Kinda weird but thx for the tip ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.