Skip to content

Commit

Permalink
build: cmake update
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Nov 2, 2023
1 parent 9cc38e6 commit c33b98d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cmake/3rd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ if (NOT CGAL_FOUND)
"Following https://doc.cgal.org/latest/Manual/devman_create_and_use_a_cmakelist.html to install.")
endif ()

find_package(Boost COMPONENTS thread system REQUIRED)
find_package(Boost COMPONENTS thread REQUIRED)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Boost not found.\n"
"Following https://www.boost.org to install.")
Expand Down
1 change: 1 addition & 0 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ list(APPEND DEFAULT_COMPILE_OPTIONS

list(APPEND DEFAULT_LINK_LIB
spdlog::spdlog
$<BUILD_INTERFACE:glm::glm>
)
62 changes: 51 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@ set(lib_src
physics/dtkRigidBody.cpp
)

add_library(${PROJECT_NAME}-static STATIC
link_libraries(
${DEFAULT_LINK_LIB}
Boost::headers
Boost::thread
CGAL
$<BUILD_INTERFACE:glfw>
)

add_library(${PROJECT_NAME}-shared SHARED
${lib_src}
)

target_include_directories(${PROJECT_NAME}-static PRIVATE
target_compile_definitions(${PROJECT_NAME}-shared PRIVATE
BOOST_ALL_DYN_LINK
)

target_include_directories(${PROJECT_NAME}-shared PRIVATE
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/src/dtk/include
${PROJECT_SOURCE_DIR}/src/math/include
Expand All @@ -65,17 +77,45 @@ target_include_directories(${PROJECT_NAME}-static PRIVATE

)

target_link_libraries(${PROJECT_NAME}-static PRIVATE
${DEFAULT_LINK_LIB}
Boost::boost
Boost::thread
CGAL
glfw
glm::glm
# 打包动态库
packageProject(
# 要导出的 target
NAME ${PROJECT_NAME}-shared
# 版本
VERSION ${PROJECT_VERSION}
# 生成文件目录
BINARY_DIR ${PROJECT_BINARY_DIR}
# 头文件路径
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/dtk/include ${PROJECT_SOURCE_DIR}/src/math/include ${PROJECT_SOURCE_DIR}/src/physics/include
# 与 target 的 INSTALL_INTERFACE 一致
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
# 头文件过滤
INCLUDE_HEADER_PATTERN "*.h"
# namespace 名称,不能包含 '::'
NAMESPACE ${PROJECT_NAMESPACE}
# (optional) option to disable the versioning of install destinations
DISABLE_VERSION_SUFFIX YES
ARCH_INDEPENDENT YES
# 生成 CPack 变量
CPACK YES
)

add_library(${PROJECT_NAME}-static STATIC
${lib_src}
)

target_include_directories(${PROJECT_NAME}-static PRIVATE
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/src/dtk/include
${PROJECT_SOURCE_DIR}/src/math/include
${PROJECT_SOURCE_DIR}/src/physics/include
>

$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>

)

# 打包
# @todo 导出静态库与动态库
# 打包静态库
packageProject(
# 要导出的 target
NAME ${PROJECT_NAME}-static
Expand Down
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ link_libraries(
${DEFAULT_LINK_LIB}
gtest_main
${glog_LIBRARIES}
SimplePhysicsEngine-static
Eigen
GLUT::GLUT
OpenGL::GL
OpenGL::GLU
SimplePhysicsEngine-shared
)

add_subdirectory(unit_test)
Expand Down
8 changes: 0 additions & 8 deletions test/system_test/demo2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ add_executable(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME} PRIVATE
include
)

target_link_libraries(${PROJECT_NAME} PRIVATE
Eigen
GLUT::GLUT
glm
OpenGL::GL
OpenGL::GLU
)
8 changes: 0 additions & 8 deletions test/system_test/demo3d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,3 @@ add_executable(demo3d
target_include_directories(${PROJECT_NAME} PRIVATE
include
)

target_link_libraries(${PROJECT_NAME} PRIVATE
Eigen
GLUT::GLUT
glm
OpenGL::GL
OpenGL::GLU
)

0 comments on commit c33b98d

Please sign in to comment.