Logo AND Algorithmique Numérique Distribuée

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