Skip to content

Instantly share code, notes, and snippets.

@573
Created October 24, 2012 11:39
Show Gist options
  • Save 573/3945616 to your computer and use it in GitHub Desktop.
Save 573/3945616 to your computer and use it in GitHub Desktop.
CMakeLists.txt für Microsoft Visual C++ 2010 Express Edition
# file: CmakeLists.txt
# Is for generating Makefile etc. for a VC++ 2010 Express Win32 App
cmake_minimum_required(VERSION 2.8.1)
# But, target isn't the same as executable name! Use output_name for the latter
set(TARGET TaskBoxEx)
set(CMAKE_CXX_FLAGS_RELEASE_DEFAULTS "/MD /O2 /Ob2 /D NDEBUG")
project (${TARGET})
# For a start default build type to be Release
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
# to be able to load the source-file list, e. g. TaskBoxEx_src_files.cmake
# or other cmake includes (in this same folder, therefore
# CMAKE_CURRENT_SOURCE_DIR used):
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
# ---8<---
## file: ${CMAKE_CURRENT_SOURCE_DIR}/TaskBoxEx_src_files.cmake
## load the source-file list with CMake's include(...) command:
##include (TaskBoxEx_src_files)
set (file_root
${TARGET}/${TARGET}.cpp
${TARGET}/${TARGET}.ico
${TARGET}/${TARGET}.rc
${TARGET}/${TARGET}.h
)
# ---8<---
# final step is to use the file_root variable from the previously created source-file list to build your CMake target, observe WIN32 as second argument:
add_executable (${TARGET} WIN32 ${file_root})
# ---8<---
## file: ${CMAKE_CURRENT_SOURCE_DIR}/TaskBoxEx_UsingMfc.cmake
## load the list with the MFC-related settings (order after add_executable, as it contains set_target_properties):
## include (TaskBoxEx_UsingMfc)
# See http://www.cmake.org/Wiki/CMake_FAQ#How_to_use_MFC_with_CMake:
# In order to use MFC with UNICODE, you must also specify the entry point wWinMainCRTStartup. For example:
set(CMAKE_MFC_FLAG 2)
# relates to the add_executable target in CMakeLists.txt (the includee)
set_target_properties (${TARGET} PROPERTIES
OUTPUT_NAME "${TARGET}"
COMPILE_DEFINITIONS _AFXDLL,_UNICODE,UNICODE,_BIND_TO_CURRENT_CRT_VERSION,_BIND_TO_CURRENT_MFC_VERSION
LINK_FLAGS "/ENTRY:\"wWinMainCRTStartup\""
)
# taken from the properties page in VC++ configuration properties
# ... C/C++ >> command line.
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_DEFAULTS} /D _UNICODE /D UNICODE" CACHE STRING "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)." FORCE)
# ---8<---
message ("[Trace Test].")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment