Skip to content

Commit

Permalink
Improve CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
floppyhammer committed May 10, 2024
1 parent e5b39e9 commit d9a4c72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16.1)
cmake_minimum_required(VERSION 3.16)

project(pathfinder)

Expand All @@ -19,7 +19,7 @@ endif ()

# Should handle EMSCRIPTEN before other platforms.
if (EMSCRIPTEN)
message("[Pathfinder] Will build for Web")
message("[Pathfinder] Build for Web")

# No Vulkan support for web.
set(PATHFINDER_VULKAN_SUPPORT OFF)
Expand All @@ -33,7 +33,7 @@ endif ()
add_subdirectory(pathfinder)

if (PATHFINDER_VULKAN_SUPPORT)
message("[Pathfinder] Will use Vulkan")
message("[Pathfinder] Use Vulkan")

# In case Vulkan is found but Vulkan_LIBRARY is not.
# set(Vulkan_LIBRARY "C:/VulkanSDK/1.3.224.1/Lib/vulkan-1.lib")
Expand All @@ -48,7 +48,7 @@ if (PATHFINDER_VULKAN_SUPPORT)
# We need to include Vulkan headers manually because of the above reason.
target_include_directories(pathfinder PUBLIC "${Vulkan_INCLUDE_DIRS}")
else ()
message("[Pathfinder] Will use OpenGL")
message("[Pathfinder] Use OpenGL")
endif ()

# Include third_party headers.
Expand Down Expand Up @@ -78,8 +78,25 @@ if (PATHFINDER_VULKAN_SUPPORT)
target_compile_definitions(pathfinder PUBLIC PATHFINDER_USE_VULKAN)
endif ()

# Link libraries.
if (WIN32)
target_link_libraries(pathfinder PUBLIC glfw)
if (PATHFINDER_VULKAN_SUPPORT)
target_link_libraries(pathfinder PUBLIC Vulkan::Vulkan)
endif ()
elseif (LINUX)
target_link_libraries(pathfinder PUBLIC glfw)
if (PATHFINDER_VULKAN_SUPPORT)
target_link_libraries(pathfinder PUBLIC -lvulkan)
else ()
target_link_libraries(pathfinder PUBLIC -lGL)
endif ()
elseif (APPLE)
target_link_libraries(pathfinder PUBLIC glfw Vulkan::Vulkan)
endif ()

if (PATHFINDER_BUILD_DEMO)
message("[Pathfinder] Will build demo")
message("[Pathfinder] Build demo")

# target_compile_definitions only added PATHFINDER_USE_VULKAN to the Pathfinder library.
# We need to define PATHFINDER_USE_VULKAN for the demo as well.
Expand Down
16 changes: 1 addition & 15 deletions demo/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,4 @@
add_executable(pathfinder_demo_native ${SOURCE_FILES} main.cpp)

# Link libraries.
if (WIN32)
target_link_libraries(pathfinder_demo_native glfw pathfinder pathfinder_demo_common)
if (PATHFINDER_VULKAN_SUPPORT)
target_link_libraries(pathfinder_demo_native Vulkan::Vulkan)
endif ()
elseif (LINUX)
target_link_libraries(pathfinder_demo_native pathfinder_demo_common pathfinder glfw)
if (PATHFINDER_VULKAN_SUPPORT)
target_link_libraries(pathfinder_demo_native -lvulkan)
else ()
target_link_libraries(pathfinder_demo_native -lGL)
endif ()
elseif (APPLE)
target_link_libraries(pathfinder_demo_native glfw pathfinder_demo_common pathfinder Vulkan::Vulkan)
endif ()
target_link_libraries(pathfinder_demo_native pathfinder_demo_common pathfinder)
3 changes: 1 addition & 2 deletions pathfinder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ else ()
endif ()

# Compile as static library.
add_library(pathfinder ${SOURCE_FILES}
../third_party/glad/src/gl.c)
add_library(pathfinder ${SOURCE_FILES} ../third_party/glad/src/gl.c)

0 comments on commit d9a4c72

Please sign in to comment.