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(enable_model-checking)
30 add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
31 target_link_libraries(simgrid-mc simgrid)
32 set_target_properties(simgrid-mc
33 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
34 set_property(TARGET simgrid-mc
35 APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
36 install(TARGETS simgrid-mc # install that binary without breaking the rpath on Mac
37 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/)
38 add_dependencies(tests-mc simgrid-mc)
42 # Compute the dependencies of SimGrid
43 #####################################
45 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
46 find_library(DL_LIBRARY dl)
48 mark_as_advanced(DL_LIBRARY)
50 if (HAVE_BOOST_CONTEXTS)
51 target_link_libraries(simgrid ${Boost_CONTEXT_LIBRARY})
54 if (HAVE_BOOST_STACKTRACE_BACKTRACE)
55 target_link_libraries(simgrid ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
58 if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
59 target_link_libraries(simgrid ${Boost_STACKTRACE_ADDR2LINE_LIBRARY})
62 if(CMAKE_USE_PTHREADS_INIT)
63 target_link_libraries(simgrid ${CMAKE_THREAD_LIBS_INIT})
67 SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
72 SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
75 SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
80 if(NOT ${DL_LIBRARY} STREQUAL "")
81 SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
84 if(HAVE_POSIX_GETTIME)
85 SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
88 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
89 set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
92 # Compute the dependencies of SMPI
93 ##################################
96 add_executable(smpimain src/smpi/smpi_main.c)
97 target_link_libraries(smpimain simgrid)
98 set_target_properties(smpimain
99 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
100 install(TARGETS smpimain # install that binary without breaking the rpath on Mac
101 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
102 add_dependencies(tests smpimain)
104 add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
105 target_compile_options(smpireplaymain PRIVATE -fpic)
106 target_link_libraries(smpireplaymain simgrid -fpic -shared)
107 set_target_properties(smpireplaymain
108 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
109 install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
110 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
111 add_dependencies(tests smpireplaymain)
114 if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
115 SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
116 elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
117 SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
118 elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
119 SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
120 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
121 set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
122 if ("${CMAKE_SYSTEM_VERSION}" STRGREATER_EQUAL "12")
123 set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
125 if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12\.1")
126 set(SIMGRID_DEP "${SIMGRID_DEP} -lomp")
134 if(enable_smpi AND APPLE)
135 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
138 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
139 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
141 $ENV{HOME}/local/lib64
153 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
154 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
155 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,--as-needed -latomic -Wl,--no-as-needed")
157 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
159 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
160 set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-znorelro -Wl,-znoseparate-code")
163 target_link_libraries(simgrid ${SIMGRID_DEP})
165 # Dependencies from maintainer mode
166 ###################################
167 if(enable_maintainer_mode)
168 add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
170 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
171 add_dependencies(simgrid automaton_generated_src)