Start wxWdigets programming on Windows
- Download wxWidgets
- Extracted it somewhere. "c:\wxWidgets-3.0.0", for example.
- Create environment variable WXWIN with value "c:\wxWidgets-3.3.0"
- Install Visual Studio Express 2010
- If the source is on network drive, you need set pch directory. Maybe the best way is use local folder.
- Compile wxWidgets library by running the dos batch file:
@echo off
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
nmake -f %WXWIN%\build\msw\makefile.vc BUILD=debug
nmake -f %WXWIN%\build\msw\makefile.vc BUILD=release
We use vcvars32.bat to set up the CLI tool chains.
- Install CMake
- Create a simple project with files main.cpp, main.hpp, and CMakeLists.txt
CMakeLists.txt is the project file for CMake:
PROJECT(main)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# sets variable SOURCES to the project source files.
set(XRCS
main_frame.xrc
)
set(XRCS_DIR ${main_SOURCE_DIR}/rc)
if(CMAKE_COMPILER_IS_GNUCC)
# needed for gcc 4.6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
endif()
set( CPP_SOURCES
main.cpp
)
set( H_SOURCES
main.hpp
)
)
set(SOURCES
${CPP_SOURCES}
${H_SOURCES}
)
# xrc -> xml, adv, html
set(wxWidgets_USE_LIBS xrc xml adv html core base)
find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
#try to embed resource
foreach(XRC ${XRCS})
string(REGEX REPLACE "[.].*$" ".h" XRC_HEADER ${XRC})
set(XRC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${XRC_HEADER})
set(XRC ${XRCS_DIR}/${XRC})
add_custom_command(OUTPUT ${XRC_HEADER}
COMMAND bin2c -c ${XRC} ${XRC_HEADER}
MAIN_DEPENDENCY ${XRC} )
set(SOURCES ${SOURCES} ${XRC_HEADER})
endforeach(XRC)
set(INC
)
if(UNIX AND NOT APPLE)
include(FindPkgConfig)
pkg_check_modules(GTK2 REQUIRED gtk+-2.0>=2.10)
set(INC ${INC} ${GTK2_INCLUDE_DIRS})
endif()
#add other librarie
include_directories(${INC})
if(UNIX)
add_definitions(-Wno-write-strings)
endif()
if(WIN32)
# WIN32 := subsystem is windows instead of console?
add_executable(main WIN32 ${SOURCES})
else(WIN32)
add_executable(main ${SOURCES})
endif()
set(LIBS
${wxWidgets_LIBRARIES}
)
if(MINGW AND WIN32)
set(LIBS ${LIBS} ole32 uuid oleaut32)
endif()
target_link_libraries(main ${LIBS})
- Running the below dos batch the create Visual Studio Project Files
@echo off
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
cmake path/of/directory/which/contains/CMakeLists.txt/
- Enjoy!
BTW, for other systems, see wxWiki.