Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b848846979876d201000e6690fa7e6fbff053b1e
[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()
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()
27 endif()
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()
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()
45   endif()
46 endif()
47
48 # Compute the dependencies of GRAS
49 ##################################
50 set(GRAS_DEP "-lm -pthread")
51
52 if(HAVE_POSIX_GETTIME)
53   SET(GRAS_DEP "${GRAS_DEP} -lrt")
54 endif()
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()
64 endif()
65 target_link_libraries(gras      ${GRAS_DEP})
66
67 # Compute the dependencies of SimGrid
68 #####################################
69 set(SIMGRID_DEP "-lm -lpcre")
70
71 if(pthread)
72   if(${CONTEXT_THREADS})
73     SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
74   endif()
75 endif()
76
77 if(HAVE_LUA)
78   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
79     DEPENDS     simgrid
80     ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
81     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
82     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
83     )
84   add_custom_command(
85     OUTPUT      ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
86     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
87     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
88     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
89     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
90     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
91
92     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
93     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
94     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
95
96     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
97     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
98     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test
99     )
100   SET(SIMGRID_DEP "${SIMGRID_DEP} -l${LIB_LUA_NAME}")
101 endif()
102
103 if(HAVE_GRAPHVIZ)
104   if(HAVE_CGRAPH_LIB)
105     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
106   else()
107     if(HAVE_AGRAPH_LIB)
108       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
109     endif()
110   endif()
111 endif()
112
113 if(HAVE_GTNETS)
114   SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets")
115 endif()
116
117 if(HAVE_MC)
118   # The availability of libunwind was checked in CompleteInFiles.cmake
119   #   (that includes FindLibunwind.cmake), so simply load it now.
120   
121   # This supposes that the host machine is either an AMD or a X86.
122   # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
123   if(PROCESSOR_x86_64)
124     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
125   else()    
126     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
127   endif()
128 endif()
129
130 if(HAVE_NS3)
131   if(${NS3_VERSION} EQUAL 310)
132     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
133     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
134     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
135   else()
136     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3-core -lns3-csma -lns3-point-to-point -lns3-internet -lns3-applications")
137   endif()
138 endif()
139
140 if(HAVE_POSIX_GETTIME)
141   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
142 endif()
143
144 target_link_libraries(simgrid   ${SIMGRID_DEP})
145
146 # Compute the dependencies of SMPI
147 ##################################
148 set(SMPI_DEP "")
149 if(APPLE)
150   set(SMPI_DEP "-Wl,-U -Wl,_smpi_simulated_main")
151 endif()
152 if(enable_smpi)
153   target_link_libraries(smpi    simgrid ${SMPI_DEP})
154 endif()
155
156 # Pass dependencies to static libs
157 ##################################
158 if(enable_lib_static)
159   target_link_libraries(simgrid_static  ${SIMGRID_DEP})
160   add_dependencies(simgrid_static maintainer_files)
161   set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
162   if(enable_smpi)
163     target_link_libraries(smpi_static   simgrid ${SMPI_DEP})
164     set_target_properties(smpi_static PROPERTIES OUTPUT_NAME smpi)
165   endif()
166 endif()
167
168 # Dependencies from maintainer mode
169 ###################################
170 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
171   add_dependencies(simgrid automaton_generated_src)
172 endif()