Added static library linking
This commit is contained in:
parent
2eb90cf021
commit
d6fcb24863
6 changed files with 171 additions and 42 deletions
|
@ -1,3 +1,16 @@
|
|||
# Copyright (c) 2024 Jordon Brooks
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(HarmonyLinkTest)
|
||||
|
||||
|
@ -9,23 +22,37 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|||
file(GLOB_RECURSE TEST_SOURCES "src/*.cpp")
|
||||
file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp")
|
||||
|
||||
# Add executable
|
||||
add_executable(HarmonyLinkTest ${TEST_SOURCES} ${TEST_HEADERS})
|
||||
# Add executable for static library
|
||||
add_executable(HarmonyLinkTestStatic ${TEST_SOURCES} ${TEST_HEADERS})
|
||||
target_link_libraries(HarmonyLinkTestStatic PRIVATE HarmonyLinkLibStatic)
|
||||
target_compile_definitions(HarmonyLinkTestStatic PRIVATE HARMONYLINKLIB_STATIC)
|
||||
|
||||
# Link the HarmonyLinkLib with HarmonyLinkTest
|
||||
target_link_libraries(HarmonyLinkTest PRIVATE HarmonyLinkLib)
|
||||
# Add executable for shared library
|
||||
add_executable(HarmonyLinkTestShared ${TEST_SOURCES} ${TEST_HEADERS})
|
||||
target_link_libraries(HarmonyLinkTestShared PRIVATE HarmonyLinkLibShared)
|
||||
target_compile_definitions(HarmonyLinkTestShared PRIVATE HARMONYLINKLIB_SHARED)
|
||||
|
||||
# Set output directories for all build types
|
||||
foreach(TYPE IN ITEMS DEBUG RELEASE)
|
||||
string(TOUPPER ${TYPE} TYPE_UPPER)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}"
|
||||
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}"
|
||||
|
||||
# Static test executable properties
|
||||
set_target_properties(HarmonyLinkTestStatic PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestStatic"
|
||||
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestStatic"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestStatic"
|
||||
)
|
||||
|
||||
# Shared test executable properties
|
||||
set_target_properties(HarmonyLinkTestShared PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestShared"
|
||||
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestShared"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestShared"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
add_custom_command(TARGET HarmonyLinkTest POST_BUILD
|
||||
# Copy the DLL to the executable directory after building the shared test executable
|
||||
add_custom_command(TARGET HarmonyLinkTestShared POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:HarmonyLinkLib>"
|
||||
"$<TARGET_FILE_DIR:HarmonyLinkTest>")
|
||||
"$<TARGET_FILE:HarmonyLinkLibShared>"
|
||||
"$<TARGET_FILE_DIR:HarmonyLinkTestShared>")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue