Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve dependencies around simgrid.jar (again).
[simgrid.git] / buildtools / Cmake / MakeLib.cmake
1 ### Make Libs
2
3 ###############################
4 # Declare the library content #
5 ###############################
6 # If we want supernovae, rewrite the libs' content to use it
7 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Supernovae.cmake)
8
9 # Actually declare our libraries
10
11 add_library(simgrid SHARED ${simgrid_sources})
12 set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version})
13
14 if(enable_lib_static)
15   add_library(simgrid_static STATIC ${simgrid_sources})
16 endif()
17
18 if(enable_smpi)
19   add_library(smpi SHARED ${SMPI_SRC})
20   set_target_properties(smpi PROPERTIES VERSION ${libsmpi_version})
21   if(enable_lib_static)
22     add_library(smpi_static STATIC ${SMPI_SRC})
23   endif()
24 endif()
25
26 if(enable_java)
27   add_library(SG_java SHARED ${JMSG_C_SRC})
28   set_target_properties(SG_java PROPERTIES VERSION ${libSG_java_version})
29   get_target_property(COMMON_INCLUDES SG_java INCLUDE_DIRECTORIES)
30   set_target_properties(SG_java PROPERTIES
31     INCLUDE_DIRECTORIES "${COMMON_INCLUDES};${JNI_INCLUDE_DIRS}")
32   add_dependencies(SG_java simgrid)
33
34   if(WIN32)
35     get_target_property(SIMGRID_LIB_NAME_NAME SG_java LIBRARY_OUTPUT_NAME)
36     set_target_properties(SG_java PROPERTIES
37       LINK_FLAGS "-Wl,--subsystem,windows,--kill-at ${SIMGRID_LIB_NAME}"
38       PREFIX "")
39     find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
40     message(STATUS "pexports: ${PEXPORTS_PATH}")
41     if(PEXPORTS_PATH)
42       add_custom_command(TARGET SG_java POST_BUILD
43         COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/SG_java.dll > ${CMAKE_BINARY_DIR}/SG_java.def)
44     endif(PEXPORTS_PATH)
45   else()
46     target_link_libraries(SG_java simgrid)
47   endif()
48
49   set(CMAKE_JAVA_TARGET_OUTPUT_NAME simgrid)
50   add_jar(SG_java_pre_jar ${JMSG_JAVA_SRC})
51
52   set(SIMGRID_JAR "${CMAKE_BINARY_DIR}/simgrid.jar")
53   set(MANIFEST_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/MANIFEST.MF")
54
55   if(CMAKE_SYSTEM_PROCESSOR MATCHES ".86")
56     if(${ARCH_32_BITS})
57       set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/x86/")
58     else()
59       set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/amd64/")
60     endif()
61   else()
62     message(WARNING "Unknown system type. Processor: ${CMAKE_SYSTEM_PROCESSOR}; System: ${CMAKE_SYSTEM_NAME}")
63     set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR/")
64   endif()
65   message("Native libraries bundled into: ${JSG_BUNDLE}")
66
67   set(LIBSIMGRID_SO
68     ${CMAKE_SHARED_LIBRARY_PREFIX}simgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
69   set(LIBSG_JAVA_SO
70     ${CMAKE_SHARED_LIBRARY_PREFIX}SG_java${CMAKE_SHARED_LIBRARY_SUFFIX})
71
72   if(release)
73     set(STRIP_COMMAND "${CMAKE_STRIP}")
74   else()
75     set(STRIP_COMMAND "true")
76   endif()
77
78   add_custom_command(
79     COMMENT "Finalize simgrid.jar..."
80     OUTPUT ${SIMGRID_JAR}_finalized
81     DEPENDS simgrid SG_java SG_java_pre_jar
82             ${SIMGRID_JAR} ${MANIFEST_FILE}
83             ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
84             ${CMAKE_BINARY_DIR}/lib/${LIBSG_JAVA_SO}
85             ${CMAKE_HOME_DIRECTORY}/COPYING
86             ${CMAKE_HOME_DIRECTORY}/ChangeLog
87             ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
88     COMMAND ${CMAKE_COMMAND} -E remove_directory "NATIVE"
89     COMMAND ${CMAKE_COMMAND} -E make_directory "${JSG_BUNDLE}"
90     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}" "${JSG_BUNDLE}"
91     COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSIMGRID_SO}"
92     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSG_JAVA_SO}" "${JSG_BUNDLE}"
93     COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSG_JAVA_SO}"
94     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/COPYING" "${JSG_BUNDLE}"
95     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog" "${JSG_BUNDLE}"
96     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java" "${JSG_BUNDLE}"
97     COMMAND ${JAVA_ARCHIVE} -uvmf ${MANIFEST_FILE} ${SIMGRID_JAR} "NATIVE"
98     COMMAND ${CMAKE_COMMAND} -E remove ${SIMGRID_JAR}_finalized
99     COMMAND ${CMAKE_COMMAND} -E touch ${SIMGRID_JAR}_finalized
100     )
101   add_custom_target(SG_java_jar ALL DEPENDS ${SIMGRID_JAR}_finalized)
102 endif()
103
104 add_dependencies(simgrid maintainer_files)
105
106 # if supernovaeing, we need some depends to make sure that the source gets generated
107 if (enable_supernovae)
108   add_dependencies(simgrid ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
109   if(enable_lib_static)
110     add_dependencies(simgrid_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
111   endif()
112
113   if(enable_smpi)
114     add_dependencies(smpi ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
115     if(enable_lib_static)
116       add_dependencies(smpi_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
117     endif()
118   endif()
119 endif()
120
121 # Compute the dependencies of SimGrid
122 #####################################
123 set(SIMGRID_DEP "-lm -lpcre")
124
125 if(pthread)
126   if(${CONTEXT_THREADS})
127     SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
128   endif()
129 endif()
130
131 if(HAVE_LUA)
132   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
133     DEPENDS     simgrid
134     ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
135     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
136     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
137     )
138   add_custom_command(
139     OUTPUT      ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
140     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
141     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
142     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand
143     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
144     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
145
146     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand
147     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
148     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
149
150     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand
151     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
152     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test
153     )
154   SET(SIMGRID_DEP "${SIMGRID_DEP} -l${LIB_LUA_NAME}")
155 endif()
156
157 if(HAVE_GRAPHVIZ)
158   if(HAVE_CGRAPH_LIB)
159     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
160   else()
161     if(HAVE_AGRAPH_LIB)
162       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
163     endif()
164   endif()
165 endif()
166
167 if(HAVE_GTNETS)
168   SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets")
169 endif()
170
171 if(HAVE_MC)
172   # The availability of libunwind was checked in CompleteInFiles.cmake
173   #   (that includes FindLibunwind.cmake), so simply load it now.
174   
175   # This supposes that the host machine is either an AMD or a X86.
176   # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
177   if(PROCESSOR_x86_64)
178     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
179   else()    
180     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
181   endif()
182 endif()
183
184 if(MMALLOC_WANT_OVERRIDE_LEGACY AND HAVE_GNU_LD)
185   SET(SIMGRID_DEP "${SIMGRID_DEP} -ldl")
186 endif()
187
188 if(HAVE_NS3)
189   if(${NS3_VERSION} EQUAL 310)
190     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
191     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
192     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
193   else()
194     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3-core -lns3-csma -lns3-point-to-point -lns3-internet -lns3-applications")
195   endif()
196 endif()
197
198 if(HAVE_POSIX_GETTIME)
199   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
200 endif()
201
202 target_link_libraries(simgrid   ${SIMGRID_DEP})
203
204 # Compute the dependencies of SMPI
205 ##################################
206 set(SMPI_DEP "")
207 if(APPLE)
208   set(SMPI_DEP "-Wl,-U -Wl,_smpi_simulated_main")
209 endif()
210 if(enable_smpi)
211   target_link_libraries(smpi    simgrid ${SMPI_DEP})
212 endif()
213
214 # Pass dependencies to static libs
215 ##################################
216 if(enable_lib_static)
217   target_link_libraries(simgrid_static  ${SIMGRID_DEP})
218   add_dependencies(simgrid_static maintainer_files)
219   set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
220   if(enable_smpi)
221     target_link_libraries(smpi_static   simgrid ${SMPI_DEP})
222     set_target_properties(smpi_static PROPERTIES OUTPUT_NAME smpi)
223   endif()
224 endif()
225
226 # Dependencies from maintainer mode
227 ###################################
228 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
229   add_dependencies(simgrid automaton_generated_src)
230 endif()