Reputation: 87
I have the following directory structure:
├───3rd
│ └───lua // this is git submodule, I can't modify anything here
│ ├───doc
│ └───src
└───cmake
└───lua // CMakeLists.txt for ../../3rd/lua is here
I'm pulling external library to my repo let's say lua. There's no cmake support in the distrubution. And I can't build it on windows with nmake. Then I want to create a CMakeLists.txt
somewhere in my repo for lua.
Let's say I place CMakeLists.txt
for lua in ./cmake/lua/CMakeLists.txt
. Relative to this location I have to specify sources prefixed with ../../3rd/lua/src/
which is not nice
set(SOURCES
../../3rd/lua/src/lapi.c
../../3rd/lua/src/lauxlib.c
../../3rd/lua/src/lbaselib.c
<...>)
add_library(liblua ${SOURCES}).
Putting ../../3rd/lua/src/
into a variable and prefixing each of the source files with it is not nice too. So I want to change base search path for source files with ${PROJECT_SOURCE_DIR}/../../3rd/lua/src
. And I also want to affect base path for include_directories
. I thought changing PROJECT_SOURCE_DIR
to this will do, but it has no effect at all.
I used a script found here CMAKE: Print out all accessible variables in a script to list all variables and all of them referring to CMakeLists.txt location I changed to ${PROJECT_SOURCE_DIR}/../../3rd/lua/src
:
set(CMAKE_CURRENT_LIST_DIR C:/dev/lua-external-cmake/3rd/lua/src)
set(CMAKE_CURRENT_SOURCE_DIR C:/dev/lua-external-cmake/3rd/lua/src)
set(CMAKE_HOME_DIRECTORY C:/dev/lua-external-cmake/3rd/lua/src)
set(CMAKE_SOURCE_DIR C:/dev/lua-external-cmake/3rd/lua/src)
set(PROJECT_SOURCE_DIR C:/dev/lua-external-cmake/3rd/lua/src)
set(Project_SOURCE_DIR C:/dev/lua-external-cmake/3rd/lua/src)
It seems there is no such variable, since this change had no effect. I'm aware that changing some of those is utterly wrong. I did it just to find out if there will be any effect.
So, how do I change source search location and base path for include files in cmake?
Upvotes: 1
Views: 1148
Reputation: 66061
There is no source search path
in CMake. But you can easily "rebase" sources using common cmake commands:
set(SOURCES
lapi.c
lauxlib.c
lbaselib.c
<...>)
set(SOURCES_ABS)
foreach(source ${SOURCES})
list(APPEND SOURCES_ABS ${PROJECT_SOURCE_DIR}/../../3rd/lua/src/${source})
endforeach()
add_library(liblua ${SOURCES_ABS}).
Upvotes: 3