[CMake] File permissions on CONFIGURE_FILE output
Michael Wild
themiwi at gmail.com
Wed Feb 3 04:09:45 EST 2010
On 2. Feb, 2010, at 22:31 , Aaron_Wright at selinc.com wrote:
> I run CONFIGURE_FILE on a file that is read only. The output file is also
> read only, which is a problem because I need to append to it. Is there a
> way to change this behavior? Or a work around?
>
Either change the source-file permissions or use file(COPY ...) after configure_file. Anyways, I'm not sure it's a good idea to append to a configured file... Usually it is better to have something like this (especially, look at ADDITIONAL_CONTENT):
something.h.in
----------------------
#cmakedefine HAVE_FOO_H
#cmakedefine HAVE_BAR_H
#define BAZ_DIR "@BAZ_DIR@"
@ADDITIONAL_CONTENT@
----------------------
CMakeLists.txt
--------------
....
include(CheckIncludeFile)
check_include_file(foo.h HAVE_FOO_H)
check_include_file(bar.h HAVE_BAR_H)
set(BAZ_DIR "/somewhere/somedir")
if(WIN32)
# windows.h is just plain tedious...
set(ADDITIONAL_CONTENT
"#define WIN32_LEAN_AND_MEAN
#define NOGDICAPMASKS
#define NOVIRTUALKEYCODES
#define NOWINMESSAGES
#define NOWINSTYLES
#define NOSYSMETRICS
#define NOMENUS
#define NOICONS
#define NOKEYSTATES
#define NOSYSCOMMANDS
#define NORASTEROPS
#define NOSHOWWINDOW
#define OEMRESOURCE
#define NOATOM
#define NOCLIPBOARD
#define NOCOLOR
#define NOCTLMGR
#define NODRAWTEXT
#define NOGDI
#define NOKERNEL
#define NONLS
#define NOMEMMGR
#define NOMETAFILE
#ifndef NOMINMAX
# define NOMINMAX
#endif
#define NOMSG
#define NOOPENFILE
#define NOSCROLL
#define NOSERVICE
#define NOSOUND
#define NOTEXTMETRIC
#define NOWH
#define NOWINOFFSETS
#define NOCOMM
#define NOKANJI
#define NOHELP
#define NOPROFILER
#define NODEFERWINDOWPOS
#define NOMCX
#include <Windows.h>"
)
endif()
configure_file(something.h.in ${CMAKE_BINARY_DIR}/something.h)
...
---------------------------
HTH
Michael
More information about the CMake
mailing list