Commit 6dcb26d21ed116016f0f3ee7630f532a70a66b79
1 parent
198b9647
Fix test for whether atomic library is needed
Some platforms need it for atomic<long long> but not for atomic<int>.
Showing
2 changed files
with
13 additions
and
3 deletions
CMakeLists.txt
| ... | ... | @@ -154,6 +154,7 @@ if(WIN32 AND NOT SKIP_OS_SECURE_RANDOM) |
| 154 | 154 | endif() |
| 155 | 155 | |
| 156 | 156 | include(CheckCXXSourceCompiles) |
| 157 | +set(ATOMIC_LIBRARY) | |
| 157 | 158 | function(check_atomic) |
| 158 | 159 | foreach(I 0 1) |
| 159 | 160 | if(I) |
| ... | ... | @@ -162,8 +163,8 @@ function(check_atomic) |
| 162 | 163 | check_cxx_source_compiles( |
| 163 | 164 | "#include <atomic> |
| 164 | 165 | int main() { |
| 165 | - static std::atomic<int> a{0}; | |
| 166 | - a = a.fetch_add(1); | |
| 166 | + static std::atomic<unsigned long long> a{0}; | |
| 167 | + a = a.fetch_add(1LL); | |
| 167 | 168 | return 0; |
| 168 | 169 | }" |
| 169 | 170 | ATOMIC_WORKED${I}) |
| ... | ... | @@ -172,7 +173,7 @@ int main() { |
| 172 | 173 | endif() |
| 173 | 174 | endforeach() |
| 174 | 175 | if(ATOMIC_WORKED1) |
| 175 | - list(APPEND CMAKE_REQUIRED_LIBRARIES atomic) | |
| 176 | + set(ATOMIC_WORKED1 atomic PARENT_SCOPE) | |
| 176 | 177 | endif() |
| 177 | 178 | endfunction() |
| 178 | 179 | check_atomic() | ... | ... |
libqpdf/CMakeLists.txt
| ... | ... | @@ -410,6 +410,9 @@ target_include_directories(${OBJECT_LIB} |
| 410 | 410 | ${CMAKE_CURRENT_BINARY_DIR}) |
| 411 | 411 | target_link_directories(${OBJECT_LIB} INTERFACE ${dep_link_directories}) |
| 412 | 412 | target_link_libraries(${OBJECT_LIB} INTERFACE ${dep_link_libraries}) |
| 413 | +if(ATOMIC_LIBRARY) | |
| 414 | + target_link_libraries(${OBJECT_LIB} INTERFACE ${ATOMIC_LIBRARY}) | |
| 415 | +endif() | |
| 413 | 416 | |
| 414 | 417 | set(LD_VERSION_FLAGS "") |
| 415 | 418 | function(ld_version_script) |
| ... | ... | @@ -490,6 +493,9 @@ if(BUILD_SHARED_LIBS) |
| 490 | 493 | $<INSTALL_INTERFACE:include>) |
| 491 | 494 | target_link_directories(${SHARED_LIB} PRIVATE ${dep_link_directories}) |
| 492 | 495 | target_link_libraries(${SHARED_LIB} PRIVATE ${dep_link_libraries}) |
| 496 | + if(ATOMIC_LIBRARY) | |
| 497 | + target_link_libraries(${SHARED_LIB} PRIVATE ${ATOMIC_LIBRARY}) | |
| 498 | + endif() | |
| 493 | 499 | if(LD_VERSION_FLAGS) |
| 494 | 500 | target_link_options(${SHARED_LIB} PRIVATE ${LD_VERSION_FLAGS}) |
| 495 | 501 | endif() |
| ... | ... | @@ -527,6 +533,9 @@ if(BUILD_STATIC_LIBS) |
| 527 | 533 | INTERFACE $<BUILD_INTERFACE:${dep_link_directories}> |
| 528 | 534 | PRIVATE $<INSTALL_INTERFACE:${dep_link_directories}>) |
| 529 | 535 | target_link_libraries(${STATIC_LIB} INTERFACE ${dep_link_libraries}) |
| 536 | + if(ATOMIC_LIBRARY) | |
| 537 | + target_link_libraries(${STATIC_LIB} INTERFACE ${ATOMIC_LIBRARY}) | |
| 538 | + endif() | |
| 530 | 539 | |
| 531 | 540 | # Avoid name clashes on Windows with the the DLL import library. |
| 532 | 541 | if(NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS) | ... | ... |