Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/mwapl/simgrid
[simgrid.git] / examples / sthread / CMakeLists.txt
1 set(THREADS_PREFER_PTHREAD_FLAG ON)
2 find_package(Threads REQUIRED)
3
4 # Regular pthread examples: test the interceptor of the pthread interface
5 #########################################################################
6
7 foreach(x
8         mutex-simple
9         producer-consumer)
10
11   if("${CMAKE_SYSTEM}" MATCHES "Linux")
12     add_executable       (pthread-${x} EXCLUDE_FROM_ALL pthread-${x}.c)
13     set_target_properties(pthread-${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
14     target_link_libraries(pthread-${x} PRIVATE Threads::Threads)
15     if(SIMGRID_HAVE_STATEFUL_MC) # Only needed to introspect the binary
16       target_link_libraries(pthread-${x} PUBLIC "-Wl,-znorelro -Wl,-znoseparate-code") # TODO: convert to target_link_option once CMAKE_VERSION is >3.13
17     endif()
18
19     add_dependencies(tests pthread-${x})
20     ADD_TESH_FACTORIES(pthread-${x} "^thread" --setenv libdir=${CMAKE_BINARY_DIR}/lib --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
21
22     if(SIMGRID_HAVE_MC)
23       add_dependencies(tests-mc pthread-${x})
24       ADD_TESH_FACTORIES(pthread-mc-${x} "^thread" --setenv libdir=${CMAKE_BINARY_DIR}/lib --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/pthread-mc-${x}.tesh)
25     endif()
26   endif()
27
28   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh
29                                      ${CMAKE_CURRENT_SOURCE_DIR}/pthread-mc-${x}.tesh)
30   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c)
31
32 endforeach()
33
34 # Regular pthread examples that may deadlock: test sthread + MC in that case
35 ############################################################################
36
37 foreach(x
38         mutex-simpledeadlock)
39
40   if("${CMAKE_SYSTEM}" MATCHES "Linux") # sthread is linux-only
41
42     add_executable       (pthread-${x} EXCLUDE_FROM_ALL pthread-${x}.c)
43     set_target_properties(pthread-${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
44     target_link_libraries(pthread-${x} PRIVATE Threads::Threads)
45     if(SIMGRID_HAVE_STATEFUL_MC) # Only needed to introspect the binary
46       target_link_libraries(pthread-${x} PUBLIC "-Wl,-znorelro -Wl,-znoseparate-code") # TODO: convert to target_link_option once CMAKE_VERSION is >3.13
47     endif()
48
49     if(SIMGRID_HAVE_MC)
50       add_dependencies(tests-mc pthread-${x})
51       ADD_TESH_FACTORIES(pthread-mc-${x} "^thread" --setenv libdir=${CMAKE_BINARY_DIR}/lib --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/pthread-mc-${x}.tesh)
52     endif()
53   endif()
54
55   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/pthread-mc-${x}.tesh)
56   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c)
57
58 endforeach()
59
60 # C++ tests with sthread+MC that live in their own directory
61 ########################################################
62 foreach(example
63         stdobject)
64
65   if("${CMAKE_SYSTEM}" MATCHES "Linux") # sthread is linux-only
66
67     add_executable       (${example} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.cpp)
68     set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
69     target_link_libraries(${example} PRIVATE Threads::Threads)
70     if(SIMGRID_HAVE_STATEFUL_MC) # Only needed to introspect the binary
71       target_link_libraries(${example} PUBLIC "-fPIC -Wl,-znorelro -Wl,-znoseparate-code") # TODO: convert to target_link_option once CMAKE_VERSION is >3.13
72     endif()
73     set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
74
75     if(SIMGRID_HAVE_MC)
76       add_dependencies(tests-mc ${example})
77       ADD_TESH_FACTORIES(sthread-mc-${example} "^thread" --setenv libdir=${CMAKE_BINARY_DIR}/lib --cd ${CMAKE_BINARY_DIR}/examples/sthread/${example} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
78     endif()
79   endif()
80
81   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
82   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.cpp)
83 endforeach()
84
85 # Regular sthread examples: test the internal interface for debugging purpose
86 #############################################################################
87
88 foreach(x
89         mutex-simple)
90   if("${CMAKE_SYSTEM}" MATCHES "Linux")
91     add_executable       (sthread-${x} EXCLUDE_FROM_ALL sthread-${x}.c)
92     set_target_properties(sthread-${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
93     target_link_libraries(sthread-${x} sthread)
94     set_property(TARGET sthread-${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
95
96     add_dependencies(tests sthread-${x})
97     ADD_TESH_FACTORIES(sthread-${x} "^thread" --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
98   endif()
99
100   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
101   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.c)
102 endforeach()
103
104
105 # Add all extra files to the archive
106 ####################################
107
108 set(tesh_files    ${tesh_files}     PARENT_SCOPE)
109 set(bin_files     ${bin_files}      PARENT_SCOPE)
110 set(examples_src  ${examples_src}   PARENT_SCOPE)
111 set(xml_files     ${xml_files}      PARENT_SCOPE)
112
113