Skip to content

Instantly share code, notes, and snippets.

@kellabyte
Created April 15, 2014 22:08
Show Gist options
  • Save kellabyte/10781926 to your computer and use it in GitHub Desktop.
Save kellabyte/10781926 to your computer and use it in GitHub Desktop.
cmake_minimum_required(VERSION 2.8)
# create_source_group(relativeSourcePath sourceGroupName files)
#
# Creates a source group with the specified name relative to the relative path
# specified.
#
# Parameters:
# - sourceGroupName: Name of the source group to create.
# - relativeSourcePath: Relative path to the files.
# - sourceFiles: Files to add to the source group.
#
# For example if you have the following directory structure:
#
# - ExampleApplication
# - include
# - Main.h
# - Window
# Window.h
# - source
# - Main.cpp
# - Window
# Window.cpp
#
# You can get your list of files and call create_source_group the following way
#
# file(GLOB_RECURSE my_source_files ${CMAKE_CURRENT_SOURCE_DIR}/source/*)
# create_source_group("Source Files" "${CMAKE_CURRENT_SOURCE_DIR}/source" ${my_source_files})
# file(GLOB_RECURSE my_header_files ${CMAKE_CURRENT_SOURCE_DIR}/include/*)
# create_source_group("Header Files" "${CMAKE_CURRENT_SOURCE_DIR}/include" ${my_header_files})
# add_executable(ExampleApplication ${my_source_files} ${my_header_files})
#
# Then the generated solution would look like this
#
# - ExampleApplication (project)
# - Header Files
# - Main.h
# - Window
# Window.h
# - Source Files
# - Main.cpp
# - Window
# Window.cpp
#
function(create_source_group sourceGroupName relativeSourcePath)
FOREACH(currentSourceFile ${ARGN})
FILE(RELATIVE_PATH folder ${relativeSourcePath} ${currentSourceFile})
get_filename_component(filename "${folder}" NAME)
string(REPLACE ${filename} "" folder ${folder})
if(NOT folder STREQUAL "")
string(REGEX REPLACE "/+$" "" folderlast ${folder})
string(REPLACE "/" "\\" folderlast ${folderlast})
SOURCE_GROUP("${sourceGroupName}\\${folderlast}" FILES ${currentSourceFile})
endif(NOT folder STREQUAL "")
ENDFOREACH(currentSourceFile ${ARGN})
endfunction(create_source_group)
# ----------------------------------------
# executable
# ----------------------------------------
project(redone C CXX)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
#set(CMAKE_BUILD_TYPE Debug)
add_definitions(-mavx)
#add_definitions(-msse4.2)
add_definitions(-std=c++11)
add_definitions(-Weffc++)
add_definitions(-pedantic)
add_definitions(-O3)
add_definitions(-Wall)
add_definitions(-Wextra)
add_definitions(-Wcast-align)
add_definitions(-w)
file(GLOB_RECURSE REDONE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
list(SORT REDONE_SOURCES)
create_source_group("Source Files" "${CMAKE_CURRENT_SOURCE_DIR}/src" ${REDONE_SOURCES})
include_directories(${CMAKE_SOURCE_DIR}/lib/mdb/libraries/liblmdb/)
find_package(Threads REQUIRED)
add_executable (redone
${REDONE_SOURCES}
${CMAKE_SOURCE_DIR}/lib/mdb/libraries/liblmdb/mdb.o
${CMAKE_SOURCE_DIR}/lib/mdb/libraries/liblmdb/midl.o)
target_link_libraries (redone ${CMAKE_THREAD_LIBS_INIT})
-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Looking for include file pthread.h
CMake Error at /usr/local/Cellar/cmake/2.8.10.2/share/cmake/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:2 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for include file pthread.h - not found
CMake Error at /usr/local/Cellar/cmake/2.8.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/2.8.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/2.8.10.2/share/cmake/Modules/FindThreads.cmake:166 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:85 (find_package)


-- Configuring incomplete, errors occurred!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment