Logo AND Algorithmique Numérique Distribuée

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