Closed sakirma closed 3 years ago
This is the CMAKE if it is needed
# cmake_minimum_required(VERSION 2.6) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CURRENT_BINARY_DIR ./build) set(CMAKE_CURRENT_SOURCE_DIR ./) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(SDL2_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../SDL) set(BOX2D_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../box2d)
project(SDL2Test)
add_subdirectory(${SDL2_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/sdl) add_subdirectory(${BOX2D_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/box2d)
add_executable(SDL2Test Main.cpp)
find_package(box2d REQUIRED)
target_include_directories(SDL2Test PUBLIC ${SDL2_SOURCE_DIR}/include ${BOX2D_SOURCE_DIR}/include/box2d)
target_link_libraries(SDL2Test PRIVATE SDL2 box2d) #
I have box2D as a SubModule in my git repository
I've never seen box2d::box2d
syntax before. Is it a new cmake feature? Might just be a copy-paste typo.
It is on the Readme page. It doesn't work for me at least and I have the latest CMake version.
I know, I saw it there. I meant I haven't seen it anywhere else.
Ah sorry, but are you able to remake this problem? With the latest CMake
Actually, I think the box2d::box2d example was correct if you use the box2dConfig.cmake script to find box2d.
CMakeLists.txt in src:
...
install(
TARGETS box2d
EXPORT box2dConfig
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
EXPORT box2dConfig
NAMESPACE box2d::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/box2d"
)
...
Due to the namespace it will hide the library behind it. Corresponding box2dConfig.cmake script from the install target:
...
# Create imported target box2d::box2d
add_library(box2d::box2d STATIC IMPORTED)
...
Using this i had to use:
target_link_libraries(mytarget box2d::box2d)
Otherwise it did not find any header and can not find the box2d.lib
Make sure these boxes are checked before submitting your issue - thank you!
The example says to use:
target_link_libraries(mytarget PRIVATE box2d::box2d)
But this caused a problem when I ran the
make
command in the console: which showed the following problem:And after changing the
target_link_libraries
to:target_link_libraries(mytarget PRIVATE box2d)
It worked again