Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: switch to xxhash as a (fast) hashing function.
[simgrid.git] / tools / cmake / MakeLib.cmake
1 ### Make Libs
2
3 # On macOS, specify that rpath is useful to look for the dependencies
4 # See https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling and Java.cmake
5 set(CMAKE_MACOSX_RPATH TRUE)
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 "${CMAKE_INSTALL_PREFIX}/lib")
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   set_property(TARGET simgrid PROPERTY CXX_STANDARD 14)
31
32   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
33   target_link_libraries(simgrid-mc simgrid)
34   set_target_properties(simgrid-mc
35                         PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
36   set_property(TARGET simgrid-mc
37                APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
38   install(TARGETS simgrid-mc # install that binary without breaking the rpath on Mac
39     RUNTIME DESTINATION bin/)
40   add_dependencies(tests simgrid-mc)
41 endif()
42
43
44 # Compute the dependencies of SimGrid
45 #####################################
46 # search for dlopen
47 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
48   find_library(DL_LIBRARY dl)
49 endif()
50 mark_as_advanced(DL_LIBRARY)
51
52 if (HAVE_BOOST_CONTEXTS)
53   target_link_libraries(simgrid ${Boost_CONTEXT_LIBRARY})
54 endif()
55
56 if (HAVE_BOOST_STACKTRACE_BACKTRACE)
57   target_link_libraries(simgrid ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
58 endif()
59
60 if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
61   target_link_libraries(simgrid ${Boost_STACKTRACE_ADDR2LINE_LIBRARY})
62 endif()
63
64 if(CMAKE_USE_PTHREADS_INIT)
65   set(SIMGRID_DEP "${SIMGRID_DEP} ${CMAKE_THREAD_LIBS_INIT}")
66 endif()
67
68 if(SIMGRID_HAVE_LUA)
69   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
70     DEPENDS     simgrid
71     )
72   SET(SIMGRID_DEP "${SIMGRID_DEP} ${LUA_LIBRARY} ${DL_LIBRARY}")
73 endif()
74
75 if(HAVE_PAPI)
76   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
77 endif()
78
79 if(HAVE_GRAPHVIZ)
80   if(HAVE_CGRAPH_LIB)
81     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
82   else()
83     if(HAVE_AGRAPH_LIB)
84       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
85     endif()
86   endif()
87 endif()
88
89 if(SIMGRID_HAVE_MC AND NOT ${DL_LIBRARY} STREQUAL "")
90   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
91 endif()
92
93 if(HAVE_POSIX_GETTIME)
94   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
95 endif()
96
97 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
98   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
99 endif()
100
101 # Compute the dependencies of SMPI
102 ##################################
103
104 if(enable_smpi)
105   if(NOT ${DL_LIBRARY} STREQUAL "")
106     set(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}") # for privatization
107   endif()
108
109   add_executable(smpimain src/smpi/smpi_main.c)
110   target_link_libraries(smpimain simgrid)
111   set_target_properties(smpimain
112     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
113   install(TARGETS smpimain # install that binary without breaking the rpath on Mac
114     RUNTIME DESTINATION lib/simgrid)
115   add_dependencies(tests smpimain)
116
117   add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
118   target_compile_options(smpireplaymain PRIVATE -fpic)
119   target_link_libraries(smpireplaymain simgrid -fpic -shared)
120   set_target_properties(smpireplaymain
121     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
122   install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
123     RUNTIME DESTINATION lib/simgrid)
124   add_dependencies(tests smpireplaymain)
125
126   if(SMPI_FORTRAN)
127     if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
128       SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
129     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
130       SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
131     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
132       SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
133       if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
134         set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
135         if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12")
136             set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
137         endif()
138       endif()
139     endif()
140   endif()
141
142 endif()
143
144 if(enable_smpi AND APPLE)
145   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
146 endif()
147
148 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
149 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
150   HINTS
151     $ENV{HOME}/local/lib64
152     $ENV{HOME}/local/lib
153     /usr/local/lib64
154     /usr/local/lib
155     /opt/local/lib64
156     /opt/local/lib
157     /usr/lib64
158     /usr/lib
159     /lib64
160     /lib
161 )
162
163 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
164 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
165     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,--as-needed -latomic -Wl,--no-as-needed")
166 endif()
167 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
168
169 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
170     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,-znoseparate-code")
171 endif()
172
173 target_link_libraries(simgrid   ${SIMGRID_DEP})
174
175 # Dependencies from maintainer mode
176 ###################################
177 if(enable_maintainer_mode)
178   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
179 endif()
180 if(enable_maintainer_mode AND PYTHON_EXE)
181   add_dependencies(simgrid simcalls_generated_src)
182 endif()
183 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
184   add_dependencies(simgrid automaton_generated_src)
185 endif()