Skip to content

Commit 8c3d253

Browse files
committed
Support building with cmake.
1 parent 70c4977 commit 8c3d253

File tree

5 files changed

+100
-6
lines changed

5 files changed

+100
-6
lines changed

.travis.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
sudo: false
22

33
env:
4-
- PLATFORM=x86_64 WINE=wine64 UNICODE=
5-
- PLATFORM=i686 WINE=wine UNICODE=
6-
- PLATFORM=x86_64 WINE=wine64 UNICODE=1
7-
- PLATFORM=i686 WINE=wine UNICODE=1
4+
- PLATFORM=x86_64 WINE=wine64 UNICODE= CMAKE=
5+
- PLATFORM=i686 WINE=wine UNICODE= CMAKE=
6+
- PLATFORM=x86_64 WINE=wine64 UNICODE=1 CMAKE=
7+
- PLATFORM=i686 WINE=wine UNICODE=1 CMAKE=
8+
- PLATFORM=x86_64 WINE=wine64 UNICODE= CMAKE=1
9+
- PLATFORM=i686 WINE=wine UNICODE= CMAKE=1
10+
- PLATFORM=x86_64 WINE=wine64 UNICODE=1 CMAKE=1
11+
- PLATFORM=i686 WINE=wine UNICODE=1 CMAKE=1
812

913
language: cpp
1014

@@ -17,16 +21,21 @@ addons:
1721
packages:
1822
- binutils-mingw-w64-i686
1923
- binutils-mingw-w64-x86-64
24+
- cmake
2025
- mingw-w64-dev
2126
- g++-mingw-w64-i686
2227
- g++-mingw-w64-x86-64
2328
- gcc-mingw-w64-i686
2429
- gcc-mingw-w64-x86-64
2530
- wine
2631

32+
before_script:
33+
- if [ ! -z "$CMAKE" ]; then cmake -DPLATFORM=$PLATFORM -D UNICODE=$UNICODE -H. -B.; fi
34+
2735
script:
28-
- make PLATFORM=$PLATFORM UNICODE=$UNICODE
29-
- make test PLATFORM=$PLATFORM UNICODE=$UNICODE
36+
- if [ -z "$CMAKE" ]; then make PLATFORM=$PLATFORM UNICODE=$UNICODE; fi
37+
- if [ -z "$CMAKE" ]; then make test PLATFORM=$PLATFORM UNICODE=$UNICODE; fi
38+
- if [ ! -z "$CMAKE" ]; then cmake --build .; fi
3039
- cd example/DllLoader
3140
- WINEPREFIX=`pwd`/$WINE WINEPATH=/usr/lib/gcc/$PLATFORM-w64-mingw32/4.6/ $WINE ./DllLoader.exe
3241
- WINEPREFIX=`pwd`/$WINE WINEPATH=/usr/lib/gcc/$PLATFORM-w64-mingw32/4.6/ $WINE ./DllLoaderLoader.exe

CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
project (MemoryModule)
2+
cmake_minimum_required (VERSION 2.8.7)
3+
4+
set (PLATFORM "x86_64" CACHE STRING "Platform to compile for")
5+
message (STATUS "Compile for ${PLATFORM} platform")
6+
7+
if (NOT MSVC)
8+
set (CMAKE_SYSTEM_NAME Windows)
9+
set (CMAKE_POSITION_INDEPENDENT_CODE False)
10+
11+
set (COMPILER_PREFIX "${PLATFORM}-w64-mingw32")
12+
set (CMAKE_C_COMPILER "${COMPILER_PREFIX}-gcc")
13+
set (CMAKE_CXX_COMPILER "${COMPILER_PREFIX}-g++")
14+
set (CMAKE_RC_COMPILER "${COMPILER_PREFIX}-windres")
15+
set (CMAKE_AR "${COMPILER_PREFIX}-ar")
16+
set (CMAKE_RANLIB "${COMPILER_PREFIX}-ranlib")
17+
18+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
19+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
20+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
21+
22+
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
23+
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
24+
25+
set (CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
26+
endif ()
27+
28+
add_definitions ("-Wall")
29+
30+
option(UNICODE "Compile with UNICODE support" OFF)
31+
if (UNICODE)
32+
message (STATUS "Compile with UNICODE support")
33+
add_definitions ("-DUNICODE" "-D_UNICODE")
34+
else ()
35+
message (STATUS "Compile without UNICODE support")
36+
endif ()
37+
38+
add_library (MemoryModule STATIC MemoryModule.c MemoryModule.h)
39+
if (NOT MSVC)
40+
set_target_properties ("MemoryModule" PROPERTIES PREFIX "")
41+
endif ()
42+
43+
add_subdirectory (example)
44+
45+
enable_language (RC)

example/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory (DllLoader)
2+
add_subdirectory (SampleDLL)

example/DllLoader/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set (sources_dllloader
2+
DllLoader.cpp
3+
)
4+
5+
set (sources_dllloaderloader
6+
DllLoaderLoader.cpp
7+
)
8+
9+
if (NOT MSVC)
10+
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-static")
11+
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static")
12+
endif ()
13+
14+
add_executable (DllLoader ${sources_dllloader})
15+
target_link_libraries ("DllLoader" "MemoryModule")
16+
if (NOT MSVC)
17+
set_target_properties ("DllLoader" PROPERTIES SUFFIX ".exe")
18+
set_target_properties ("DllLoader" PROPERTIES LINK_FLAGS "-Wl,--image-base -Wl,0x20000000")
19+
endif ()
20+
21+
add_executable (DllLoaderLoader ${sources_dllloaderloader})
22+
target_link_libraries ("DllLoaderLoader" "MemoryModule")
23+
if (NOT MSVC)
24+
set_target_properties ("DllLoaderLoader" PROPERTIES SUFFIX ".exe")
25+
set_target_properties ("DllLoaderLoader" PROPERTIES LINK_FLAGS "-Wl,--image-base -Wl,0x10000000")
26+
endif ()

example/SampleDLL/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set (sources
2+
SampleDLL.cpp
3+
SampleDLL.h
4+
SampleDLL.rc
5+
)
6+
7+
add_definitions (-DSAMPLEDLL_EXPORTS)
8+
add_library (SampleDLL MODULE ${sources})
9+
if (NOT MSVC)
10+
set_target_properties ("SampleDLL" PROPERTIES PREFIX "")
11+
set_target_properties ("SampleDLL" PROPERTIES SUFFIX ".dll")
12+
endif ()

0 commit comments

Comments
 (0)