Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename SIMGRID_HAVE_MC into SIMGRID_HAVE_STATEFUL_MC (so that MC can be optional...
[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     add_dependencies(tests-mc pthread-${x})
23     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)
24   endif()
25
26   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh
27                                      ${CMAKE_CURRENT_SOURCE_DIR}/pthread-mc-${x}.tesh)
28   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c)
29
30 endforeach()
31
32 # Regular pthread examples that may deadlock: test sthread + MC in that case
33 ############################################################################
34
35 foreach(x
36         mutex-simpledeadlock)
37
38   if("${CMAKE_SYSTEM}" MATCHES "Linux") # sthread is linux-only
39
40     add_executable       (pthread-${x} EXCLUDE_FROM_ALL pthread-${x}.c)
41     set_target_properties(pthread-${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
42     target_link_libraries(pthread-${x} PRIVATE Threads::Threads)
43     if(SIMGRID_HAVE_STATEFUL_MC) # Only needed to introspect the binary
44       target_link_libraries(pthread-${x} PUBLIC "-Wl,-znorelro -Wl,-znoseparate-code") # TODO: convert to target_link_option once CMAKE_VERSION is >3.13
45     endif()
46
47     add_dependencies(tests-mc pthread-${x})
48     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)
49   endif()
50
51   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/pthread-mc-${x}.tesh)
52   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c)
53
54 endforeach()
55
56 # C++ tests with sthread+MC that live in their own directory
57 ########################################################
58 foreach(example
59         stdobject)
60
61   if("${CMAKE_SYSTEM}" MATCHES "Linux") # sthread is linux-only
62
63     add_executable       (${example} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.cpp)
64     set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
65     target_link_libraries(${example} PRIVATE Threads::Threads)
66     if(SIMGRID_HAVE_STATEFUL_MC) # Only needed to introspect the binary
67       target_link_libraries(${example} PUBLIC "-fPIC -Wl,-znorelro -Wl,-znoseparate-code") # TODO: convert to target_link_option once CMAKE_VERSION is >3.13
68     endif()
69     set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
70
71     add_dependencies(tests-mc ${example})
72     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)
73   endif()
74
75   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
76   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.cpp)
77 endforeach()
78
79 # Regular sthread examples: test the internal interface for debugging purpose
80 #############################################################################
81
82 foreach(x
83         mutex-simple)
84   if("${CMAKE_SYSTEM}" MATCHES "Linux")
85     add_executable       (sthread-${x} EXCLUDE_FROM_ALL sthread-${x}.c)
86     set_target_properties(sthread-${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
87     target_link_libraries(sthread-${x} sthread)
88     set_property(TARGET sthread-${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
89
90     add_dependencies(tests sthread-${x})
91     ADD_TESH_FACTORIES(sthread-${x} "^thread" --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
92   endif()
93
94   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
95   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.c)
96 endforeach()
97
98
99 # Add all extra files to the archive
100 ####################################
101
102 set(tesh_files    ${tesh_files}     PARENT_SCOPE)
103 set(bin_files     ${bin_files}      PARENT_SCOPE)
104 set(examples_src  ${examples_src}   PARENT_SCOPE)
105 set(xml_files     ${xml_files}      PARENT_SCOPE)
106
107