Issue
i want use cmake to build my project.but i have some question about add_execuable function. when i use add_execuable to build a project not use the project name.there are some problem. it looks like the cmake can't understand the relative path. there are two cmakelist.txt. i want know why one is work.and another can't work.
Set(SOURCES ${PROJECT_SOURCE_DIR}/main.cpp
)
# Add an executable
#add_executable(hello main.cpp)
add_executable(hello ${SOURES})
this can't work
Set(SOURCES ${PROJECT_SOURCE_DIR}/main.cpp
)
# Add an executable
add_executable(hello main.cpp)
this can work and there are project name
# Set the project name
project (hello_cmake)
my english is so bad, so sorry =_=
Solution
If it's complaining that it can't find main.cpp
then it's an issue with your paths. If the CMakeLists.txt
containing the add_executable()
statement is in the same directory as main.cpp
then you shouldn't have any problems as it will look relative to the CMakeLists.txt
file.
If there are any spaces in the path then that could cause problems as well. In that case you'd need to use ${PROJECT_SOURCE_DIR}/main.cpp
.
Answered By - dwosk