Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compile the safe part of MC in default mode too
[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 # TODO: is it still useful now that Java is gone? For Python maybe?
6 set(CMAKE_MACOSX_RPATH TRUE)
7 if(APPLE)
8   SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # When installed, use system path
9   set(CMAKE_SKIP_BUILD_RPATH FALSE)         # When executing from build tree, take the lib from the build path if exists
10   set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # When executing from build tree, take the lib from the system path if exists
11
12   # add the current location of libsimgrid-java.dynlib as a location for libsimgrid.dynlib
13   # (useful when unpacking the native libraries from the jarfile)
14   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
15 endif()
16
17 ###############################
18 # Declare the library content #
19 ###############################
20
21 # Actually declare our libraries
22 add_library(simgrid SHARED ${simgrid_sources})
23 set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version})
24 # The library can obviously use the internal headers
25 set_property(TARGET simgrid
26              APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
27
28 add_dependencies(simgrid maintainer_files)
29
30 if("${CMAKE_SYSTEM}" MATCHES "Linux")
31   add_library(sthread SHARED ${STHREAD_SRC})
32   set_property(TARGET sthread
33                 APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
34   target_link_libraries(sthread simgrid)
35 else()
36   set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC})
37 endif()
38
39 if(HAVE_MMALLOC)
40   add_library(sgmalloc SHARED ${SGMALLOC_SRC})
41   set_property(TARGET sgmalloc
42                 APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
43 endif()
44
45 add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
46 target_link_libraries(simgrid-mc simgrid)
47 set_target_properties(simgrid-mc
48                       PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
49 set_property(TARGET simgrid-mc
50               APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
51 install(TARGETS simgrid-mc # install that binary without breaking the rpath on Mac
52   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/)
53 add_dependencies(tests-mc simgrid-mc)
54 if("${CMAKE_SYSTEM}" MATCHES "Linux")
55   add_dependencies(tests-mc sthread)
56 endif()
57
58 # Compute the dependencies of SimGrid
59 #####################################
60 # search for dlopen
61 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
62   find_library(DL_LIBRARY dl)
63 endif()
64 mark_as_advanced(DL_LIBRARY)
65
66 if (HAVE_BOOST_CONTEXTS)
67   target_link_libraries(simgrid ${Boost_CONTEXT_LIBRARY})
68 endif()
69
70 if (HAVE_BOOST_STACKTRACE_BACKTRACE)
71   target_link_libraries(simgrid ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
72 endif()
73
74 if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
75   target_link_libraries(simgrid ${Boost_STACKTRACE_ADDR2LINE_LIBRARY})
76 endif()
77
78 if(CMAKE_USE_PTHREADS_INIT)
79   target_link_libraries(simgrid ${CMAKE_THREAD_LIBS_INIT})
80 endif()
81
82 if(HAVE_PAPI)
83   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
84 endif()
85
86 if(HAVE_GRAPHVIZ)
87   if(HAVE_CGRAPH_LIB)
88     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
89   else()
90     if(HAVE_AGRAPH_LIB)
91       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
92     endif()
93   endif()
94 endif()
95
96 if(SIMGRID_HAVE_JSON)
97   target_link_libraries(simgrid  nlohmann_json::nlohmann_json)
98 endif()
99
100 if(NOT ${DL_LIBRARY} STREQUAL "")
101   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
102 endif()
103
104 if(HAVE_POSIX_GETTIME)
105   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
106 endif()
107
108 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
109   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
110 endif()
111
112 # Compute the dependencies of SMPI
113 ##################################
114
115 if(enable_smpi)
116   add_executable(smpimain src/smpi/smpi_main.c)
117   target_link_libraries(smpimain simgrid)
118   set_target_properties(smpimain
119     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
120   install(TARGETS smpimain # install that binary without breaking the rpath on Mac
121     RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
122   add_dependencies(tests smpimain)
123
124   add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
125   target_compile_options(smpireplaymain PRIVATE -fpic)
126   target_link_libraries(smpireplaymain simgrid -fpic -shared)
127   set_target_properties(smpireplaymain
128     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
129   install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
130     RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
131   add_dependencies(tests smpireplaymain)
132
133   if(SMPI_FORTRAN)
134     if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
135       SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
136     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
137       SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
138     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
139       SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
140       if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
141         set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
142         if ("${CMAKE_SYSTEM_VERSION}" STRGREATER_EQUAL "12")
143             set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
144         endif()
145         if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12\\.1")
146             set(SIMGRID_DEP "${SIMGRID_DEP} -lomp")
147         endif()
148       endif()
149     endif()
150   endif()
151
152 endif()
153
154 if(enable_smpi AND APPLE)
155   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
156 endif()
157
158 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
159 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
160   HINTS
161     $ENV{HOME}/local/lib64
162     $ENV{HOME}/local/lib
163     /usr/local/lib64
164     /usr/local/lib
165     /opt/local/lib64
166     /opt/local/lib
167     /usr/lib64
168     /usr/lib
169     /lib64
170     /lib
171 )
172
173 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
174 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
175     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,--as-needed -latomic -Wl,--no-as-needed")
176 endif()
177 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
178
179 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
180     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,-znorelro -Wl,-znoseparate-code")
181 endif()
182
183 target_link_libraries(simgrid   ${SIMGRID_DEP})
184
185 # Dependencies from maintainer mode
186 ###################################
187 if(enable_maintainer_mode)
188   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
189 endif()
190 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
191   add_dependencies(simgrid automaton_generated_src)
192 endif()