I'm trying to have CMake either run three bash commands or a bash script. However, I can't seem to get it to work.
The bash commands are:
cd ${CMAKE_SOURCE_DIR}/dependencies/library
make
cd ${CMAKE_BINARY_DIR}
Essentially, I would like CMake to build the library in that directory if it does not already exist.
Here's the CMake code I tried:
if(NOT "${CMAKE_SOURCE_DIR}/dependencies/library/lib.o")
execute_process(COMMAND cd ${CMAKE_SOURCE_DIR}/dependencies/library)
execute_process(COMMAND make)
execute_process(COMMAND cd ${CMAKE_BINARY_DIR})
endif(NOT "${CMAKE_SOURCE_DIR}/dependencies/library/lib.o")
However, it's not building anything. What am I doing wrong?
Also, while I'm here asking this: should the third command, to move to the binary folder, be included?
Thanks!
WORKING_DIRECTORY
parameter instead of thosecd
commands?Something likeexecute_process(COMMAND make WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dependencies/library)
. I suppose,execute_process()
calls does not share the same environment. Also, if I were You, I'd check out theadd_custom_target()
andadd_custom_command()
for this kind of thing. – Wackerexecute_process
not sharing state is almost certainly accurate. It is incredibly likely that thecd
in the first command changes directory only for that process and not for any other ones. – Gatling