I assume the error is that you are calling add_library with source files that do not already exist during the first run of CMake?
If so, you can set the GENERATED property in these source files using set_source_files_properties . This allows CMake to know that it is normal if these files do not exist during configure (when CMake starts), but they will exist during build.
For the add_jar command add_jar run before add_library , create a dependency on the add_jar target using add_dependencies . For the add_custom_command command add_custom_command run before add_library , use the custom TARGET ... PRE_BUILD .
For example, if the source list for lib is stored in a variable named ${Srcs} , you can do:
# Allow 'Srcs' to not exist at configure-time set_source_files_properties(${Srcs} PROPERTIES GENERATED TRUE) add_library(MyLib ${Srcs}) # compile .class files add_jar(MyJarTarget ...) # generate .h headers add_custom_command(TARGET MyLib PRE_BUILD COMMAND ...) # Force 'add_jar' to be built before 'MyLib' add_dependencies(MyLib MyJarTarget)
source share