Logo AND Algorithmique Numérique Distribuée

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