diff --git a/CMakeLists.txt b/CMakeLists.txt index d340d5c8ab..e9f526f0e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,14 +320,12 @@ else() endif() endif() find_package(ZLIB REQUIRED) -include_directories(${ZLIB_INCLUDE_DIRS}) set(USE_SYSTEM_SDL2 OFF CACHE BOOL "Set to ON to use the system SDL2 headers.") if(BUILD_LIBRARY) if(USE_SYSTEM_SDL2) find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2) - include_directories(${SDL2_INCLUDE_DIRS}) else() # Download SDL release and extract into depends in the build dir # all we need are the header files (including generated headers), so the same release package @@ -342,7 +340,7 @@ if(BUILD_LIBRARY) ${SDL_ZIP_MD5}) file(ARCHIVE_EXTRACT INPUT ${SDL_ZIP_PATH}${SDL_ZIP_FILE} DESTINATION ${SDL_ZIP_PATH}) - include_directories(${SDL_ZIP_PATH}/SDL2-${SDL_VERSION}/include) + set(SDL2_INCLUDE_DIRS ${SDL_ZIP_PATH}/SDL2-${SDL_VERSION}/include) endif() endif() @@ -404,10 +402,6 @@ endif() #### expose depends #### -include_directories(depends/protobuf) -include_directories(depends/lua/include) -include_directories(depends/md5) - # Support linking against external tinyxml # If we find an external tinyxml, set the DFHACK_TINYXML variable to "tinyxml" # Otherwise, set it to "dfhack-tinyxml" @@ -419,14 +413,9 @@ if(EXTERNAL_TINYXML) endif() set(DFHACK_TINYXML "tinyxml") else() - include_directories(depends/tinyxml) set(DFHACK_TINYXML "dfhack-tinyxml") endif() -include_directories(depends/lodepng) -include_directories(depends/clsocket/src) -include_directories(depends/xlsxio/include) - if(BUILD_LIBRARY) add_subdirectory(depends) endif() diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt index f40ef5d590..41996294c6 100644 --- a/depends/CMakeLists.txt +++ b/depends/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(lodepng) add_subdirectory(lua) add_subdirectory(md5) add_subdirectory(protobuf) +target_include_directories(protobuf-lite INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/protobuf) if(UNIX) set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion") @@ -21,6 +22,7 @@ add_subdirectory(googletest) # Don't build tinyxml if it's being externally linked against. if(NOT TinyXML_FOUND) add_subdirectory(tinyxml) + target_include_directories(dfhack-tinyxml INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tinyxml) endif() option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" OFF) @@ -87,3 +89,5 @@ if(MSVC) target_compile_options(xlsxio_read_STATIC PRIVATE /wd4013 /wd4244) target_compile_options(xlsxio_write_STATIC PRIVATE /wd4013 /wd4244) endif() +target_include_directories(xlsxio_read_STATIC INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/xlsxio/include) +target_include_directories(xlsxio_write_STATIC INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/xlsxio/include) diff --git a/depends/lua/CMakeLists.txt b/depends/lua/CMakeLists.txt index 116c7a22af..44b16e56cc 100644 --- a/depends/lua/CMakeLists.txt +++ b/depends/lua/CMakeLists.txt @@ -95,6 +95,7 @@ list(APPEND SRC_LIBLUA ${HDR_LIBLUA}) add_library(lua SHARED ${SRC_LIBLUA}) set_target_properties(lua PROPERTIES OUTPUT_NAME lua53) target_link_libraries(lua ${LIBS}) +target_include_directories(lua INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) if(MSVC) # need no space to prevent /FI from being stripped: https://github.com/DFHack/dfhack/issues/1455 diff --git a/depends/md5/CMakeLists.txt b/depends/md5/CMakeLists.txt index 747963c454..55c0bf6c1b 100644 --- a/depends/md5/CMakeLists.txt +++ b/depends/md5/CMakeLists.txt @@ -1,5 +1,6 @@ project(dfhack-md5) add_library(dfhack-md5 STATIC EXCLUDE_FROM_ALL md5.cpp md5wrapper.cpp) +target_include_directories(dfhack-md5 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) ide_folder(dfhack-md5 "Depends") if(UNIX) set_target_properties(dfhack-md5 PROPERTIES COMPILE_FLAGS "-Wno-strict-aliasing") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index c24a4cedbb..6127e83d26 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -39,14 +39,10 @@ endif() add_custom_target(generate_headers DEPENDS ${CODEGEN_OUT}) -include_directories(include) - add_subdirectory(xml) if(BUILD_LIBRARY) -include_directories(proto) - set(MAIN_HEADERS include/Internal.h include/DFHack.h @@ -347,6 +343,7 @@ set_property(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS DFHACK_ABI_VERSION=${DFHACK_ABI_VERSION} DFHACK_RUN_URL="${DFHACK_RUN_URL}" ) +target_include_directories(dfhack-version PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) if(DFHACK_PRERELEASE) set_property(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS DFHACK_PRERELEASE=1 @@ -369,13 +366,19 @@ if(EXISTS ${dfhack_SOURCE_DIR}/.git/index AND EXISTS ${dfhack_SOURCE_DIR}/.git/m endif() add_library(dfhack SHARED ${PROJECT_SOURCES}) +target_include_directories(dfhack PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/proto) + +get_target_property(xlsxio_INCLUDES xlsxio_read_STATIC INTERFACE_INCLUDE_DIRECTORIES) +target_include_directories(dfhack PRIVATE ${xlsxio_INCLUDES} ${SDL2_INCLUDE_DIRS}) add_dependencies(dfhack generate_proto_core) add_dependencies(dfhack generate_headers) add_library(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp Error.cpp ${PROJECT_PROTO_SRCS} ${CONSOLE_SOURCES}) +target_include_directories(dfhack-client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/proto) add_dependencies(dfhack-client dfhack) add_executable(dfhack-run dfhack-run.cpp) +target_include_directories(dfhack-run PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/proto) add_executable(binpatch binpatch.cpp) target_link_libraries(binpatch dfhack-md5) diff --git a/package/CMakeLists.txt b/package/CMakeLists.txt index 2df2f1d8d3..c2da95369d 100644 --- a/package/CMakeLists.txt +++ b/package/CMakeLists.txt @@ -30,13 +30,13 @@ if(BUILD_DFLAUNCH) set(STEAMAPI_SHARED_LIBRARY "${STEAMAPI_LIBRARY}") endif() - include_directories(${STEAMAPI_SOURCE_DIR}) link_libraries(${STEAMAPI_LIBRARY}) if(WIN32) add_executable(launchdf WIN32 launchdf.cpp) else() add_executable(launchdf launchdf.cpp) endif() + target_include_directories(launchdf PRIVATE ${STEAMAPI_SOURCE_DIR}) install(TARGETS launchdf DESTINATION ${DFHACK_DATA_DESTINATION}) install(FILES ${STEAMAPI_SHARED_LIBRARY} DESTINATION ${DFHACK_DATA_DESTINATION}) endif() diff --git a/plugins/Plugins.cmake b/plugins/Plugins.cmake index e058d22812..0b66e8c4c1 100644 --- a/plugins/Plugins.cmake +++ b/plugins/Plugins.cmake @@ -119,22 +119,16 @@ macro(dfhack_plugin) add_library(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) ide_folder(${PLUGIN_NAME} "Plugins") - target_include_directories(${PLUGIN_NAME} PRIVATE "${dfhack_SOURCE_DIR}/library/include") - target_include_directories(${PLUGIN_NAME} PRIVATE "${dfhack_SOURCE_DIR}/library/proto") - target_include_directories(${PLUGIN_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/proto") - target_include_directories(${PLUGIN_NAME} PRIVATE "${dfhack_SOURCE_DIR}/library/depends/xgetopt") - if(NUM_PROTO) add_dependencies(${PLUGIN_NAME} generate_proto_${PLUGIN_NAME}) - target_link_libraries(${PLUGIN_NAME} dfhack protobuf-lite dfhack-version ${PLUGIN_LINK_LIBRARIES}) - else() - target_link_libraries(${PLUGIN_NAME} dfhack dfhack-version ${PLUGIN_LINK_LIBRARIES}) + target_include_directories(${PLUGIN_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/proto") + target_link_libraries(${PLUGIN_NAME} protobuf-lite) endif() + target_link_libraries(${PLUGIN_NAME} dfhack dfhack-version ${PLUGIN_LINK_LIBRARIES}) - add_dependencies(${PLUGIN_NAME} dfhack-version) - - # Make sure the source is generated before the executable builds. - add_dependencies(${PLUGIN_NAME} generate_proto) + # since PluginManager currently uses Lua headers, even when Lua is not used + get_target_property(lua_INCLUDES lua INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(${PLUGIN_NAME} PRIVATE ${lua_INCLUDES}) if(UNIX) set(PLUGIN_COMPILE_FLAGS "${PLUGIN_COMPILE_FLAGS} ${PLUGIN_COMPILE_FLAGS_GCC}") diff --git a/plugins/channel-safely/CMakeLists.txt b/plugins/channel-safely/CMakeLists.txt index 36c7307e45..36b25f4c70 100644 --- a/plugins/channel-safely/CMakeLists.txt +++ b/plugins/channel-safely/CMakeLists.txt @@ -1,6 +1,5 @@ project(channel-safely) -include_directories(include) SET(SOURCES channel-groups.cpp channel-manager.cpp diff --git a/plugins/remotefortressreader/CMakeLists.txt b/plugins/remotefortressreader/CMakeLists.txt index 37aa64b239..caa81707f0 100644 --- a/plugins/remotefortressreader/CMakeLists.txt +++ b/plugins/remotefortressreader/CMakeLists.txt @@ -30,3 +30,6 @@ endif() # this makes sure all the stuff is put in proper places and linked to dfhack dfhack_plugin(RemoteFortressReader ${PROJECT_SRCS} LINK_LIBRARIES ${PROJECT_LIBS} PROTOBUFS ${PROJECT_PROTO}) +if(BUILD_PLUGINS) + target_include_directories(RemoteFortressReader PRIVATE ${SDL2_INCLUDE_DIRS}) +endif()