stephen kelly c++ user group, berlin july 2014 · the what, why and how of modern cmake stephen...
TRANSCRIPT
![Page 1: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/1.jpg)
The What, Why and How of Modern CMake
Stephen Kelly
C++ User Group, Berlin
July 2014
![Page 2: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/2.jpg)
Who and When
● Using CMake since KDE 4.0 (December 2007)
![Page 3: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/3.jpg)
Who and When
● Using CMake since KDE 4.0 (December 2007)● Contributor since CMake 2.8.7 (Nov 2011)
![Page 4: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/4.jpg)
Who and When
● Using CMake since KDE 4.0 (December 2007)● Contributor since CMake 2.8.7 (Nov 2011)● Feature complete in CMake 3.0 (June 2014)
![Page 5: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/5.jpg)
Who and When
● Using CMake since KDE 4.0 (December 2007)● Contributor since CMake 2.8.7 (Nov 2011)● (Almost) Feature complete in CMake 3.0 (June 2014)
![Page 6: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/6.jpg)
Buildsystem Developers
![Page 7: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/7.jpg)
Buildsystem Developers
![Page 8: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/8.jpg)
Buildsystem Developers
![Page 9: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/9.jpg)
Buildsystem Developers
![Page 10: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/10.jpg)
Buildsystem Developers
![Page 11: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/11.jpg)
Buildsystem Developers
![Page 12: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/12.jpg)
Buildsystem Developers
![Page 13: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/13.jpg)
Buildsystem Developers
![Page 14: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/14.jpg)
Buildsystem Developers
![Page 15: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/15.jpg)
Buildsystem Developers
![Page 16: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/16.jpg)
Buildsystem Developers
![Page 17: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/17.jpg)
Buildsystem Developers
![Page 18: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/18.jpg)
Buildsystem Developers
include_directories("/opt/foo/bar") compile_definitions(-DUSING_BAR=1)
![Page 19: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/19.jpg)
Buildsystem Developers
![Page 20: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/20.jpg)
What is Modern CMake?
![Page 21: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/21.jpg)
What is Modern CMake?
● Describes a useful model of buildsystem● Has design/direction ● Straightforward, clean syntax
![Page 22: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/22.jpg)
What is Modern CMake?
● Describes a useful model of buildsystem● Has design/direction ● Straightforward, clean syntax● High usability, maximum speed● High level of abstraction● Declarative
![Page 23: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/23.jpg)
What is Modern CMake?
add_library(foo foo.cpp)
add_executable(myexe main.cpp)target_link_libraries(myexe foo)
![Page 24: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/24.jpg)
What is Modern CMake?
add_library(foo foo.cpp)target_compile_definitions(foo PRIVATE -DBUILDING_FOO=1)target_include_directories(foo PRIVATE "${srcDir}/bar")
![Page 25: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/25.jpg)
What is Modern CMake?
add_library(foo foo.cpp)target_compile_definitions(foo INTERFACE -DUSING_FOO=1)target_include_directories(foo INTERFACE "/opt/foo/bar")
![Page 26: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/26.jpg)
What is Modern CMake?
add_library(foo foo.cpp)target_compile_definitions(foo INTERFACE -DUSING_FOO=1)target_include_directories(foo INTERFACE "/opt/foo/bar")
add_executable(myexe main.cpp)target_link_libraries(myexe foo)
![Page 27: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/27.jpg)
What is Modern CMake?
Describe target properties
![Page 28: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/28.jpg)
What is Modern CMake?
Describe target dependencies
![Page 29: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/29.jpg)
What is Modern CMake?
Transitive usage requirements
![Page 30: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/30.jpg)
What is Modern CMake?
Exporting for downstream use
![Page 31: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/31.jpg)
What is Modern CMake?
install(EXPORT fooTargets NAMESPACE Bar:: DESTINATION lib/cmake)
![Page 32: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/32.jpg)
What is Modern CMake?
install(EXPORT fooTargets NAMESPACE Bar:: DESTINATION lib/cmake)
# Generates:
add_library(Bar::foo IMPORTED)set_target_properties(Bar::foo INTERFACE_COMPILE_DEFINITIONS USING_FOO=1)
![Page 33: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/33.jpg)
What is Modern CMake?
find_package(Foo REQUIRED)
add_executable(myexe main.cpp)target_link_libraries(myexe Bar::foo)
![Page 34: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/34.jpg)
What is Modern CMake?
Upstream provides 'CMake config packages'
No more FindFoo.cmake!
![Page 35: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/35.jpg)
![Page 36: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/36.jpg)
Why is this better?
# Directory-scoped. Bad!include_directories(${Foo_INCLUDES})
add_executable(myexe1 main1.cpp)target_link_libraries(myexe1 foo)
# Uses the includes too!add_executable(myexe2 main2.cpp)
![Page 37: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/37.jpg)
How?
Less code!
target_link_libraries()
expresses target dependencies, consumes requirements
![Page 38: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/38.jpg)
How?
target_include_directories() target_compile_definitions() target_compile_options() target_compile_features() target_sources() target_link_options() (pending) target_archive_options() (pending)
express usage requirements
![Page 39: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/39.jpg)
How?
target_compile_definitions(tgt PRIVATE I_USE_THIS )
target_compile_definitions(tgt INTERFACE YOU_USE_THIS )
target_compile_definitions(tgt PUBLIC WE_BOTH_USE_THIS )
![Page 40: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/40.jpg)
Compiler requirements
C++11
![Page 41: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/41.jpg)
Compiler requirements
C++11
C++14
![Page 42: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/42.jpg)
Compiler requirements
C++11
C++14
C++98
![Page 43: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/43.jpg)
Compiler requirements
C++11?
C++14?
C++98?
![Page 44: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/44.jpg)
Compiler requirements
add_library(foo SHARED foo.cpp)target_compile_features(foo INTERFACE cxx_variadic_templates)
...
add_executable(myexe main.cpp)target_link_libraries(myexe Bar::foo)
![Page 45: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/45.jpg)
Compiler requirements
add_library(foo SHARED foo.cpp)target_compile_features(foo INTERFACE cxx_variadic_templates cxx_decltype_auto)...
add_executable(myexe main.cpp)target_link_libraries(myexe Bar::foo)
![Page 46: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/46.jpg)
Compiler requirements
add_library(foo SHARED foo.cpp)target_compile_features(foo INTERFACE cxx_template_template_parameters)
...
add_executable(myexe main.cpp)target_link_libraries(myexe Bar::foo)
![Page 47: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/47.jpg)
Compiler requirements
add_library(foo SHARED foo.c)target_compile_features(foo INTERFACE c_restrict c_static_assert)
...
add_executable(myexe main.c)target_link_libraries(myexe Bar::foo)
![Page 48: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/48.jpg)
The QTestLib problem
add_executable(guitest guitest.cpp)target_link_libraries(guitest Qt5::Test Qt5::Gui)
add_executable(coretest coretest.cpp)target_link_libraries(coretest Qt5::Test Qt5::Core)
![Page 49: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/49.jpg)
The QTestLib problem
#if defined(QT_CORE_LIB) QCoreApplication#elif defined(QT_GUI_LIB) QGuiApplication#elif defined(QT_WIDGET_LIB) QApplication#endif
![Page 50: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/50.jpg)
Typo diagnostics
find_package(Qt5Widgets REQUIRED)
add_executable(typotest typotest.cpp)target_link_libraries(typotest Qt5::Wydjits)
![Page 51: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/51.jpg)
Typo diagnostics
# find_package(Qt5Widgets REQUIRED)
add_executable(typotest typotest.cpp)target_link_libraries(typotest Qt5::Widgets)
![Page 52: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/52.jpg)
Declarative
add_library(foo foo.cpp)target_include_directories(foo INTERFACE $<BUILD_INTERFACE:${srcDir}/bar> $<INSTALL_INTERFACE:${installDir}/bar>)
![Page 53: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/53.jpg)
Declarative
add_library(foo foo.cpp)target_compile_definitions(foo INTERFACE $<$<CONFIG:Debug>:DEBUG_MODE>)
![Page 54: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/54.jpg)
Interface compatibility
add_library(foo foo.cpp)set_target_property(foo INTERFACE_CUSTOM_STRING MULTI_THREADED)
add_library(bar bar.cpp)set_target_property(bar INTERFACE_CUSTOM_STRING NOT_MULTI_THREADED)
![Page 55: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/55.jpg)
Interface-only libraries
add_library(boost::range INTERFACE IMPORTED)
![Page 56: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/56.jpg)
Interface-only libraries
add_library(boost::range INTERFACE IMPORTED)set_target_properties(boost::range INTERFACE_INCLUDE_DIRECTORIES "/opt/boost_range/include")
![Page 57: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/57.jpg)
Interface-only libraries
add_executable(myexe main.cpp)target_link_libraries(myexe boost::range boost::any boost::units)
![Page 58: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/58.jpg)
Header-library challenges
● Find headers● Use include directories● Use correct macros (BOOST_ALL_NO_LIB etc)
![Page 59: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/59.jpg)
Header-library challenges
● Find headers● Use include directories● Use correct macros (BOOST_ALL_NO_LIB etc)● Use correct compile flags (eg, non-broken preprocessor with Clang on Windows)● Compatibility between components● Diagnostics
![Page 60: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/60.jpg)
Interface sources
add_library(lib_with_global_obj lib.cpp)target_sources(lib_with_global_obj INTERFACE symbol_user.cpp)
![Page 61: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/61.jpg)
Interface sources
set(isExe "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>")add_library(lib_with_global_obj lib.cpp)target_sources(lib_with_global_obj INTERFACE "$<${isExe}:symbol_user.cpp>")
![Page 62: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/62.jpg)
Interface sources
set(isExe "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>")add_library(lib_with_global_obj lib.cpp)target_sources(lib_with_global_obj INTERFACE "$<${isExe}:symbol_user.cpp>")
add_library(intermediate other.cpp)target_link_libraries(intermediate PUBLIC lib_with_global_obj)
![Page 63: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/63.jpg)
Interface sources
set(isExe "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>")add_library(lib_with_global_obj lib.cpp)target_sources(lib_with_global_obj INTERFACE "$<${isExe}:symbol_user.cpp>")
add_library(intermediate other.cpp)target_link_libraries(intermediate PUBLIC lib_with_global_obj)
...
add_executable(myexe intermediate)
![Page 64: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/64.jpg)
Batteries included
![Page 65: Stephen Kelly C++ User Group, Berlin July 2014 · The What, Why and How of Modern CMake Stephen Kelly C++ User Group, Berlin July 2014](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9aecee7383597cbf4dc004/html5/thumbnails/65.jpg)
Questions
And Answers...
steveire.wordpress.comhttp://www.cmake.org/cmake/help/v3.0/