Logo AND Algorithmique Numérique Distribuée

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