Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2c7ea0911c3d52bf1c1c22cd3f6d2fb9ac5d6ebb
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2 project(simgrid-java C)
3 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
4 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
5 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/lib")
6
7
8 set(soversion 1)
9 ###############################
10 # Test the build dependencies #
11 ###############################
12 include(FindSimGrid.cmake)
13 include(FindJavaSG.cmake)
14
15 ###############################
16 # Declare our package content #
17 ###############################
18 set(JMSG_C_SRC
19         src/smx_context_java.h
20         src/smx_context_java.c
21         src/jxbt_utilities.c
22         src/jxbt_utilities.h
23         src/jmsg.c 
24         src/jmsg.h
25         src/jmsg_host.c
26         src/jmsg_host.h
27         src/jmsg_process.c
28         src/jmsg_process.h
29         src/jmsg_task.c
30         src/jmsg_task.h
31         src/jmsg_application_handler.c
32         src/jmsg_application_handler.h
33 )
34
35 set(JMSG_JAVA_SRC
36         org/simgrid/msg/ApplicationHandler.java
37         org/simgrid/msg/Host.java
38         org/simgrid/msg/HostFailureException.java       
39         org/simgrid/msg/HostNotFoundException.java      
40         org/simgrid/msg/JniException.java
41         org/simgrid/msg/Msg.java
42         org/simgrid/msg/MsgException.java
43         org/simgrid/msg/MsgNative.java
44         org/simgrid/msg/NativeException.java
45         org/simgrid/msg/Process.java
46         org/simgrid/msg/ProcessNotFoundException.java
47         org/simgrid/msg/Sem.java
48         org/simgrid/msg/Task.java
49         org/simgrid/msg/TaskCancelledException.java
50         org/simgrid/msg/TimeoutException.java
51         org/simgrid/msg/TransferFailureException.java   
52 )
53
54 set(JAVA_EXAMPLES
55         examples/mutualExclusion/centralized/MutexCentral.java
56         examples/mutualExclusion/centralized/GrantTask.java
57         examples/mutualExclusion/centralized/Coordinator.java
58         examples/mutualExclusion/centralized/ReleaseTask.java
59         examples/mutualExclusion/centralized/Node.java
60         examples/mutualExclusion/centralized/RequestTask.java
61         examples/basic/FinalizeTask.java
62         examples/basic/Forwarder.java
63         examples/basic/Master.java
64         examples/basic/BasicTest.java
65         examples/basic/Slave.java
66         examples/commTime/FinalizeTask.java
67         examples/commTime/Master.java
68         examples/commTime/Slave.java
69         examples/commTime/CommTimeTest.java
70         examples/pingPong/PingPongTask.java
71         examples/pingPong/Sender.java
72         examples/pingPong/Receiver.java
73         examples/pingPong/PingPongTest.java
74 )
75
76 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror ")
77
78 set(INCLUDE_PATH "-I${CMAKE_HOME_DIRECTORY}/src -I$ENV{SIMGRID_ROOT}/include -I$ENV{SIMGRID_ROOT}/src -I$ENV{SIMGRID_ROOT}/src/include")
79 set(LIB_PATH "-L$ENV{SIMGRID_ROOT}/lib")
80
81 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${INCLUDE_PATH} ${LIB_PATH}")
82
83 string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/org/" JAVA_FILES "${JMSG_JAVA_SRC}") 
84
85 string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/classes/org/" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC}")
86 string(REPLACE ".java" ".class" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC_CLASS}")
87
88 string(REPLACE "examples/" "${CMAKE_HOME_DIRECTORY}/examples/" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES}") 
89 string(REPLACE ".java" ".class" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES_CLASS}")
90
91 # TARGET SG_java
92 add_library(SG_java SHARED ${JMSG_C_SRC})
93 target_link_libraries(SG_java -lsimgrid)
94 set_target_properties(SG_java PROPERTIES VERSION ${soversion})
95   
96 # TARGET java_classes
97 add_custom_command(
98         OUTPUT  ${JMSG_JAVA_SRC_CLASS}
99         DEPENDS ${JMSG_JAVA_SRC}
100         COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
101         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
102                                         -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JAVA_FILES}
103         COMMENT "Compiling java sources of core library..."                                     
104 )
105 add_custom_target(java_classes ALL
106   DEPENDS ${JMSG_JAVA_SRC_CLASS}                
107 )
108
109 # TARGET simgrid_jar
110 add_custom_target(simgrid_jar ALL
111   COMMAND ${JAVA_ARCHIVE} -cvf ${CMAKE_HOME_DIRECTORY}/simgrid.jar .
112   COMMENT "Building simgrid.jar..."
113   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/classes 
114 )
115
116 # TARGET simgrid_java_examples
117 add_custom_command(
118         COMMENT "Build examples for java"
119         OUTPUT  ${JAVA_EXAMPLES_CLASS}
120         
121         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java  
122         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/pingPong/*.java
123         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
124         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java                                 
125 )
126 add_custom_target(simgrid_java_examples ALL
127         DEPENDS ${JAVA_EXAMPLES_CLASS}
128 )
129
130 # Declare dependencies
131 add_dependencies(simgrid_jar java_classes)
132 add_dependencies(simgrid_java_examples simgrid_jar SG_java)
133
134 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
135 ${CMAKE_HOME_DIRECTORY}/simgrid.jar
136 )
137
138 #####################
139 # Declare our tests #
140 #####################
141 INCLUDE(CTest)
142 ENABLE_TESTING()
143
144 ADD_TEST(java-basic     ${CMAKE_HOME_DIRECTORY}/test_java.sh ${CMAKE_HOME_DIRECTORY}/examples basic/BasicTest ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/basic/)
145 ADD_TEST(java-pingpong  ${CMAKE_HOME_DIRECTORY}/test_java.sh ${CMAKE_HOME_DIRECTORY}/examples pingPong/PingPongTest ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/pingPong/)