cmake_minimum_required(VERSION 2.6) # define compiler in order not to take clang # and clang++ as default compilers # do rm -rf CMakeFiles/* CMakeCache.txt # if it is not working set(CMAKE_C_COMPILER "/usr/bin/gcc") set(CMAKE_CXX_COMPILER "/usr/bin/g++") project(MyProject) set(CMAKE_BUILD_TYPE Release) set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE}) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") # tell where to find the .h files include_directories(src src/maths) # find .cpp files for the maths library file(GLOB_RECURSE source_files_maths src/maths/*.cpp) # tell to create a library add_library(maths SHARED ${source_files_maths}) file(GLOB_RECURSE source_files src/*.cpp) # will generate the binary ./main.exe add_executable(main.exe ${source_files}) # link with library maths target_link_libraries(main.exe maths)