56 lines
1.9 KiB
CMake
Raw Normal View History

2019-11-11 23:01:05 +01:00
# add the library that runs
add_library(MathFunctions MathFunctions.cxx)
# state that anybody linking to us needs to include the current source dir
# to find MathFunctions.h, while we don't.
target_include_directories(MathFunctions
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if(USE_MYMATH)
2020-02-01 23:06:01 +01:00
target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
2019-11-11 23:01:05 +01:00
2023-07-02 19:51:09 +02:00
include(MakeTable.cmake) # generates Table.h
2019-11-11 23:01:05 +01:00
# library that just does sqrt
add_library(SqrtLibrary STATIC
mysqrt.cxx
${CMAKE_CURRENT_BINARY_DIR}/Table.h
)
# state that we depend on our binary dir to find Table.h
target_include_directories(SqrtLibrary PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)
2020-02-01 23:06:01 +01:00
# state that SqrtLibrary need PIC when the default is shared libraries
2019-11-11 23:01:05 +01:00
set_target_properties(SqrtLibrary PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
2020-08-30 11:54:41 +02:00
target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
2019-11-11 23:01:05 +01:00
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
2020-08-30 11:54:41 +02:00
target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
2019-11-11 23:01:05 +01:00
# define the symbol stating we are using the declspec(dllexport) when
# building on windows
target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
2022-11-16 20:14:03 +01:00
# install libs
2021-09-14 00:13:48 +02:00
set(installable_libs MathFunctions tutorial_compiler_flags)
if(TARGET SqrtLibrary)
list(APPEND installable_libs SqrtLibrary)
endif()
install(TARGETS ${installable_libs}
2022-03-29 21:10:50 +02:00
EXPORT MathFunctionsTargets
DESTINATION lib)
2022-11-16 20:14:03 +01:00
# install include headers
2019-11-11 23:01:05 +01:00
install(FILES MathFunctions.h DESTINATION include)