How to write multiported library?
-
If you mean conditionally including files then something like this:
set(COMMON_SOURCES file1.cpp file2.cpp ... ) if (WIN32) set(PLATFORM_SOURCES win32file1.cpp win32file2.cpp ...} elseif (UNIX) set(PLATFORM_SOURCES unixfile1.cpp unixfile2.cpp ...} else() # generate error? endif() add_library(my_library ${COMMON_SOURCES} ${PLATFORM_SOURCES} )or
- use an explicitly set variable rather than the WIN32/UNIX pre-defined variables
- detect the presence of the platform specific libraries in order to determine what to build
Or other example: library for SingleInstance using ICP irrespective of Qt5, Qt6 or WxWidgets.
No idea what "SingleInstance using ICP" means