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)
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
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}")
17 ###############################
18 # Declare the library content #
19 ###############################
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}")
28 add_dependencies(simgrid maintainer_files)
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)
36 set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC})
40 add_library(sgmalloc SHARED ${SGMALLOC_SRC})
41 set_property(TARGET sgmalloc
42 APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
45 if(enable_model-checking)
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)
60 # Compute the dependencies of SimGrid
61 #####################################
63 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
64 find_library(DL_LIBRARY dl)
66 mark_as_advanced(DL_LIBRARY)
68 if (HAVE_BOOST_CONTEXTS)
69 target_link_libraries(simgrid ${Boost_CONTEXT_LIBRARY})
72 if (HAVE_BOOST_STACKTRACE_BACKTRACE)
73 target_link_libraries(simgrid ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
76 if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
77 target_link_libraries(simgrid ${Boost_STACKTRACE_ADDR2LINE_LIBRARY})
80 if(CMAKE_USE_PTHREADS_INIT)
81 target_link_libraries(simgrid ${CMAKE_THREAD_LIBS_INIT})
85 SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
90 SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
93 SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
98 if(NOT ${DL_LIBRARY} STREQUAL "")
99 SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
102 if(HAVE_POSIX_GETTIME)
103 SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
106 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
107 set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
110 # Compute the dependencies of SMPI
111 ##################################
114 add_executable(smpimain src/smpi/smpi_main.c)
115 target_link_libraries(smpimain simgrid)
116 set_target_properties(smpimain
117 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
118 install(TARGETS smpimain # install that binary without breaking the rpath on Mac
119 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
120 add_dependencies(tests smpimain)
122 add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
123 target_compile_options(smpireplaymain PRIVATE -fpic)
124 target_link_libraries(smpireplaymain simgrid -fpic -shared)
125 set_target_properties(smpireplaymain
126 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
127 install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
128 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
129 add_dependencies(tests smpireplaymain)
132 if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
133 SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
134 elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
135 SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
136 elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
137 SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
138 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
139 set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
140 if ("${CMAKE_SYSTEM_VERSION}" STRGREATER_EQUAL "12")
141 set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
143 if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12\\.1")
144 set(SIMGRID_DEP "${SIMGRID_DEP} -lomp")
152 if(enable_smpi AND APPLE)
153 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
156 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
157 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
159 $ENV{HOME}/local/lib64
171 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
172 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
173 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,--as-needed -latomic -Wl,--no-as-needed")
175 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
177 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
178 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-znorelro -Wl,-znoseparate-code")
181 target_link_libraries(simgrid ${SIMGRID_DEP})
183 # Dependencies from maintainer mode
184 ###################################
185 if(enable_maintainer_mode)
186 add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
188 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
189 add_dependencies(simgrid automaton_generated_src)