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)
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
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_FULL_LIBDIR}")
16 ###############################
17 # Declare the library content #
18 ###############################
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}")
27 add_dependencies(simgrid maintainer_files)
29 if("${CMAKE_SYSTEM}" MATCHES "Linux")
30 add_library(sthread SHARED ${STHREAD_SRC})
31 set_property(TARGET sthread
32 APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
33 install(TARGETS sthread # install that binary without breaking the rpath on Mac
34 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/)
35 target_link_libraries(sthread simgrid)
37 set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC})
40 if(enable_model-checking)
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)
55 # Compute the dependencies of SimGrid
56 #####################################
58 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
59 find_library(DL_LIBRARY dl)
61 mark_as_advanced(DL_LIBRARY)
63 if (HAVE_BOOST_CONTEXTS)
64 target_link_libraries(simgrid ${Boost_CONTEXT_LIBRARY})
67 if (HAVE_BOOST_STACKTRACE_BACKTRACE)
68 target_link_libraries(simgrid ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
71 if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
72 target_link_libraries(simgrid ${Boost_STACKTRACE_ADDR2LINE_LIBRARY})
75 if(CMAKE_USE_PTHREADS_INIT)
76 target_link_libraries(simgrid ${CMAKE_THREAD_LIBS_INIT})
80 SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
85 SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
88 SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
93 if(NOT ${DL_LIBRARY} STREQUAL "")
94 SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
97 if(HAVE_POSIX_GETTIME)
98 SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
101 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
102 set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
105 # Compute the dependencies of SMPI
106 ##################################
109 add_executable(smpimain src/smpi/smpi_main.c)
110 target_link_libraries(smpimain simgrid)
111 set_target_properties(smpimain
112 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
113 install(TARGETS smpimain # install that binary without breaking the rpath on Mac
114 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
115 add_dependencies(tests smpimain)
117 add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
118 target_compile_options(smpireplaymain PRIVATE -fpic)
119 target_link_libraries(smpireplaymain simgrid -fpic -shared)
120 set_target_properties(smpireplaymain
121 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
122 install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
123 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
124 add_dependencies(tests smpireplaymain)
127 if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
128 SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
129 elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
130 SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
131 elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
132 SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
133 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
134 set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
135 if ("${CMAKE_SYSTEM_VERSION}" STRGREATER_EQUAL "12")
136 set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
138 if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12\.1")
139 set(SIMGRID_DEP "${SIMGRID_DEP} -lomp")
147 if(enable_smpi AND APPLE)
148 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
151 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
152 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
154 $ENV{HOME}/local/lib64
166 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
167 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
168 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,--as-needed -latomic -Wl,--no-as-needed")
170 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
172 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
173 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-znorelro -Wl,-znoseparate-code")
176 target_link_libraries(simgrid ${SIMGRID_DEP})
178 # Dependencies from maintainer mode
179 ###################################
180 if(enable_maintainer_mode)
181 add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
183 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
184 add_dependencies(simgrid automaton_generated_src)