title: How to link and compile a C++ project for Linux using CMake? (Adapting CMakeLists.txt)
body: <p><strong>Context:</strong> I want to make a GameClient, GameServer, and custom library (which both Client and Server use) cross platform for Linux, Windows &amp; MacOS. Server and Client both depend on various libraries I prefer linking statically, and headers. I heard I could do this by wrapping my 3 currently VisualStudio developed projects into a CMake environment, so I started by making CMakeLists.txt's for Server and Shared lib, which are the simplest and have fewer library dependencies.</p>
  <p><strong>Question:</strong> How can I adapt these CMakeLists.txt's (currently building on and for Windows), so I can choose if I want to compile for Windows or Linux (preferably from Windows)?</p>
  <p>Shared Lib CMakeLists.txt:</p>
  <pre><code>cmake_minimum_required(VERSION 3.10)
  
  project(MORPH_Server VERSION 1.0)
  
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED True)
  
  set(SFML_STATIC_LIBRARIES TRUE) #Link to statically
  set(SFML_DIR &quot;C:/libraries/SFML/SFMLx64SourceAndCompile&quot;)
  find_package(SFML 2.5.1 COMPONENTS system network REQUIRED)
  
  add_library(MORPH_Shared_Functions)
  target_sources(MORPH_Shared_Functions
                 PRIVATE Transform.cpp
                 PRIVATE World.cpp
                 PRIVATE Player.cpp
                 PRIVATE PropsData.cpp
                 PRIVATE Prop.cpp
                 PRIVATE udp_network_manager.cpp
                 PRIVATE utility_functions.cpp
                 )
  
  target_link_libraries(MORPH_Shared_Functions 
                        sfml-system #Basically already found sfml modules and their dependencies (find-package)
                        sfml-network
                        )
  
  target_include_directories(MORPH_Shared_Functions
                             PRIVATE C:/libraries/SFML/SFML-2.5.1/include
                             PRIVATE C:/libraries/GLM/glm
                             PRIVATE C:/libraries/CEREAL
                             )
  </code></pre>
  <p>Server CMakeLists.txt:</p>
  <pre><code>cmake_minimum_required(VERSION 3.10)
  
  project(MORPH_Server VERSION 1.0)
  
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED True)
  
  configure_file(CmakeConfig.h.in CmakeConfig.h)
  
  set(SFML_STATIC_LIBRARIES TRUE) #Link to statically
  set(SFML_DIR &quot;C:/libraries/SFML/SFMLx64SourceAndCompile&quot;)
  find_package(SFML 2.5.1 COMPONENTS system network REQUIRED)
  
  add_executable(MORPH_Server)
  target_sources(MORPH_Server
                 PRIVATE Main.cpp 
                 PRIVATE Game.cpp
                 PRIVATE CommandManager.cpp
                 PRIVATE ServerPlayer.cpp
                 PRIVATE ServerProp.cpp
                 PRIVATE ServerWorldState.cpp
                 PRIVATE UDP_Server_CS.cpp
                 )
  add_library(MORPH_Shared_Functions STATIC IMPORTED)
  
  set_target_properties(MORPH_Shared_Functions PROPERTIES IMPORTED_LOCATION C:/Users/dylan/Desktop/MORPH/MORPH_Shared_Functions/Build/Debug/MORPH_Shared_Functions.lib)
  
  target_link_libraries(MORPH_Server
                        MORPH_Shared_Functions 
                        sfml-system
                        sfml-network
                        )
  
  target_include_directories(MORPH_Server 
                             PRIVATE C:/Users/dylan/Desktop/MORPH/MORPH_Shared_Functions
                             PRIVATE C:/libraries/SFML/SFML-2.5.1/include
                             PRIVATE C:/libraries/GLM/glm
                             PRIVATE C:/libraries/CEREAL
                             )
  </code></pre>