I want to link the Chipmunk2D physics framework with SDL via CMake.
I have the following project structure:
MyProject
-chipmunk:
--include
--demo:
---CMakeList.txt
--src:
---CMakeList.txt
--CMakeList.txt
-src:
--main.cpp
-CMakeLists.txt
I read about static and shared libraries, and decide I want to use a static library, so I went in the chipmunk folder and I ran cmake .
1.The first CMakeList file sets the options:
message(STATUS "Set BUILD_STATIC option ON")
option(BUILD_SHARED "Build and install the shared library" ON)
option(BUILD_STATIC "Build as static library" ON)
option(INSTALL_STATIC "Install the static library" ON)
and after that:
add_subdirectory(src)
The CMakeList.txt from src enters the action:
if(BUILD_STATIC)
message(STATUS "BUILDING chipmunk_static")
add_library(chipmunk_static STATIC ${chipmunk_source_files})
set_target_properties(chipmunk_static PROPERTIES OUTPUT_NAME chipmunk)
if(INSTALL_STATIC)
message(STATUS "INSTALL chipmunk_static ${LIB_INSTALL_DIR}")
install(TARGETS chipmunk_static ARCHIVE DESTINATION {LIB_INSTALL_DIR})
endif(INSTALL_STATIC)
endif(BUILD_STATIC)
In the demo folder the CmakeFile does the follows:
set(chipmunk_demos_libraries
chipmunk_static
${GLEW_LIBRARIES}
${OPENGL_LIBRARIES}
)
S0 my questions are:
My attempt to find the chipmunk static library without success:
add_subdirectory(chipmunk)
find_package(SDL2 REQUIRED)
find_library(CHIPMUNK_LIB chipmunk_static)
message(${CHIPMUNK_LIB})
So with CMake, when you "find" a library it looks for an installed one, not one built by a sub-project. So somewhere you should have a line where you reference the directory that has Chipmunk in it. In my project:
add_subdirectory(external/Chipmunk2D)
Then when you are building your executable (or library, whatever), you can just list libraries built by sub-projects by name. In my case, glfw, chipmunk_static, and enet are all built by CMake in sub-projects:
target_link_libraries(my_executable
${OPENGL_LIBRARIES}
glfw
chipmunk_static
enet
)