OS specific instructions in CMAKE: How to?
Use
if (WIN32) #do somethingendif (WIN32)
or
if (UNIX) #do somethingendif (UNIX)
or
if (MSVC) #do somethingendif (MSVC)
or similar
Given this is such a common issue, geronto-posting:
if(UNIX AND NOT APPLE) set(LINUX TRUE) endif() # if(NOT LINUX) should work, too, if you need that if(LINUX) message(STATUS ">>> Linux") # linux stuff here else() message(STATUS ">>> Not Linux") # stuff that should happen not on Linux endif()
In General
You can detect and specify variables for several operating systems like that:
Detect Microsoft Windows
if(WIN32) # for Windows operating system in generalendif()
Or:
if(MSVC OR MSYS OR MINGW) # for detecting Windows compilersendif()
Detect Apple MacOS
if(APPLE) # for MacOS X or iOS, watchOS, tvOS (since 3.10.3)endif()
Detect Unix and Linux
if(UNIX AND NOT APPLE) # for Linux, BSD, Solaris, Minixendif()
Your specific linker issue
To solve your issue with the Windows-specific wsock32
library, just remove it from other systems, like that:
if(WIN32) target_link_libraries(${PROJECT_NAME} bioutils wsock32)else target_link_libraries(${PROJECT_NAME} bioutils)endif()