Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8d65b90e604a6fa6e21f07a2e1203eaf88a5c06d
[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 # The library can obviously use the internal headers
24 set_property(TARGET simgrid
25              APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
26
27 add_dependencies(simgrid maintainer_files)
28
29 if(enable_model-checking)
30   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
31   target_link_libraries(simgrid-mc simgrid)
32   set_target_properties(simgrid-mc
33                         PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
34   set_property(TARGET simgrid-mc
35                APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
36
37 endif()
38
39
40 # Compute the dependencies of SimGrid
41 #####################################
42 if (HAVE_BOOST_CONTEXTS)
43   set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
44 endif()
45
46 if(CMAKE_USE_PTHREADS_INIT AND ${HAVE_THREAD_CONTEXTS})
47   set(SIMGRID_DEP "${SIMGRID_DEP} ${CMAKE_THREAD_LIBS_INIT}")
48 endif()
49
50 if(SIMGRID_HAVE_LUA)
51   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
52     DEPENDS     simgrid
53     )
54   SET(SIMGRID_DEP "${SIMGRID_DEP} ${LUA_LIBRARY} ${DL_LIBRARY}")
55 endif()
56
57 if(HAVE_PAPI)
58   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
59 endif()
60
61 if(HAVE_GRAPHVIZ)
62   if(HAVE_CGRAPH_LIB)
63     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
64   else()
65     if(HAVE_AGRAPH_LIB)
66       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
67     endif()
68   endif()
69 endif()
70
71 if(SIMGRID_HAVE_MC AND HAVE_GNU_LD AND NOT ${DL_LIBRARY} STREQUAL "")
72   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
73 endif()
74
75 if(HAVE_POSIX_GETTIME)
76   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
77 endif()
78
79 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
80   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
81 endif()
82
83 # Compute the dependencies of SMPI
84 ##################################
85
86 if(enable_smpi)
87   if(NOT ${DL_LIBRARY} STREQUAL "")
88     set(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}") # for privatization
89   endif()
90   add_executable(smpimain src/smpi/smpi_main.c)
91   target_link_libraries(smpimain simgrid)
92   set_target_properties(smpimain
93     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
94 endif()
95
96 if(enable_smpi AND APPLE)
97   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
98 endif()
99
100 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
101 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
102   HINTS
103     $ENV{HOME}/local/lib64
104     $ENV{HOME}/local/lib
105     /usr/local/lib64
106     /usr/local/lib
107     /opt/local/lib64
108     /opt/local/lib
109     /usr/lib64
110     /usr/lib
111     /lib64
112     /lib
113 )
114
115 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
116 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
117     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,--as-needed -latomic -Wl,--no-as-needed")
118 endif()
119
120 target_link_libraries(simgrid   ${SIMGRID_DEP})
121
122 # Dependencies from maintainer mode
123 ###################################
124 if(enable_maintainer_mode)
125   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
126 endif()
127 if(enable_maintainer_mode AND PYTHON_EXE)
128   add_dependencies(simgrid simcalls_generated_src)
129 endif()
130 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
131   add_dependencies(simgrid automaton_generated_src)
132 endif()