Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1378bd485cc8d5e4651bdf9ec0560b14670e7b08
[simgrid.git] / tools / cmake / MakeLib.cmake
1 ### Make Libs
2
3 # On Mac OSX, specify that rpath is useful to look for the dependencies
4 # See https://cmake.org/Wiki/CMake_RPATH_handling and Java.cmake
5 set(MACOSX_RPATH ON)
6 if(APPLE)
7   # add the current location of libsimgrid-java.dynlib as a location for libsimgrid.dynlib
8   # (useful when unpacking the native libraries from the jarfile)
9   set(CMAKE_INSTALL_RPATH "@loader_path/.")
10   SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
11 endif()
12
13 ###############################
14 # Declare the library content #
15 ###############################
16
17 # Actually declare our libraries
18 add_library(simgrid SHARED ${simgrid_sources})
19 set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version})
20
21 add_dependencies(simgrid maintainer_files)
22
23 if(enable_model-checking)
24   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
25   target_link_libraries(simgrid-mc simgrid)
26   set_target_properties(simgrid-mc
27     PROPERTIES
28       RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
29 endif()
30
31 # Compute the dependencies of SimGrid
32 #####################################
33 if (HAVE_BOOST_CONTEXTS)
34   set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
35 endif()
36
37 if(HAVE_PTHREAD AND ${HAVE_THREAD_CONTEXTS} AND NOT APPLE)
38   # Clang on recent Mac OS X is not happy about -pthread.
39   SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
40 endif()
41
42 if(SIMGRID_HAVE_LUA)
43   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
44     DEPENDS     simgrid
45     ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
46     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
47     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
48     )
49   add_custom_command(
50     OUTPUT      ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
51     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
52     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
53     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
54     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
55     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
56
57     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
58     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
59     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
60
61     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
62     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
63     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test
64     )
65   SET(SIMGRID_DEP "${SIMGRID_DEP} ${LUA_LIBRARY} ${DL_LIBRARY}")
66 endif()
67
68 if(HAVE_PAPI)
69   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
70 endif()
71
72 if(HAVE_GRAPHVIZ)
73   if(HAVE_CGRAPH_LIB)
74     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
75   else()
76     if(HAVE_AGRAPH_LIB)
77       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
78     endif()
79   endif()
80 endif()
81
82 if(SIMGRID_HAVE_MC AND HAVE_GNU_LD AND NOT ${DL_LIBRARY} STREQUAL "")
83   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
84 endif()
85
86 if(SIMGRID_HAVE_NS3)
87   SET(SIMGRID_DEP "${SIMGRID_DEP} -lns${NS3_VERSION}-core${NS3_SUFFIX} -lns${NS3_VERSION}-csma${NS3_SUFFIX} -lns${NS3_VERSION}-point-to-point${NS3_SUFFIX} -lns${NS3_VERSION}-internet${NS3_SUFFIX} -lns${NS3_VERSION}-applications${NS3_SUFFIX}")
88 endif()
89
90 if(HAVE_POSIX_GETTIME)
91   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
92 endif()
93
94 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
95   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
96 endif()
97
98 # Compute the dependencies of SMPI
99 ##################################
100
101 if(enable_smpi)
102   if(NOT ${DL_LIBRARY} STREQUAL "")
103     set(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}") # for privatization
104   endif()
105   add_executable(smpimain src/smpi/smpi_main.c)
106   target_link_libraries(smpimain simgrid)
107   set_target_properties(smpimain
108     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
109 endif()
110
111 if(enable_smpi AND APPLE)
112   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
113 endif()
114
115 target_link_libraries(simgrid   ${SIMGRID_DEP})
116
117 # Dependencies from maintainer mode
118 ###################################
119 if(enable_maintainer_mode)
120   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
121 endif()
122 if(enable_maintainer_mode AND PYTHON_EXE)
123   add_dependencies(simgrid simcalls_generated_src)
124 endif()
125 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
126   add_dependencies(simgrid automaton_generated_src)
127 endif()