Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Boost.Context context factory
[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 set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
37
38 if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"
39     AND NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 10.0
40     AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
41   # FreeBSD from 10.0 provide a internal C++ stack (unused by gcc)
42   # see https://wiki.freebsd.org/NewC%2B%2BStack
43   set(SIMGRID_DEP "${SIMGRID_DEP} -lc++")
44 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"
45     AND ${CMAKE_SYSTEM_VERSION} VERSION_LESS 10.0
46     AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
47   # FreeBSD prior to 10.0 does not necessarily have a compiler
48   # installed that is capable of c++11! Hence, we just assume
49   # here that libc++ was compiled.
50   # FIXME: We should change this behavior; we may want to include
51   # an option of whether libc++ (clang++) or libstdc++ (g++)
52   # should be used.
53   include_directories( "/usr/local/include/c++/v1")
54   set(SIMGRID_DEP "${SIMGRID_DEP} -lc++ -L/usr/local/lib ")
55 else()
56   set(SIMGRID_DEP "${SIMGRID_DEP} -lstdc++")
57 endif()
58
59 if(pthread)
60   if(${CONTEXT_THREADS})
61     SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
62   endif()
63 endif()
64
65 if(HAVE_LUA)
66   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
67     DEPENDS     simgrid
68     ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
69     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
70     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
71     )
72   add_custom_command(
73     OUTPUT      ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
74     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
75     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
76     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
77     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
78     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
79
80     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
81     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
82     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
83
84     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
85     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
86     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test
87     )
88   SET(SIMGRID_DEP "${SIMGRID_DEP} -l${LIB_LUA_NAME}")
89 endif()
90
91 if(HAVE_GRAPHVIZ)
92   if(HAVE_CGRAPH_LIB)
93     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
94   else()
95     if(HAVE_AGRAPH_LIB)
96       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
97     endif()
98   endif()
99 endif()
100
101 if(HAVE_LIBSIGC++)
102   SET(SIMGRID_DEP "${SIMGRID_DEP} -lsigc-2.0")
103 endif()
104
105 if(HAVE_GTNETS)
106   SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets")
107 endif()
108
109 if(enable_mc_content_adressable_pages)
110   SET(SIMGRID_DEP "${SIMGRID_DEP} -lnettle")
111 endif()
112
113 if(HAVE_MC)
114   # The availability of libunwind was checked in CompleteInFiles.cmake
115   #   (that includes FindLibunwind.cmake), so simply load it now.
116
117   SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind -lunwind-ptrace")
118
119   # Same for libdw
120   SET(SIMGRID_DEP "${SIMGRID_DEP} -ldw")
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} ${DL_LIBRARY}")
132 endif()
133
134 if(HAVE_NS3)
135   if(${NS3_VERSION_MINOR} EQUAL 10)
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.${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")
141   endif()
142 endif()
143
144 if(HAVE_POSIX_GETTIME)
145   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
146 endif()
147
148 if(HAVE_BACKTRACE_IN_LIBEXECINFO)
149   SET(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
150 endif(HAVE_BACKTRACE_IN_LIBEXECINFO)
151
152 # Dependencies from USR
153 ###################################
154 if(enable_ust)
155   set(SIMGRID_DEP "${SIMGRID_DEP} -llttng-ust")
156 endif()
157
158 # Compute the dependencies of SMPI
159 ##################################
160 if(enable_smpi AND APPLE)
161   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
162 endif()
163
164 target_link_libraries(simgrid   ${SIMGRID_DEP})
165
166 # Pass dependencies to static libs
167 ##################################
168 if(enable_lib_static)
169   target_link_libraries(simgrid_static  ${SIMGRID_DEP})
170   add_dependencies(simgrid_static maintainer_files)
171   set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
172 endif()
173
174 # Dependencies from maintainer mode
175 ###################################
176 if(enable_maintainer_mode AND PYTHON_EXE)
177   add_dependencies(simgrid simcalls_generated_src)
178 endif()
179 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
180   add_dependencies(simgrid automaton_generated_src)
181 endif()