Logo AND Algorithmique Numérique Distribuée

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