Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'actor-yield' of github.com:Takishipp/simgrid into actor-yield
[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     )
48   SET(SIMGRID_DEP "${SIMGRID_DEP} ${LUA_LIBRARY} ${DL_LIBRARY}")
49 endif()
50
51 if(HAVE_PAPI)
52   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
53 endif()
54
55 if(HAVE_GRAPHVIZ)
56   if(HAVE_CGRAPH_LIB)
57     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
58   else()
59     if(HAVE_AGRAPH_LIB)
60       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
61     endif()
62   endif()
63 endif()
64
65 if(SIMGRID_HAVE_MC AND HAVE_GNU_LD AND NOT ${DL_LIBRARY} STREQUAL "")
66   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
67 endif()
68
69 if(SIMGRID_HAVE_NS3)
70   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}")
71 endif()
72
73 if(HAVE_POSIX_GETTIME)
74   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
75 endif()
76
77 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
78   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
79 endif()
80
81 # Compute the dependencies of SMPI
82 ##################################
83
84 if(enable_smpi)
85   if(NOT ${DL_LIBRARY} STREQUAL "")
86     set(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}") # for privatization
87   endif()
88   add_executable(smpimain src/smpi/smpi_main.c)
89   target_link_libraries(smpimain simgrid)
90   set_target_properties(smpimain
91     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
92 endif()
93
94 if(enable_smpi AND APPLE)
95   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
96 endif()
97
98 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
99 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
100   HINTS
101     $ENV{HOME}/local/lib64
102     $ENV{HOME}/local/lib
103     /usr/local/lib64
104     /usr/local/lib
105     /opt/local/lib64
106     /opt/local/lib
107     /usr/lib64
108     /usr/lib
109     /lib64
110     /lib
111 )
112
113 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
114 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
115     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,--as-needed -latomic -Wl,--no-as-needed")
116 endif()
117
118 target_link_libraries(simgrid   ${SIMGRID_DEP})
119
120 # Dependencies from maintainer mode
121 ###################################
122 if(enable_maintainer_mode)
123   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
124 endif()
125 if(enable_maintainer_mode AND PYTHON_EXE)
126   add_dependencies(simgrid simcalls_generated_src)
127 endif()
128 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
129   add_dependencies(simgrid automaton_generated_src)
130 endif()