[cmake-developers] check_cxx_source_compiles and include directories
Roman Wüger
roman.wueger at gmx.at
Mon Jul 27 15:26:18 EDT 2015
So, here is the piece of code which works
Main CMakeLists.txt:
project(MyProject)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
if (APPLE)
set(CMAKE_CXX_EXTENSIONS OFF) # Use -std=c++11 instead of -std=gnu++11
endif()
set(CMAKE_CXX_STANDARD 11)
include(CheckCXXCompilerFlag)
# Required for check_cxx_source_cmopiles
check_cxx_compiler_flag("-std=c++11" CXX11_FLAG)
if (CXX11_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
include(CheckMyCXX11Features.cmake)
.
.
.
add_subdirectory(SubProj1)
add_subdirectory(SubProj2)
.
.
.
CheckMyCXX11Features.cmake:
include(CheckCXXSourceCompiles)
# C++11 Unique Lock and Mutex
set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}")
check_cxx_source_compiles(
"#include <mutex> // std::mutex, std::unique_lock
std::mutex mtx; // mutex for critical section
void print_block (int n, char c) {
// critical section (exclusive access to std::cout signaled by
lifetime of lck):
std::unique_lock<std::mutex> lck (mtx);
for (int i=0; i<n; ++i) { /* Do Something */ }
}
int main ()
{
print_block(50,'$');
return 0;
}"
MY_HAVE_CXX11_MUTEX_AND_UNIQUE_LOCK
)
set(CMAKE_REQUIRED_FLAGS "")
configure_file(${CMAKE_SOURCE_DIR}/cmake/MyCXX11Features.h.in
${CMAKE_BINARY_DIR}/cmake/MyCXX11Features.h)
SubProj1 and SubProj2 does not find <mutex>, but check_cxx_source_compiles
succeeds.
Did I miss configure something here?
Best Regards
Roman
> -----Ursprüngliche Nachricht-----
> Von: cmake-developers [mailto:cmake-developers-bounces at cmake.org] Im
> Auftrag von Roman Wüger
> Gesendet: Montag, 27. Juli 2015 07:35
> An: CMake MailingList <cmake at cmake.org>; CMake Developer MailingList
> <cmake-developers at cmake.org>
> Betreff: [cmake-developers] check_cxx_source_compiles and include
> directories
>
> Hello,
>
> I've a small code example to test if the <mutex> header file exists (with
> check_cxx_source_compiles), which sets my variable successfully to TRUE.
>
> When I compile the real code then I got an error message saying 'mutex'
file
> not found.
>
> I checked the compile flags for both situations and these are equal. So I
> thought that the include directories could be the problem.
>
> Any hints?
>
> Best Regards
> Roman
> --
>
> Powered by <http://www.kitware.com> www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> <http://www.cmake.org/Wiki/CMake_FAQ> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: <http://cmake.org/cmake/help/support.html>
http://cmake.org/cmake/help/support.html
> CMake Consulting: <http://cmake.org/cmake/help/consulting.html>
http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: <http://cmake.org/cmake/help/training.html>
http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> <http://www.kitware.com/opensource/opensource.html>
http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> <http://public.kitware.com/mailman/listinfo/cmake-developers>
http://public.kitware.com/mailman/listinfo/cmake-developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20150727/eaacd01c/attachment-0001.html>
More information about the cmake-developers
mailing list