Logo AND Algorithmique Numérique Distribuée

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