Skip to content

Commit 0516b98

Browse files
jcfrjamesobutler
authored andcommitted
cmake: Set include directories as target compile property
This changes the include directories from global include_directories to target-specific target_include_directories. This improves the encapsulation and modularity of the build.
1 parent 84e5b86 commit 0516b98

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ foreach(qtlib ${qt_required_components})
152152
list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES})
153153
endforeach()
154154

155-
# Required for use of "QtCore/private/qmetaobjectbuilder_p.h" in "PythonQt.cpp"
156-
include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS})
157-
158155
macro(pythonqt_wrap_cpp)
159156
qt5_wrap_cpp(${ARGV})
160157
endmacro()
@@ -306,10 +303,6 @@ pythonqt_wrap_cpp(gen_moc_sources ${moc_sources})
306303
#-----------------------------------------------------------------------------
307304
# Build the library
308305

309-
include_directories(
310-
${CMAKE_CURRENT_SOURCE_DIR}/src
311-
)
312-
313306
add_library(PythonQt SHARED
314307
${sources}
315308
${gen_moc_sources}
@@ -327,6 +320,15 @@ target_compile_options(PythonQt PRIVATE
327320
$<$<CXX_COMPILER_ID:MSVC>:/bigobj>
328321
)
329322

323+
target_include_directories(PythonQt
324+
PUBLIC
325+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
326+
$<INSTALL_INTERFACE:${PythonQt_INSTALL_INCLUDE_DIR}>
327+
PRIVATE
328+
# Required for use of "QtCore/private/qmetaobjectbuilder_p.h" in "PythonQt.cpp"
329+
${Qt5Core_PRIVATE_INCLUDE_DIRS}
330+
)
331+
330332
target_link_libraries(PythonQt
331333
${PYTHON_LIBRARY}
332334
${QT_LIBRARIES}
@@ -364,8 +366,6 @@ if(BUILD_TESTING)
364366
)
365367

366368
if(PythonQt_Wrap_Qtcore)
367-
include_directories(generated_cpp${generated_cpp_suffix})
368-
369369
list(APPEND test_sources
370370
tests/PythonQtTestCleanup.cpp
371371
tests/PythonQtTestCleanup.h
@@ -378,6 +378,12 @@ if(BUILD_TESTING)
378378
endif()
379379

380380
add_executable(PythonQtCppTests ${test_sources})
381+
382+
target_include_directories(PythonQtCppTests
383+
PRIVATE
384+
$<$<BOOL:${PythonQt_Wrap_Qtcore}>:${CMAKE_CURRENT_SOURCE_DIR}/generated_cpp${generated_cpp_suffix}>
385+
)
386+
381387
target_link_libraries(PythonQtCppTests PythonQt)
382388

383389
target_compile_definitions(PythonQtCppTests

0 commit comments

Comments
 (0)