Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
09cd2818e9da4ea6e90302b318063f3c087809ca
[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 endif()
49
50 add_dependencies(simgrid maintainer_files)
51
52 # if supernovaeing, we need some depends to make sure that the source gets generated
53 if (enable_supernovae)
54   add_dependencies(simgrid ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
55   if(enable_lib_static)
56     add_dependencies(simgrid_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
57   endif()
58
59   if(enable_smpi)
60     add_dependencies(smpi ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
61     if(enable_lib_static)
62       add_dependencies(smpi_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
63     endif()
64   endif()
65 endif()
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(MMALLOC_WANT_OVERRIDE_LEGACY AND HAVE_GNU_LD)
131   SET(SIMGRID_DEP "${SIMGRID_DEP} -ldl")
132 endif()
133
134 if(HAVE_NS3)
135   if(${NS3_VERSION} EQUAL 310)
136     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
137     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
138     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
139   else()
140     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3-core -lns3-csma -lns3-point-to-point -lns3-internet -lns3-applications")
141   endif()
142 endif()
143
144 if(HAVE_POSIX_GETTIME)
145   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
146 endif()
147
148 target_link_libraries(simgrid   ${SIMGRID_DEP})
149
150 # Compute the dependencies of SMPI
151 ##################################
152 set(SMPI_DEP "")
153 if(APPLE)
154   set(SMPI_DEP "-Wl,-U -Wl,_smpi_simulated_main")
155 endif()
156 if(enable_smpi)
157   target_link_libraries(smpi    simgrid ${SMPI_DEP})
158 endif()
159
160 # Pass dependencies to static libs
161 ##################################
162 if(enable_lib_static)
163   target_link_libraries(simgrid_static  ${SIMGRID_DEP})
164   add_dependencies(simgrid_static maintainer_files)
165   set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
166   if(enable_smpi)
167     target_link_libraries(smpi_static   simgrid ${SMPI_DEP})
168     set_target_properties(smpi_static PROPERTIES OUTPUT_NAME smpi)
169   endif()
170 endif()
171
172 # Dependencies from maintainer mode
173 ###################################
174 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
175   add_dependencies(simgrid automaton_generated_src)
176 endif()