Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't malloc data if mysmysocket->remaining equals 0, just return.
[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 add_library(gras SHARED ${gras_sources})
15 set_target_properties(gras PROPERTIES VERSION ${libgras_version})
16
17 if(enable_lib_static)
18         add_library(simgrid_static STATIC ${simgrid_sources})   
19 endif(enable_lib_static)
20
21 if(enable_smpi)
22         add_library(smpi SHARED ${SMPI_SRC})
23         set_target_properties(smpi PROPERTIES VERSION ${libsmpi_version})
24         if(enable_lib_static)
25                 add_library(smpi_static STATIC ${SMPI_SRC})     
26         endif(enable_lib_static)
27 endif(enable_smpi)
28
29 add_dependencies(gras maintainer_files)
30 add_dependencies(simgrid maintainer_files)                              
31
32 # if supernovaeing, we need some depends to make sure that the source gets generated
33 if (enable_supernovae)
34         add_dependencies(simgrid ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
35         if(enable_lib_static)
36                 add_dependencies(simgrid_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
37         endif(enable_lib_static)
38         add_dependencies(gras ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c)
39
40         if(enable_smpi)
41                 add_dependencies(smpi ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
42                 if(enable_lib_static)
43                         add_dependencies(smpi_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
44                 endif(enable_lib_static)
45         endif(enable_smpi)
46 endif(enable_supernovae)        
47
48 # Compute the dependencies of GRAS
49 ##################################
50 set(GRAS_DEP "-lm -lpthread")
51
52 if(HAVE_POSIX_GETTIME)
53         SET(GRAS_DEP "${GRAS_DEP} -lrt")
54 endif(HAVE_POSIX_GETTIME)
55
56 # the following is probably unneed since it kills the previous
57 # GRAS_DEP (and is thus probably invalid).
58 # My guess is that pthread is never true [Mt]
59 # FIXME: KILLME if we get a working windows with that?
60 if(with_context MATCHES windows)
61 if(pthread)
62                 SET(GRAS_DEP "msg")
63 endif(pthread)
64 endif(with_context MATCHES windows)
65 target_link_libraries(gras      ${GRAS_DEP})
66
67 # Compute the dependencies of SimGrid
68 #####################################
69 set(SIMGRID_DEP "-lm")
70 if(HAVE_PCRE_LIB)
71        SET(SIMGRID_DEP "${SIMGRID_DEP} -lpcre")
72 endif(HAVE_PCRE_LIB)
73
74 if(pthread)
75         if(${CONTEXT_THREADS})
76                 SET(SIMGRID_DEP "${SIMGRID_DEP} -lpthread")
77         endif(${CONTEXT_THREADS})       
78 endif(pthread)
79
80 if(HAVE_LUA)      
81     ADD_CUSTOM_TARGET(link_simgrid_lua ALL
82       DEPENDS   simgrid
83                         ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
84                                 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
85                                 ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
86         )
87         add_custom_command(
88                 OUTPUT  ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
89                                 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
90                                 ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
91                 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
92                 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
93                 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
94                 
95                 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
96                 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
97                 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
98                 
99                 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
100                 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
101                 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test                       
102         )
103         SET(SIMGRID_DEP "${SIMGRID_DEP} -l${LIB_LUA_NAME}")       
104 endif(HAVE_LUA)
105
106 if(HAVE_GRAPHVIZ)
107     if(HAVE_CGRAPH_LIB)
108             SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
109         else(HAVE_CGRAPH_LIB)
110         if(HAVE_AGRAPH_LIB)
111             SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
112         endif(HAVE_AGRAPH_LIB)  
113     endif(HAVE_CGRAPH_LIB)          
114 endif(HAVE_GRAPHVIZ)
115
116 if(HAVE_GTNETS)
117         SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets")
118 endif(HAVE_GTNETS)
119
120 if(HAVE_NS3)
121     if(${NS3_VERSION} EQUAL 310)
122             SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
123             set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
124             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
125         else(${NS3_VERSION} EQUAL 310)
126             SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3-core -lns3-csma -lns3-point-to-point")
127         endif(${NS3_VERSION} EQUAL 310)
128 endif(HAVE_NS3)
129
130 if(HAVE_NS3 AND HAVE_RED_QUEUE_H)
131             set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_HAVE_NS3_RED")
132             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_HAVE_NS3_RED")
133 endif(HAVE_NS3 AND HAVE_RED_QUEUE_H)
134
135 if(HAVE_POSIX_GETTIME)
136         SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
137 endif(HAVE_POSIX_GETTIME)
138
139 target_link_libraries(simgrid   ${SIMGRID_DEP})
140
141 # Compute the dependencies of SMPI
142 ##################################
143 set(SMPI_LDEP "")
144 if(APPLE)
145     set(SMPI_LDEP "-Wl,-U -Wl,_smpi_simulated_main")
146 endif(APPLE)
147 if(enable_smpi)
148         target_link_libraries(smpi      simgrid ${SMPI_LDEP})
149 endif(enable_smpi)
150
151 # Pass dependencies to static libs
152 ##################################
153 if(enable_lib_static)
154         target_link_libraries(simgrid_static    ${SIMGRID_DEP})
155         add_dependencies(simgrid_static maintainer_files)
156         set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
157         if(enable_smpi)
158                 target_link_libraries(smpi_static       simgrid ${SMPI_LDEP})
159                 set_target_properties(smpi_static PROPERTIES OUTPUT_NAME smpi)
160         endif(enable_smpi)
161 endif(enable_lib_static)