[CMake] Unit tests, but not CTest

Magnus Therning magnus at therning.org
Fri May 14 02:24:37 EDT 2010


On 14/05/10 01:14, Michael Hertling wrote:
> On 05/13/2010 10:43 AM, Magnus Therning wrote:
[...]
>> It's not ideal.
>>
>> I'm writing some CMake scripts to ease the use of OCaml with CMake.  There are
>> basically two macros at this point:
>>
>> • add_ocaml_library()
>> • add_ocaml_executable()
>>
>> Both of them can somewhat simplistically be thought of as just wrappers around
>> add_custom_command().  In some cases the OCaml executable is a unit test,
>> which means I'd like the executable to be run after being built. [...]
> 
> OK, as far as I understand your concern, you have two separate tasks:
> 
> (1) (Re)build the executable using ADD_CUSTOM_COMMAND() and,
> (2) in some cases, run it as a unit test after its (re)build.
> 
> IMO, these two can't be adequately expressed as Make-time dependencies: Who
> depends on who? Of course, (1) on (2) does not, but vice versa does not
> succeed, also, since you want *(1)* to trigger (2) after (1) itself has been
> rebuilt, and this is nothing you can explain to Make as usual dependencies
> between two targets unless you are willing to trigger (2) explicitly when
> you mean (1). Thus, you can't use ADD_CUSTOM_TARGET() to achieve the desired
> workflow via pure target interdependencies, and since
> ADD_CUSTOM_COMMAND(TARGET ... POST_BUILD) which would probably do the job
> isn't applicable in your case it turns out that (2) - even if optional -
> should be integrated in (1) manually.

Thanks for this analysis, it makes the problem a lot clearer to me.  One thing
it doesn't clarify is how ADD_CUSTOM_COMMAND( TARGET ... POST_BUILD ) could
*ever* be useful.  I'm still to see an example of any buildable target that
such a post-build command can be connected to and only triggered on (re)build.

>> [...] Instead
>> I'll have to either create a specific macro for an executable that is a unit
>> test, or pass a flag to add_ocaml_executable().
> 
> The latter would be my recommendation as being most convenient.

I've added a flag to my add_ocaml_executable().  As you say, it looks like the
most convenient solution.

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100514/52a56c03/attachment.pgp>


More information about the CMake mailing list