Andreas, Here is a summary of our conversation. The PKI project consists of several components (e.g. util, common, ca, kra) and each might have source codes and test codes. We want to use CMake to generate the following Makefile targets: * all: This is the default target which should build only the main source code, not the test code. * test: This target will build and run the test code. It will use 2 subtargets: build-test and run-test. They need to be separate targets because we might need to fix either the source or the test and then rerun the test without having to rebuild everything. Currently this is what we have (see http://fedorapeople.org/gitweb?p=edewata/public_git/pki.git;a=tree;f=pki;h=0...). The main CMakeLists.txt defines the main 'test' target: add_custom_target(test) This target is empty, but each component can attach itself to the main 'test' target. For example the util package contains the following script (see base/util/test/CMakeLists.txt): ... # build util test add_jar(pki-util-test ...) ... # define util test target add_junit_test(test-pki-util ...) # attach util test to the main test target add_dependencies(test test-pki-util) The problem is the add_jar() is defined at the top level, so the test code will be built when we call 'make all', which is not what we want. Is there a way to move add_jar() into a function/target such that the test code will be built only when the 'test' target is called? So the main CMakeLists.txt will be something like this: # define the test target add_custom_target(test) # define the build-test subtarget add_custom_target(build-test) add_dependencies(test build-test) # define the run-test subtarget add_custom_target(run-test) add_dependencies(test run-test) and the util's CMakeLists.txt will be like this: # define a function/target to build util test function(build-pki-util-test ...) ... add_jar(pki-util-test ...) ... endfunction(build-pki-util-test ...) # attach the function/target to build-test add_dependencies(build-test build-pki-util-test) # define a function/target to run util test add_junit_test(run-pki-util-test ...) # attach the function/target to run-test add_dependencies(run-test run-pki-util-test) If this is not possible, what would be the best alternative? Thanks! PS: We also talked about compiling Java codes without having to specify the files explicitly, but that's for a separate discussion. -- Endi S. Dewata