[CMake] ADD_CUSTOM_COMMAND

Keyan ml at pulsschlag.net
Mon Dec 14 04:56:52 EST 2009


hi,

i found the problem, just in case anyone is interested. the problem was, that i use "package first.second.third;" in my java-sources, so that the class files are compiled to 
${CMAKE_CURRENT_BINARY_DIR}/first/second/third/file.class and not to 
${CMAKE_CURRENT_BINARY_DIR}/file.class, which is while the depend never found the class files.

the remaining problem is to build the jar file on dependency of changes of the class files. what i am currently trying is:

SET(MY_FILES File1 File2 File3)
SET(CLASS_FILES)

FOREACH(f ${MY_FILES})
  LIST(APPEND CLASS_FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_PATH}/${f}.class)
ENDFOREACH(f ${MY_FILES})

ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/${JAR_DIR}/${JAR_FILE}
    DEPENDS ${CLASS_FILES}
    COMMAND ${CMAKE_COMMAND} 
    ARGS -E chdir ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_Java_ARCHIVE} cfm ${CMAKE_BINARY_DIR}/${JAR_DIR}/${JAR_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.MF org)


ADD_CUSTOM_TARGET(${JAR_FILE} 
    ALL
    DEPENDS ${PROJECT_BINARY_DIR}/${JAR_DIR}/${JAR_FILE})

but the jar files is build every time i call make.

regards,
keyan

On 10 Dec 2009, at 18:14, Keyan wrote:

> hi,
> 
> i am tryting to build java code in my otherwise c++ project. for some reason, i just cant get add_custom_command to do what i want it to do. here are the lines of code that i am currently trying:
> 
> SET(MY_FILES FirstJavaFile SecondJavaFile)
> SET(CLASS_FILES "")
> SET(JAVA_FILES "")
> FOREACH(f ${MY_FILES})
>  SET(CLASS_FILES "${CLASS_FILES} ${PROJECT_BINARY_DIR}/${CLASS_DIR}/${f}.class")
>  SET(JAVA_FILES "${JAVA_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${f}.java")
> ENDFOREACH(f JAVA_FILES)
> message("Java files:  \"${JAVA_FILES}\"")
> message("Class files: \"${CLASS_FILES}\"")
> 
> # compile all .java files with javac to .class
> ADD_CUSTOM_COMMAND(
>    OUTPUT  ${CLASS_FILES}
>    DEPENDS ${JAVA_FILES}
>    COMMAND ${CMAKE_Java_COMPILER} ARGS -d ${PROJECT_BINARY_DIR}/${CLASS_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.java
> )
> 
> 
> From my understanding of what add_custom_command should be doing, this should compile FIrstJavaFile.java and SecondJavaFile.java to class files, if they have been changed. but it does nothing.
> 
> i am thankful for any tip.
> 
> regards,
> keyan
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list