Ok so I have the following code in my root/CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release" FORCE)
endif()
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configurations" FORCE)
mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory install)
SET(CMAKE_INSTALL_PREFIX install)
project(efge)
# include
add_definitions(-DEFGE_EXPORTS)
include_directories("${CMAKE_SOURCE_DIR}/include/EFGE/"
"${CMAKE_SOURCE_DIR}/include/EFGE/Math"
"${CMAKE_SOURCE_DIR}/include/EFGE/System")
# preconf
set(EFGE_SHARED_LIBS TRUE CACHE BOOL "Shared libraries (needs shared SFML libraries, too)")
if(WIN32)
set(EFGE_STATIC_STD_LIBS FALSE CACHE BOOL "Statically linked runtime/standard libraries? Must match with SFML-Option.")
if(EFGE_STATIC_STD_LIBS)
if(EFGE_SHARED_LIBS)
message("\nEFGE_STATIC_STD_LIBS and EFGE_SHARED_LIBS aren\'t compatible!")
elseif(MSVC)
foreach(flag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE)
if(${flag} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
endif()
endforeach()
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
endif()
endif()
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CSS_FLAGS} -std=c++0x")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
add_definitions(-DEFGE_USE_STD_RANDOMENGINE)
endif()
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/;${CMAKE_MODULE_PATH}")
if(NOT EFGE_SHARED_LIBS)
set(SFML_STATIC_LIBRARIES TRUE)
endif()
find_package(SFML 2 COMPONENTS audio graphics window system)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
else()
set(SFML_ROOT "" CACHE PATH "SFML top-level directory")
message("\n SFML directory not found. Please set SFML_ROOT to SFML top-level path, wich contains /include/ and /lib/ directories.")
message("Make sure SFML libraries have the same configuration.")
endif()
# linking sfml
macro(efge_link_sfml EFGE_TARGET)
target_link_libraries(${EFGE_TARGET} ${SFML_LIBRARIES})
endmacro()
macro(efge_link_sfml_dependencies EFGE_TARGET)
target_link_libraries(${EFGE_TARGET} ${SFML_DEPENDENCIES})
endmacro()
macro(efge_link_efge EFGE_TARGET)
target_link_libraries(${EFGE_TARGET} efge)
endmacro()
# source
add_subdirectory(src)
# include
install(DIRECTORY include
DESTINATION .)
My file structure, if this is important, is the following:
+-- include
+-- Math
+--- *.hpp files
+-- System
+--- *.hpp files
+--- *.hpp files
+-- src
+--- *.cpp files
+--- CMakeLists.txt
+--- CMakeLists.txt
How can I add the headers to my generated projectfile (e.g. CodeBlocks) ? Makefile seems to work fine. Stuff like set_group
do not affect the projectfile.
I can't figure it out, using CMake for the first time. Thanks!