Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
838739c03f4fbdc9c4414b7a7948473db3bac21f
[simgrid.git] / buildtools / Cmake / MakeLib.cmake
1 ### Make Libs
2
3 ###############################
4 # Declare the library content #
5 ###############################
6
7 # Actually declare our libraries
8 add_library(simgrid SHARED ${simgrid_sources})
9 set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version})
10
11 if(enable_lib_static)
12   add_library(simgrid_static STATIC ${simgrid_sources})
13 endif()
14
15 if(enable_ust)
16   ADD_DEPENDENCIES(simgrid simgrid_ust)
17 endif()
18
19 if(enable_java)
20   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
21 endif()
22
23 add_dependencies(simgrid maintainer_files)
24
25 if(enable_model-checking)
26   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
27   target_link_libraries(simgrid-mc simgrid)
28   set_target_properties(simgrid-mc
29     PROPERTIES
30       RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
31 endif()
32
33 # Compute the dependencies of SimGrid
34 #####################################
35 set(SIMGRID_DEP "-lm")
36 if (HAVE_BOOST_CONTEXT)
37   set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
38 endif()
39
40 if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"
41     AND NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 10.0
42     AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
43   # FreeBSD from 10.0 provide a internal C++ stack (unused by gcc)
44   # see https://wiki.freebsd.org/NewC%2B%2BStack
45   set(SIMGRID_DEP "${SIMGRID_DEP} -lc++")
46 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"
47     AND ${CMAKE_SYSTEM_VERSION} VERSION_LESS 10.0
48     AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
49   # FreeBSD prior to 10.0 does not necessarily have a compiler
50   # installed that is capable of c++11! Hence, we just assume
51   # here that libc++ was compiled.
52   # FIXME: We should change this behavior; we may want to include
53   # an option of whether libc++ (clang++) or libstdc++ (g++)
54   # should be used.
55   include_directories( "/usr/local/include/c++/v1")
56   set(SIMGRID_DEP "${SIMGRID_DEP} -lc++ -L/usr/local/lib ")
57 else()
58   set(SIMGRID_DEP "${SIMGRID_DEP} -lstdc++")
59 endif()
60
61 if(pthread AND ${CONTEXT_THREADS} AND NOT APPLE)
62   # Clang on recent Mac OS X is not happy about -pthread.
63   SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
64 endif()
65
66 if(HAVE_LUA)
67   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
68     DEPENDS     simgrid
69     ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
70     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
71     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
72     )
73   add_custom_command(
74     OUTPUT      ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
75     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
76     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
77     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
78     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
79     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
80
81     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
82     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
83     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
84
85     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
86     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
87     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test
88     )
89   SET(SIMGRID_DEP "${SIMGRID_DEP} -l${LIB_LUA_NAME}")
90 endif()
91
92 if(HAVE_GRAPHVIZ)
93   if(HAVE_CGRAPH_LIB)
94     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
95   else()
96     if(HAVE_AGRAPH_LIB)
97       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
98     endif()
99   endif()
100 endif()
101
102 if(HAVE_LIBSIGC++)
103   SET(SIMGRID_DEP "${SIMGRID_DEP} -lsigc-2.0")
104 endif()
105
106 if(HAVE_GTNETS)
107   SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets")
108 endif()
109
110 if(enable_mc_content_adressable_pages)
111   SET(SIMGRID_DEP "${SIMGRID_DEP} -lnettle")
112 endif()
113
114 if(HAVE_MC)
115   # The availability of libunwind was checked in CompleteInFiles.cmake
116   #   (that includes FindLibunwind.cmake), so simply load it now.
117
118   SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind -lunwind-ptrace")
119
120   # Same for libdw
121   SET(SIMGRID_DEP "${SIMGRID_DEP} -ldw")
122   # This supposes that the host machine is either an AMD or a X86.
123   # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
124   if(PROCESSOR_x86_64)
125     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
126   else()
127     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
128   endif()
129 endif()
130
131 if(MMALLOC_WANT_OVERRIDE_LEGACY AND HAVE_GNU_LD)
132   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
133 endif()
134
135 if(HAVE_NS3)
136   if(${NS3_VERSION_MINOR} EQUAL 10)
137     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
138     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
139     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
140   else()
141     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3.${NS3_VERSION_MINOR}-core -lns3.${NS3_VERSION_MINOR}-csma -lns3.${NS3_VERSION_MINOR}-point-to-point -lns3.${NS3_VERSION_MINOR}-internet -lns3.${NS3_VERSION_MINOR}-applications")
142   endif()
143 endif()
144
145 if(HAVE_POSIX_GETTIME)
146   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
147 endif()
148
149 if(HAVE_BACKTRACE_IN_LIBEXECINFO)
150   SET(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
151 endif(HAVE_BACKTRACE_IN_LIBEXECINFO)
152
153 # Dependencies from USR
154 ###################################
155 if(enable_ust)
156   set(SIMGRID_DEP "${SIMGRID_DEP} -llttng-ust")
157 endif()
158
159 # Compute the dependencies of SMPI
160 ##################################
161 if(enable_smpi AND APPLE)
162   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
163 endif()
164
165 target_link_libraries(simgrid   ${SIMGRID_DEP})
166
167 # Pass dependencies to static libs
168 ##################################
169 if(enable_lib_static)
170   target_link_libraries(simgrid_static  ${SIMGRID_DEP})
171   add_dependencies(simgrid_static maintainer_files)
172   set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
173 endif()
174
175 # Dependencies from maintainer mode
176 ###################################
177 if(enable_maintainer_mode AND PYTHON_EXE)
178   add_dependencies(simgrid simcalls_generated_src)
179 endif()
180 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
181   add_dependencies(simgrid automaton_generated_src)
182 endif()