From d0a58367cb7ba44b152c55c09d9502fc2a0657a8 Mon Sep 17 00:00:00 2001 From: Giulio M <1172898+giuliom@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:00:13 +0100 Subject: [PATCH] Added BasicRendererLib target --- BasicRenderer/CMakeLists.txt | 32 ++++++++++++++++++++++++-------- BasicRenderer/build.sh | 2 +- BasicRenderer/run_tests.sh | 4 ++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/BasicRenderer/CMakeLists.txt b/BasicRenderer/CMakeLists.txt index 61dc4ab..fd17a1c 100644 --- a/BasicRenderer/CMakeLists.txt +++ b/BasicRenderer/CMakeLists.txt @@ -9,9 +9,9 @@ include(FetchContent) # Avoid warnings by using new policy cmake_policy(SET CMP0135 NEW) + # ------ BasicCppLibrary ----- # -# BasicCppLibrary FetchContent_Declare( BasicCppLibrary GIT_REPOSITORY https://github.com/giuliom/BasicCppLibrary.git @@ -19,15 +19,24 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(BasicCppLibrary) -# ------ BasicRenderer ----- # +# ------ BasicRenderer Library ----- # + +set (LIBRARY_NAME BasicRendererLib) file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/source/*.cpp" "${PROJECT_SOURCE_DIR}/include/*.h") +list(REMOVE_ITEM SOURCES "${PROJECT_SOURCE_DIR}/source/main.cpp") -add_executable(${PROJECT_NAME} ${SOURCES}) -target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) +add_library(${LIBRARY_NAME} STATIC ${SOURCES}) +set_target_properties(${LIBRARY_NAME} PROPERTIES LINKER_LANGUAGE CXX) +target_include_directories(${LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) + +target_link_libraries(${LIBRARY_NAME} PUBLIC BasicCppLibrary) +add_dependencies(${LIBRARY_NAME} BasicCppLibrary) + +# Set the library version (optional) +set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION 1.0 SOVERSION 1) +install(TARGETS ${LIBRARY_NAME} DESTINATION lib) -target_link_libraries(${PROJECT_NAME} PUBLIC BasicCppLibrary) -add_dependencies(${PROJECT_NAME} BasicCppLibrary) # ------ Google Test ----- # @@ -42,14 +51,21 @@ FetchContent_MakeAvailable(googletest) enable_testing() file (GLOB TESTS "test/*.h" "test/*.cpp") -list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp") add_executable(BasicRendererTest ${TESTS} ${SOURCES}) target_include_directories(BasicRendererTest PUBLIC ${PROJECT_SOURCE_DIR}/include) target_link_libraries( BasicRendererTest + ${LIBRARY_NAME} GTest::gtest_main ) include(GoogleTest) -gtest_discover_tests(BasicRendererTest) \ No newline at end of file +gtest_discover_tests(BasicRendererTest) + +# ------ BasicRenderer Executable ----- # + +add_executable(${PROJECT_NAME} ${SOURCES} "${PROJECT_SOURCE_DIR}/source/main.cpp") + +target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARY_NAME}) \ No newline at end of file diff --git a/BasicRenderer/build.sh b/BasicRenderer/build.sh index 60397ef..d7bb499 100644 --- a/BasicRenderer/build.sh +++ b/BasicRenderer/build.sh @@ -2,4 +2,4 @@ echo "Building BasicRenderer" cmake -S . -B build -cmake --build build \ No newline at end of file +cmake --build build --config release --target BasicRenderer \ No newline at end of file diff --git a/BasicRenderer/run_tests.sh b/BasicRenderer/run_tests.sh index 6d41cc1..ad9b265 100644 --- a/BasicRenderer/run_tests.sh +++ b/BasicRenderer/run_tests.sh @@ -1,6 +1,6 @@ #!/bin/bash cmake -S . -B build -cmake --build build +cmake --build build --config release cd build -ctest \ No newline at end of file +ctest -C release \ No newline at end of file