[CMake] Fwd: Adding custom directories to PATH enviroment
Michael Wild
themiwi at gmail.com
Wed Apr 13 07:26:28 EDT 2011
On 04/13/2011 01:04 PM, Gabriele Greco wrote:
>
>
>
> And then configure and run it like this:
>
> CMakeLists.txt:
> ---------------
> # ...
> configure_file(foo_wrapper.cmake.in <http://foo_wrapper.cmake.in>
> "${CMAKE_CURRENT_BINARY_DIR}/foo_wrapper.cmake" @ONLY)
> add_custom_command(OUTPUT bar
> COMMAND "${CMAKE_COMMAND}" -P
> "${CMAKE_CURRENT_BINARY_DIR}/foo_wrapper.cmake"
> COMMENT "Creating bar")
>
>
> If you need to pass the script variables using the -D flags, make sure
> to pass them before the -P flag, otherwise they are silently ignored.
>
> I hope you get the idea.
>
>
>
> I fear I've not explained enough the problem.
>
> If I understood correctly your solution when in my CMakeLists.txt I
> execute the custom command "bar" what I obtain is that "foo" is called.
>
> In my project I have some "IDL" files written in a custom format, those
> files require a preprocessing pass to be transformed in .h/.cpp, that I
> perform using add_custom_command() inside a macro
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${PROJECT_SOURCE_DIR}/inc/intf/${_out_FILE}.h
> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE}
> COMMAND idlcc
> ARGS -V -S -s ${PROJECT_SOURCE_DIR}/inc/intf
> -I${PROJECT_SOURCE_DIR}/inc/intf -I${PROJECT_SOURCE_DIR}/inc
> ${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE}
> )
>
> The command *idlcc* is bundled within the repository and is in the
> directory $PROJECT_SOURCE_DIR/ext_bin/DFC, I can call it directly with a
> path, changing
>
> COMMAND idlcc
>
> to
>
> COMMAND ${PROJECT_SOURCE_DIR}/ext_bin/DFC/idlcc
>
> ...but the problem is that idlcc calls its "second step", *dfc_idl*,
> that is in the same directory, and pretend it to be in the command
> search path.
>
> the previous makefile used to do:
>
> export PATH=$PROJECT_DIR/ext/bin/DFC:$PATH
>
> The exported path is used by idlcc that is launched from the Makefile
> and that can find dfc_idl without problems.
>
> I need to mimic this behaviour in CMake.
>
> It seems a very simple task, I can see similar problems with
> LD_LIBRARY_PATH in other projects, it's strange CMake cannot do this in
> an easy way, that's why I think I'm missing something.
>
> ATM my solution is to manually do
>
> export PATH=basedir/ext_bin/DFC/idlcc:$PATH
> *
> *
> *BEFORE* building.
>
> --
> Bye,
> Gabry
>
Then you haven't read or understood my message ;-) Instead of calling
idlcc directly in the add_custom_command, you call a wrapper script,
that sets the PATH environment variable, and *then* invokes idlcc.
In your case that would look something like this:
idlcc_wrapper.cmake.in:
-----------------------
foreach(var INFILE OUTDIR)
if(NOT DEFINED ${var})
message(FATAL_ERROR "${var} must be passed on the command line")
endif()
endforeach()
set(ENV{PATH} "@PROJECT_SOURCE_DIR@/ext_bin/DFC:$ENV{PATH}")
execute_process(
COMMAND idlcc -V -S -s "${OUTDIR}"
-I"@PROJECT_SOURCE_DIR@/inc/intf" -I"@PROJECT_SOURCE_DIR@/inc"
"@INFILE@")
CMakeLists.txt:
---------------
# ...
configure_file(iclcc_wrapper.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/iclcc_wrapper.cmake" @ONLY)
# ...
add_custom_command(
OUTPUT "${PROJECT_SOURCE_DIR}/inc/intf/${_out_FILE}.h"
COMMAND "${CMAKE_COMMAND}"
-DINFILE="${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE}"
-DOUTDIR="${PROJECT_SOURCE_DIR}/inc/intf"
-P "${CMAKE_CURRENT_BINARY_DIR}/iclcc_wrapper.cmake"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE}"
COMMENT "Creating ${_out_FILE}.h")
One additional comment: Creating output in the source tree is a *very*
bad habit. Some people (including me) consider it to be obscene... ;-)
Unless you are doing an in-source build (which you shouldn't, for the
same reasons you shouldn't create output in the source tree), a build
system should *never* modify the source tree.
Michael
More information about the CMake
mailing list